*General*

- Further work on centralizing- the place for package name and filename corrections and refactoring existing usages of both refs #83699

git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@48172 ebf7c1c2-ba36-0410-9fe8-c592906822b4

Former-commit-id: c7135b58c469d8eceb36ef407ec0c893b6b495a9
This commit is contained in:
psp 2023-08-17 14:10:56 +00:00
parent 21c0ab27bb
commit 0e35ebbedb
7 changed files with 119 additions and 105 deletions

View File

@ -1,13 +1,22 @@
package jd.controlling.linkcollector;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import jd.controlling.packagecontroller.AbstractNode;
import org.appwork.storage.config.JsonConfig;
import org.appwork.utils.DebugMode;
import org.appwork.utils.Regex;
import org.appwork.utils.StringUtils;
import org.appwork.utils.os.CrossSystem;
import org.jdownloader.controlling.filter.CompiledFiletypeFilter;
import org.jdownloader.controlling.filter.CompiledFiletypeFilter.ArchiveExtensions;
import org.jdownloader.controlling.filter.CompiledFiletypeFilter.ExtensionsFilterInterface;
import org.jdownloader.settings.GeneralSettings;
import jd.controlling.packagecontroller.AbstractNode;
public class LinknameCleaner {
public static final Pattern pat0 = Pattern.compile("(.*)(\\.|_|-)pa?r?t?\\.?[0-9]+.(rar|rev|exe)($|\\.html?)", Pattern.CASE_INSENSITIVE);
@ -35,12 +44,12 @@ public class LinknameCleaner {
/* not loaded yet */
}
}
public static final Pattern pat12 = Pattern.compile("(CD\\d+)", Pattern.CASE_INSENSITIVE);
public static final Pattern pat13 = Pattern.compile("(part\\d+)", Pattern.CASE_INSENSITIVE);
public static final Pattern pat17 = Pattern.compile("(.+)\\.\\d+\\.xtm($|\\.html?)");
public static final Pattern pat18 = Pattern.compile("(.*)\\.isz($|\\.html?)", Pattern.CASE_INSENSITIVE);
public static final Pattern pat19 = Pattern.compile("(.*)\\.i\\d{2}$", Pattern.CASE_INSENSITIVE);
public static final Pattern[] iszPats = new Pattern[] { pat18, pat19 };
public static final Pattern pat12 = Pattern.compile("(CD\\d+)", Pattern.CASE_INSENSITIVE);
public static final Pattern pat13 = Pattern.compile("(part\\d+)", Pattern.CASE_INSENSITIVE);
public static final Pattern pat17 = Pattern.compile("(.+)\\.\\d+\\.xtm($|\\.html?)");
public static final Pattern pat18 = Pattern.compile("(.*)\\.isz($|\\.html?)", Pattern.CASE_INSENSITIVE);
public static final Pattern pat19 = Pattern.compile("(.*)\\.i\\d{2}$", Pattern.CASE_INSENSITIVE);
public static final Pattern[] iszPats = new Pattern[] { pat18, pat19 };
public static enum EXTENSION_SETTINGS {
KEEP,
@ -52,6 +61,7 @@ public class LinknameCleaner {
return cleanFileName(null, name, splitUpperLowerCase, ignoreArchiveFilters, extensionSettings, cleanup);
}
/* TODO: Refactor this */
public static String cleanFileName(AbstractNode node, String name, boolean splitUpperLowerCase, boolean ignoreArchiveFilters, final EXTENSION_SETTINGS extensionSettings, boolean cleanup) {
if (name == null) {
return null;
@ -69,7 +79,7 @@ public class LinknameCleaner {
}
if (extensionStilExists) {
/**
* remove 7zip/zip and hjmerge extensions
* remove 7zip/zip and merge extensions
*/
before = name;
for (Pattern Pat : zipPats) {
@ -105,7 +115,7 @@ public class LinknameCleaner {
/**
* FFSJ splitted files
*
* */
*/
before = name;
for (Pattern Pat : ffsjPats) {
name = getNameMatch(name, Pat);
@ -197,6 +207,46 @@ public class LinknameCleaner {
return name.trim();
}
public static String cleanPackagename(final String packagename) {
return LinknameCleaner.cleanFileName(null, packagename, false, true, LinknameCleaner.EXTENSION_SETTINGS.REMOVE_KNOWN, true);
}
public static String cleanFilename(final String filename, final boolean removeLeadingHidingDot) {
String newfinalFileName = filename;
final String toRemove = new Regex(newfinalFileName, Pattern.compile("r(?:ar|\\d{2,3})(\\.html?)$", Pattern.CASE_INSENSITIVE)).getMatch(0);
if (toRemove != null) {
System.out.println("Use Workaround for stupid >>rar.html<< uploaders!");
newfinalFileName = newfinalFileName.substring(0, newfinalFileName.length() - toRemove.length());
}
if (DebugMode.TRUE_IN_IDE_ELSE_FALSE) {
// 2023-08-04: TODO, see https://svn.jdownloader.org/issues/83699
// TODO: This should never be null ?!
final Map<String, String> forbiddenCharacterRegexReplaceMap = JsonConfig.create(GeneralSettings.class).getFilenameAndPathCharacterRegexReplaceMap();
if (forbiddenCharacterRegexReplaceMap != null && !forbiddenCharacterRegexReplaceMap.isEmpty()) {
String newfilenameTemp = newfinalFileName;
final Iterator<Entry<String, String>> iterator = forbiddenCharacterRegexReplaceMap.entrySet().iterator();
while (iterator.hasNext()) {
final Entry<String, String> entry = iterator.next();
if (entry.getValue() != null) {
try {
newfilenameTemp = newfilenameTemp.replaceAll(entry.getKey(), entry.getValue());
} catch (final PatternSyntaxException e) {
}
}
}
/**
* Users can put anything into that replace map. </br>
* Try to avoid the results of adding something like ".+" resulting in empty filenames.
*/
if (!StringUtils.isEmpty(newfilenameTemp)) {
newfinalFileName = newfilenameTemp;
}
}
}
newfinalFileName = CrossSystem.alleviatePathParts(newfinalFileName, removeLeadingHidingDot);
return newfinalFileName;
}
private static String getNameMatch(String name, Pattern pattern) {
String match = new Regex(name, pattern).getMatch(0);
if (match != null) {

View File

@ -3,20 +3,6 @@ package jd.controlling.linkcrawler;
import java.util.Iterator;
import java.util.List;
import jd.controlling.linkcollector.LinkCollectingInformation;
import jd.controlling.linkcollector.LinkCollectingJob;
import jd.controlling.linkcollector.LinkOriginDetails;
import jd.controlling.packagecontroller.AbstractNode;
import jd.controlling.packagecontroller.AbstractNodeNotifier;
import jd.controlling.packagecontroller.AbstractPackageChildrenNode;
import jd.plugins.Account;
import jd.plugins.CryptedLink;
import jd.plugins.DownloadLink;
import jd.plugins.DownloadLinkProperty;
import jd.plugins.LinkInfo;
import jd.plugins.Plugin;
import jd.plugins.PluginForHost;
import org.appwork.utils.StringUtils;
import org.appwork.utils.os.CrossSystem;
import org.jdownloader.DomainInfo;
@ -28,6 +14,21 @@ import org.jdownloader.extensions.extraction.BooleanStatus;
import org.jdownloader.myjdownloader.client.json.AvailableLinkState;
import org.jdownloader.plugins.controller.crawler.LazyCrawlerPlugin;
import jd.controlling.linkcollector.LinkCollectingInformation;
import jd.controlling.linkcollector.LinkCollectingJob;
import jd.controlling.linkcollector.LinkOriginDetails;
import jd.controlling.linkcollector.LinknameCleaner;
import jd.controlling.packagecontroller.AbstractNode;
import jd.controlling.packagecontroller.AbstractNodeNotifier;
import jd.controlling.packagecontroller.AbstractPackageChildrenNode;
import jd.plugins.Account;
import jd.plugins.CryptedLink;
import jd.plugins.DownloadLink;
import jd.plugins.DownloadLinkProperty;
import jd.plugins.LinkInfo;
import jd.plugins.Plugin;
import jd.plugins.PluginForHost;
public class CrawledLink implements AbstractPackageChildrenNode<CrawledPackage>, CheckableLink, AbstractNodeNotifier, Iterable<CrawledLink> {
private static enum PROPERTY {
ENABLED,
@ -350,7 +351,7 @@ public class CrawledLink implements AbstractPackageChildrenNode<CrawledPackage>,
}
if (name != null) {
if (!name.contains("<jd:")) {
name = CrossSystem.alleviatePathParts(name);
name = LinknameCleaner.cleanFilename(name, true);
}
if (StringUtils.equals(name, this.name)) {
return;

View File

@ -32,30 +32,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import jd.controlling.linkcollector.LinkCollectingJob;
import jd.controlling.linkcollector.LinkCollector.JobLinkCrawler;
import jd.controlling.linkcollector.LinknameCleaner;
import jd.controlling.linkcrawler.LinkCrawlerConfig.DirectHTTPPermission;
import jd.controlling.linkcrawler.LinkCrawlerRule.RULE;
import jd.http.Browser;
import jd.http.Request;
import jd.http.URLConnectionAdapter;
import jd.http.requests.PostRequest;
import jd.nutils.SimpleFTP;
import jd.nutils.encoding.Encoding;
import jd.parser.html.Form;
import jd.parser.html.HTMLParser;
import jd.parser.html.HTMLParser.HtmlParserCharSequence;
import jd.parser.html.HTMLParser.HtmlParserResultSet;
import jd.plugins.CryptedLink;
import jd.plugins.DownloadLink;
import jd.plugins.FilePackage;
import jd.plugins.Plugin;
import jd.plugins.PluginForDecrypt;
import jd.plugins.PluginForHost;
import jd.plugins.PluginsC;
import jd.plugins.hoster.DirectHTTP;
import org.appwork.net.protocol.http.HTTPConstants;
import org.appwork.scheduler.DelayedRunnable;
import org.appwork.storage.config.JsonConfig;
@ -89,6 +65,30 @@ import org.jdownloader.plugins.controller.host.HostPluginController;
import org.jdownloader.plugins.controller.host.LazyHostPlugin;
import org.jdownloader.settings.GeneralSettings;
import jd.controlling.linkcollector.LinkCollectingJob;
import jd.controlling.linkcollector.LinkCollector.JobLinkCrawler;
import jd.controlling.linkcollector.LinknameCleaner;
import jd.controlling.linkcrawler.LinkCrawlerConfig.DirectHTTPPermission;
import jd.controlling.linkcrawler.LinkCrawlerRule.RULE;
import jd.http.Browser;
import jd.http.Request;
import jd.http.URLConnectionAdapter;
import jd.http.requests.PostRequest;
import jd.nutils.SimpleFTP;
import jd.nutils.encoding.Encoding;
import jd.parser.html.Form;
import jd.parser.html.HTMLParser;
import jd.parser.html.HTMLParser.HtmlParserCharSequence;
import jd.parser.html.HTMLParser.HtmlParserResultSet;
import jd.plugins.CryptedLink;
import jd.plugins.DownloadLink;
import jd.plugins.FilePackage;
import jd.plugins.Plugin;
import jd.plugins.PluginForDecrypt;
import jd.plugins.PluginForHost;
import jd.plugins.PluginsC;
import jd.plugins.hoster.DirectHTTP;
public class LinkCrawler {
private static enum DISTRIBUTE {
STOP,
@ -3028,7 +3028,7 @@ public class LinkCrawler {
}
final String name;
if (fp.isCleanupPackageName()) {
name = LinknameCleaner.cleanFileName(fp, fp.getName(), false, true, LinknameCleaner.EXTENSION_SETTINGS.REMOVE_KNOWN, true);
name = LinknameCleaner.cleanPackagename(fp.getName());
} else {
name = fp.getName();
}

View File

@ -25,24 +25,16 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.appwork.exceptions.WTFException;
import org.appwork.storage.JSonStorage;
import org.appwork.storage.TypeRef;
import org.appwork.storage.config.JsonConfig;
import org.appwork.utils.DebugMode;
import org.appwork.utils.Files;
import org.appwork.utils.Regex;
import org.appwork.utils.StringUtils;
import org.appwork.utils.os.CrossSystem;
import org.appwork.utils.reflection.Clazz;
import org.jdownloader.DomainInfo;
import org.jdownloader.controlling.DefaultDownloadLinkViewImpl;
@ -70,6 +62,7 @@ import jd.controlling.downloadcontroller.DownloadLinkCandidate;
import jd.controlling.downloadcontroller.DownloadWatchDog;
import jd.controlling.downloadcontroller.HistoryEntry;
import jd.controlling.downloadcontroller.SingleDownloadController;
import jd.controlling.linkcollector.LinknameCleaner;
import jd.controlling.linkcrawler.CheckableLink;
import jd.controlling.packagecontroller.AbstractNodeNotifier;
import jd.controlling.packagecontroller.AbstractPackageChildrenNode;
@ -1579,37 +1572,7 @@ public class DownloadLink extends Property implements Serializable, AbstractPack
}
protected String fixFilename(String filename, final boolean removeLeadingHidingDot) {
String newfinalFileName = filename;
final String toRemove = new Regex(newfinalFileName, Pattern.compile("r(?:ar|\\d{2,3})(\\.html?)$", Pattern.CASE_INSENSITIVE)).getMatch(0);
if (toRemove != null) {
System.out.println("Use Workaround for stupid >>rar.html<< uploaders!");
newfinalFileName = newfinalFileName.substring(0, newfinalFileName.length() - toRemove.length());
}
if (DebugMode.TRUE_IN_IDE_ELSE_FALSE) {
// 2023-08-04: TODO, see https://svn.jdownloader.org/issues/83699
// TODO: This should never be null ?!
final Map<String, String> forbiddenCharacterRegexReplaceMap = JsonConfig.create(GeneralSettings.class).getFilenameAndPathCharacterRegexReplaceMap();
if (forbiddenCharacterRegexReplaceMap != null && !forbiddenCharacterRegexReplaceMap.isEmpty()) {
String newfilenameTemp = newfinalFileName;
final Iterator<Entry<String, String>> iterator = forbiddenCharacterRegexReplaceMap.entrySet().iterator();
while (iterator.hasNext()) {
final Entry<String, String> entry = iterator.next();
try {
newfilenameTemp = newfilenameTemp.replaceAll(entry.getKey(), entry.getValue());
} catch (final PatternSyntaxException e) {
}
}
/**
* Users can put anything into that replace map. </br>
* Try to avoid the results of adding something like ".+" resulting in empty filenames.
*/
if (!StringUtils.isEmpty(newfilenameTemp)) {
newfinalFileName = newfilenameTemp;
}
}
}
newfinalFileName = CrossSystem.alleviatePathParts(newfinalFileName, removeLeadingHidingDot);
return newfinalFileName;
return LinknameCleaner.cleanFilename(filename, removeLeadingHidingDot);
}
/**

View File

@ -452,7 +452,7 @@ public class AllDebridCom extends PluginForHost {
}
} else {
title = "Alldebrid - Confirm new location";
message += "\r\nHello dear alldebrid user";
message += "Hello dear alldebrid user";
message += "\r\nYou were logged out because you've tried to sign in from a new location.";
message += "\r\nYou've received an e-mail with a link to confirm this new location.";
message += "\r\n Confirm this e-mail to continue using your Alldebrid account in JDownloader.";

View File

@ -8,13 +8,6 @@ import java.util.Locale;
import javax.swing.JComponent;
import javax.swing.filechooser.FileFilter;
import jd.controlling.linkcollector.LinknameCleaner;
import jd.controlling.linkcrawler.CrawledLink;
import jd.controlling.packagecontroller.AbstractPackageChildrenNode;
import jd.controlling.packagecontroller.AbstractPackageNode;
import jd.http.Browser;
import jd.plugins.DownloadLink;
import org.appwork.uio.CloseReason;
import org.appwork.utils.Application;
import org.appwork.utils.IO;
@ -36,6 +29,13 @@ import org.jdownloader.gui.views.components.packagetable.LinkTreeUtils;
import org.jdownloader.images.NewTheme;
import org.jdownloader.settings.staticreferences.CFG_GUI;
import jd.controlling.linkcollector.LinknameCleaner;
import jd.controlling.linkcrawler.CrawledLink;
import jd.controlling.packagecontroller.AbstractPackageChildrenNode;
import jd.controlling.packagecontroller.AbstractPackageNode;
import jd.http.Browser;
import jd.plugins.DownloadLink;
public class DLCFactory extends D {
public String encryptDLC(String xml) {
final String[] encrypt = encrypt(xml);
@ -89,7 +89,7 @@ public class DLCFactory extends D {
if (nodes != null && nodes.size() > 0) {
if (nodes.size() == 1) {
final String name = nodes.get(0).getName();
return LinknameCleaner.cleanFileName(name, false, false, LinknameCleaner.EXTENSION_SETTINGS.REMOVE_ALL, false) + ".dlc";
return LinknameCleaner.cleanFilename(name, true) + ".dlc";
} else {
for (AbstractPackageChildrenNode node : nodes) {
final AbstractPackageNode parent = ((AbstractPackageNode) nodes.get(0).getParentNode());

View File

@ -3,12 +3,6 @@ package org.jdownloader.gui.views.linkgrabber.contextmenu;
import java.io.File;
import java.util.List;
import jd.controlling.linkcollector.LinkCollector;
import jd.controlling.linkcollector.LinknameCleaner;
import jd.controlling.linkcrawler.CrawledLink;
import jd.controlling.linkcrawler.CrawledPackage;
import jd.controlling.linkcrawler.CrawledPackage.TYPE;
import org.appwork.utils.event.queue.Queue;
import org.appwork.utils.swing.dialog.DialogCanceledException;
import org.appwork.utils.swing.dialog.DialogClosedException;
@ -19,6 +13,12 @@ import org.jdownloader.gui.views.SelectionInfo;
import org.jdownloader.gui.views.components.packagetable.context.SetDownloadFolderAction;
import org.jdownloader.settings.staticreferences.CFG_LINKCOLLECTOR;
import jd.controlling.linkcollector.LinkCollector;
import jd.controlling.linkcollector.LinknameCleaner;
import jd.controlling.linkcrawler.CrawledLink;
import jd.controlling.linkcrawler.CrawledPackage;
import jd.controlling.linkcrawler.CrawledPackage.TYPE;
public class SetDownloadFolderInLinkgrabberAction extends SetDownloadFolderAction<CrawledPackage, CrawledLink> {
/**
*
@ -62,7 +62,7 @@ public class SetDownloadFolderInLinkgrabberAction extends SetDownloadFolderActio
final CrawledPackage pkg = new CrawledPackage();
pkg.setExpanded(CFG_LINKCOLLECTOR.CFG.isPackageAutoExpanded());
if (TYPE.NORMAL != entry.getType()) {
final String pkgName = LinknameCleaner.cleanFileName(entry, getSelection().getPackageView(entry).getChildren().get(0).getName(), false, true, LinknameCleaner.EXTENSION_SETTINGS.REMOVE_ALL, true);
final String pkgName = LinknameCleaner.cleanPackagename(getSelection().getPackageView(entry).getChildren().get(0).getName());
pkg.setName(pkgName);
} else {
pkg.setName(entry.getName());