diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 284896b0..9615e794 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -175,7 +175,7 @@ public class MediaBindingBean { } // enforce title length limit by default - return truncateText(infoObject instanceof MultiEpisode ? SeasonEpisode.formatMultiTitle(getEpisodes()) : getEpisode().getTitle(), 150); + return truncateText(SeasonEpisode.formatMultiTitle(getEpisodes()), NamingStandard.TITLE_MAX_LENGTH); } @Define("d") @@ -846,7 +846,7 @@ public class MediaBindingBean { @Define("episodes") public List getEpisodes() { - return infoObject instanceof MultiEpisode ? ((MultiEpisode) infoObject).getEpisodes() : asList(getEpisode()); + return infoObject instanceof MultiEpisode ? ((MultiEpisode) infoObject).getEpisodes() : singletonList(getEpisode()); } @Define("movie") @@ -1103,7 +1103,7 @@ public class MediaBindingBean { private List getKeywords() { // collect key information - Set keys = new HashSet(); + List keys = new ArrayList(); keys.add(getName()); keys.add(getYear()); keys.addAll(getAliasNames()); @@ -1116,14 +1116,9 @@ public class MediaBindingBean { } // word list for exclude pattern - List words = new ArrayList(keys.size()); - for (Object it : keys) { - String w = normalizePunctuation(normalizeSpace(Objects.toString(it, ""), " ")); - if (w != null && w.length() > 0) { - words.add(w); - } - } - return words; + return keys.stream().filter(Objects::nonNull).map(it -> { + return normalizePunctuation(normalizeSpace(it.toString(), " ")); + }).filter(s -> s.length() > 0).distinct().collect(toList()); } @Override diff --git a/source/net/filebot/media/NamingStandard.java b/source/net/filebot/media/NamingStandard.java index f7f9a388..11d4b68b 100644 --- a/source/net/filebot/media/NamingStandard.java +++ b/source/net/filebot/media/NamingStandard.java @@ -1,6 +1,7 @@ package net.filebot.media; import static java.util.Arrays.*; +import static java.util.Collections.*; import static java.util.stream.Collectors.*; import static net.filebot.WebServices.*; import static net.filebot.similarity.Normalization.*; @@ -20,6 +21,8 @@ public enum NamingStandard { Plex; + public static final int TITLE_MAX_LENGTH = 150; + public String getPath(Object o) { if (o instanceof Episode) return getPath((Episode) o); @@ -33,7 +36,7 @@ public enum NamingStandard { public String getPath(Episode e) { // enforce title length limit by default - String episodeTitle = truncateText(e instanceof MultiEpisode ? SeasonEpisode.formatMultiTitle(((MultiEpisode) e).getEpisodes()) : e.getTitle(), 150); + String episodeTitle = truncateText(SeasonEpisode.formatMultiTitle(e instanceof MultiEpisode ? ((MultiEpisode) e).getEpisodes() : singletonList(e)), TITLE_MAX_LENGTH); // Anime if (isAnime(e)) { diff --git a/source/net/filebot/similarity/EpisodeMetrics.java b/source/net/filebot/similarity/EpisodeMetrics.java index d89f3953..990b2e57 100644 --- a/source/net/filebot/similarity/EpisodeMetrics.java +++ b/source/net/filebot/similarity/EpisodeMetrics.java @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -118,9 +119,11 @@ public enum EpisodeMetrics implements SimilarityMetric { Episode e = (Episode) object; // don't use title for matching if title equals series name - String normalizedToken = normalizeObject(e.getTitle() == null ? null : removeTrailingBrackets(e.getTitle())); - if (normalizedToken.length() >= 4 && !normalizeObject(e.getSeriesName()).contains(normalizedToken)) { - return normalizedToken; + if (e.getTitle() != null) { + String title = normalizeObject(removeTrailingBrackets(e.getTitle())); + if (title.length() >= 4 && !normalizeObject(e.getSeriesName()).contains(title)) { + return title; + } } } @@ -200,7 +203,7 @@ public enum EpisodeMetrics implements SimilarityMetric { protected Object[] fields(Object object) { if (object instanceof Episode) { Episode e = (Episode) object; - return StreamEx.of(e.getSeriesName(), e.getTitle()).append(e.getSeriesNames()).map(Normalization::removeTrailingBrackets).distinct().limit(5).toArray(); + return StreamEx.of(e.getSeriesName(), e.getTitle()).append(e.getSeriesNames()).filter(Objects::nonNull).map(Normalization::removeTrailingBrackets).distinct().limit(5).toArray(); } if (object instanceof File) { diff --git a/source/net/filebot/web/EpisodeFormat.java b/source/net/filebot/web/EpisodeFormat.java index 74d36e79..fa77692b 100644 --- a/source/net/filebot/web/EpisodeFormat.java +++ b/source/net/filebot/web/EpisodeFormat.java @@ -8,6 +8,7 @@ import java.text.Format; import java.text.ParseException; import java.text.ParsePosition; import java.util.Collection; +import java.util.Objects; import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; @@ -17,6 +18,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; +import net.filebot.similarity.Normalization; + public class EpisodeFormat extends Format { public static final EpisodeFormat SeasonEpisode = new EpisodeFormat(); @@ -60,10 +63,10 @@ public class EpisodeFormat extends Format { public String formatMultiEpisode(Collection episodes) { Function seriesName = it -> it.getSeriesName(); Function episodeNumber = it -> formatSxE(it); - Function episodeTitle = it -> removeTrailingBrackets(it.getTitle()); + Function episodeTitle = it -> it.getTitle() == null ? "" : removeTrailingBrackets(it.getTitle()); return Stream.of(seriesName, episodeNumber, episodeTitle).map(f -> { - return episodes.stream().map(f::apply).distinct().collect(joining(" & ")); + return episodes.stream().map(f::apply).filter(s -> s.length() > 0).distinct().collect(joining(" & ")); }).collect(joining(" - ")); } @@ -98,7 +101,7 @@ public class EpisodeFormat extends Format { } public String formatMultiTitle(Collection episodes) { - return episodes.stream().map(it -> removeTrailingBrackets(it.getTitle())).distinct().collect(joining(" & ")); + return episodes.stream().map(Episode::getTitle).filter(Objects::nonNull).map(Normalization::removeTrailingBrackets).distinct().collect(joining(" & ")); } public String formatMultiRangeSxE(Iterable episodes) {