This commit is contained in:
Reinhard Pointner 2016-04-05 18:06:23 +00:00
parent de6a51e3fc
commit 7bcfd7aa19
10 changed files with 26 additions and 35 deletions

View File

@ -170,7 +170,7 @@ public class CmdlineOperations implements CmdlineInterface {
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
// auto-determine optimal batch sets
for (Entry<Set<File>, Set<String>> sameSeriesGroup : mapSeriesNamesByFiles(mediaFiles, locale, db != AniDB, db == AniDB).entrySet()) {
for (Entry<Set<File>, Set<String>> sameSeriesGroup : mapSeriesNamesByFiles(mediaFiles, locale, db == AniDB).entrySet()) {
List<List<File>> batchSets = new ArrayList<List<File>>();
if (sameSeriesGroup.getValue() != null && sameSeriesGroup.getValue().size() > 0) {
@ -187,7 +187,7 @@ public class CmdlineOperations implements CmdlineInterface {
// auto-detect series name if not given
if (query == null) {
// detect series name by common word sequence
seriesNames = detectSeriesNames(batch, db != AniDB, db == AniDB, locale);
seriesNames = detectSeriesNames(batch, db == AniDB, locale);
log.config("Auto-detected query: " + seriesNames);
} else {
// use --q option

View File

@ -204,19 +204,19 @@ public abstract class ScriptShellBaseClass extends Script {
}
public String detectSeriesName(Object files) throws Exception {
return detectSeriesName(files, true, false);
return detectSeriesName(files, false);
}
public String detectAnimeName(Object files) throws Exception {
return detectSeriesName(files, false, true);
return detectSeriesName(files, true);
}
public String detectSeriesName(Object files, boolean useSeriesIndex, boolean useAnimeIndex) throws Exception {
public String detectSeriesName(Object files, boolean anime) throws Exception {
List<File> input = FileUtilities.asFileList(files);
if (input.isEmpty())
return null;
List<String> names = MediaDetection.detectSeriesNames(input, useSeriesIndex, useAnimeIndex, Locale.ENGLISH);
List<String> names = MediaDetection.detectSeriesNames(input, anime, Locale.ENGLISH);
return names == null || names.isEmpty() ? null : names.get(0);
}

View File

@ -98,9 +98,9 @@ public class AutoDetection {
}
private List<String> detectSeries(File f, boolean anime) throws Exception {
List<String> names = detectSeriesNames(singleton(f), !anime, anime, locale);
List<String> names = detectSeriesNames(singleton(f), anime, locale);
if (names.isEmpty()) {
names = detectSeriesNames(getVideoFiles(f.getParentFile()), !anime, anime, locale);
names = detectSeriesNames(getVideoFiles(f.getParentFile()), anime, locale);
}
return names;
}

View File

@ -181,14 +181,14 @@ public class MediaDetection {
return getDateMatcher().match(object.toString());
}
public static Map<Set<File>, Set<String>> mapSeriesNamesByFiles(Collection<File> files, Locale locale, boolean useSeriesIndex, boolean useAnimeIndex) throws Exception {
public static Map<Set<File>, Set<String>> mapSeriesNamesByFiles(Collection<File> files, Locale locale, boolean anime) throws Exception {
// map series names by folder
Map<File, Set<String>> seriesNamesByFolder = new HashMap<File, Set<String>>();
Map<File, List<File>> filesByFolder = mapByFolder(files);
for (Entry<File, List<File>> it : filesByFolder.entrySet()) {
Set<String> namesForFolder = new TreeSet<String>(getLenientCollator(locale));
namesForFolder.addAll(detectSeriesNames(it.getValue(), useSeriesIndex, useAnimeIndex, locale));
namesForFolder.addAll(detectSeriesNames(it.getValue(), anime, locale));
seriesNamesByFolder.put(it.getKey(), namesForFolder);
}
@ -317,14 +317,8 @@ public class MediaDetection {
return match;
}
public static List<String> detectSeriesNames(Collection<File> files, boolean useSeriesIndex, boolean useAnimeIndex, Locale locale) throws Exception {
List<IndexEntry<SearchResult>> index = new ArrayList<IndexEntry<SearchResult>>();
if (useSeriesIndex)
index.addAll(getSeriesIndex());
if (useAnimeIndex)
index.addAll(getAnimeIndex());
return detectSeriesNames(files, index, locale);
public static List<String> detectSeriesNames(Collection<File> files, boolean anime, Locale locale) throws Exception {
return detectSeriesNames(files, anime ? getAnimeIndex() : getSeriesIndex(), locale);
}
public static List<String> detectSeriesNames(Collection<File> files, List<IndexEntry<SearchResult>> index, Locale locale) throws Exception {
@ -1065,11 +1059,11 @@ public class MediaDetection {
return map;
}
public static Map<String, List<File>> mapBySeriesName(Collection<File> files, boolean useSeriesIndex, boolean useAnimeIndex, Locale locale) throws Exception {
public static Map<String, List<File>> mapBySeriesName(Collection<File> files, boolean anime, Locale locale) throws Exception {
Map<String, List<File>> result = new TreeMap<String, List<File>>(String.CASE_INSENSITIVE_ORDER);
for (File f : files) {
List<String> names = detectSeriesNames(singleton(f), useSeriesIndex, useAnimeIndex, locale);
List<String> names = detectSeriesNames(singleton(f), anime, locale);
String key = names.isEmpty() ? "" : names.get(0);
List<File> value = result.get(key);

View File

@ -97,7 +97,7 @@ public final class SubtitleUtilities {
Map<File, List<SubtitleDescriptor>> subtitlesByFile = new HashMap<File, List<SubtitleDescriptor>>();
for (List<File> byMediaFolder : mapByMediaFolder(fileSet).values()) {
for (Entry<String, List<File>> bySeries : mapBySeriesName(byMediaFolder, true, false, Locale.ENGLISH).entrySet()) {
for (Entry<String, List<File>> bySeries : mapBySeriesName(byMediaFolder, false, Locale.ENGLISH).entrySet()) {
// allow early abort
if (Thread.interrupted())
throw new InterruptedException();

View File

@ -54,9 +54,7 @@ import net.filebot.web.SortOrder;
class EpisodeListMatcher implements AutoCompleteMatcher {
private EpisodeListProvider provider;
private boolean useAnimeIndex;
private boolean useSeriesIndex;
private boolean anime;
// remember user selections
private TypedCache<SearchResult> persistentSelectionMemory;
@ -64,10 +62,9 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
// only allow one fetch session at a time so later requests can make use of cached results
private final Object providerLock = new Object();
public EpisodeListMatcher(EpisodeListProvider provider, boolean useSeriesIndex, boolean useAnimeIndex) {
public EpisodeListMatcher(EpisodeListProvider provider, boolean anime) {
this.provider = provider;
this.useSeriesIndex = useSeriesIndex;
this.useAnimeIndex = useAnimeIndex;
this.anime = anime;
this.persistentSelectionMemory = Cache.getCache("selection_" + provider.getName(), CacheType.Persistent).cast(SearchResult.class);
}
@ -214,14 +211,14 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
@Override
public List<Match<File, ?>> call() throws Exception {
return matchEpisodeSet(singletonList(file), detectSeriesNames(singleton(file), useSeriesIndex, useAnimeIndex, locale), sortOrder, strict, locale, autodetection, selectionMemory, inputMemory, parent);
return matchEpisodeSet(singletonList(file), detectSeriesNames(singleton(file), anime, locale), sortOrder, strict, locale, autodetection, selectionMemory, inputMemory, parent);
}
});
}
}
} else {
// in non-strict mode use the complicated (more powerful but also more error prone) match-batch-by-batch logic
for (Entry<Set<File>, Set<String>> sameSeriesGroup : mapSeriesNamesByFiles(mediaFiles, locale, useSeriesIndex, useAnimeIndex).entrySet()) {
for (Entry<Set<File>, Set<String>> sameSeriesGroup : mapSeriesNamesByFiles(mediaFiles, locale, anime).entrySet()) {
final List<List<File>> batchSets = new ArrayList<List<File>>();
final Collection<String> queries = sameSeriesGroup.getValue();
@ -307,7 +304,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
// require user input if auto-detection has failed or has been disabled
if (episodes.isEmpty() && !strict) {
List<String> detectedSeriesNames = detectSeriesNames(files, useSeriesIndex, useAnimeIndex, locale);
List<String> detectedSeriesNames = detectSeriesNames(files, anime, locale);
String parentPathHint = normalizePathSeparators(getRelativePathTail(files.get(0).getParentFile(), 2).getPath());
String suggestion = detectedSeriesNames.size() > 0 ? join(detectedSeriesNames, "; ") : normalizePunctuation(getName(files.get(0)));

View File

@ -99,7 +99,7 @@ public class Preset {
EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database);
if (sdb != null) {
return new EpisodeListMatcher(sdb, sdb != WebServices.AniDB, sdb == WebServices.AniDB);
return new EpisodeListMatcher(sdb, sdb == WebServices.AniDB);
}
MusicIdentificationService adb = WebServices.getMusicIdentificationService(database);

View File

@ -432,7 +432,7 @@ public class RenamePanel extends JComponent {
// create actions for match popup episode list completion
for (EpisodeListProvider db : WebServices.getEpisodeListProviders()) {
actionPopup.add(new AutoCompleteAction(db.getName(), db.getIcon(), new EpisodeListMatcher(db, db != WebServices.AniDB, db == WebServices.AniDB)));
actionPopup.add(new AutoCompleteAction(db.getName(), db.getIcon(), new EpisodeListMatcher(db, db == WebServices.AniDB)));
}
actionPopup.addSeparator();

View File

@ -1,5 +1,6 @@
package net.filebot.ui.subtitle.upload;
import static java.util.Collections.*;
import static net.filebot.Logging.*;
import static net.filebot.media.MediaDetection.*;
import static net.filebot.util.ui.SwingUI.*;
@ -11,7 +12,6 @@ import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -162,7 +162,7 @@ public class SubtitleUploadDialog extends JDialog {
mapping.setState(Status.Identifying);
try {
if (MediaDetection.isEpisode(mapping.getVideo().getPath(), true)) {
List<String> seriesNames = MediaDetection.detectSeriesNames(Collections.singleton(mapping.getVideo()), true, false, Locale.ENGLISH);
List<String> seriesNames = MediaDetection.detectSeriesNames(singleton(mapping.getVideo()), false, Locale.ENGLISH);
NAMES: for (String name : seriesNames) {
List<SearchResult> options = WebServices.TheTVDB.search(name, Locale.ENGLISH);
for (SearchResult entry : options) {

View File

@ -23,7 +23,7 @@ public class MediaDetectionTest {
@Test
public void detectSeriesName() throws Exception {
assertEquals("[]", MediaDetection.detectSeriesNames(singleton(new File("Movie/LOTR.2001.AVC-1080")), true, false, Locale.ENGLISH).toString());
assertEquals("[]", MediaDetection.detectSeriesNames(singleton(new File("Movie/LOTR.2001.AVC-1080")), false, Locale.ENGLISH).toString());
}
}