mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 16:28:51 -05:00
When matching AniDB->TheTVDB series names, do so as leniently as possible (e.g. One-Punch == One Punch)
@see https://www.filebot.net/forums/viewtopic.php?f=5&t=3979&p=22324#p22324
This commit is contained in:
parent
c6971a30c3
commit
f43a37ed64
@ -3,10 +3,13 @@ package net.filebot.web;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.filebot.WebServices;
|
||||
|
||||
@ -30,6 +33,8 @@ public final class EpisodeUtilities {
|
||||
|
||||
public static Episode getEpisodeByAbsoluteNumber(Episode e, EpisodeListProvider service, SortOrder order) throws Exception {
|
||||
// e.g. match AniDB episode to TheTVDB episode
|
||||
Set<String> seriesNames = getLenientSeriesNameSet(e);
|
||||
|
||||
SeriesInfo seriesInfo = e.getSeriesInfo();
|
||||
Locale locale = new Locale(seriesInfo.getLanguage());
|
||||
|
||||
@ -38,7 +43,7 @@ public final class EpisodeUtilities {
|
||||
|
||||
for (SearchResult series : service.search(seriesInfo.getName(), locale)) {
|
||||
// sanity check
|
||||
if (!series.getEffectiveNames().contains(seriesInfo.getName())) {
|
||||
if (!series.getEffectiveNames().stream().anyMatch(seriesNames::contains)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -62,6 +67,17 @@ public final class EpisodeUtilities {
|
||||
return e;
|
||||
}
|
||||
|
||||
private static Set<String> getLenientSeriesNameSet(Episode e) {
|
||||
// use maximum strength collator by default
|
||||
Collator collator = Collator.getInstance(new Locale(e.getSeriesInfo().getLanguage()));
|
||||
collator.setDecomposition(Collator.FULL_DECOMPOSITION);
|
||||
collator.setStrength(Collator.PRIMARY);
|
||||
|
||||
Set<String> seriesNames = new TreeSet<String>(collator);
|
||||
seriesNames.addAll(e.getSeriesNames());
|
||||
return seriesNames;
|
||||
}
|
||||
|
||||
public static List<Episode> filterBySeason(Collection<Episode> episodes, int season) {
|
||||
return episodes.stream().filter(it -> {
|
||||
return it.getSeason() != null && season == it.getSeason();
|
||||
|
Loading…
Reference in New Issue
Block a user