1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 16:28:51 -05:00

Episode title can be null. Make sure to avoid NPE when episode title is used.

This commit is contained in:
Reinhard Pointner 2016-05-12 23:54:49 +08:00
parent f8c4768119
commit 60bd6df2f8
4 changed files with 23 additions and 19 deletions

View File

@ -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<Episode> 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<String> getKeywords() {
// collect key information
Set<Object> keys = new HashSet<Object>();
List<Object> keys = new ArrayList<Object>();
keys.add(getName());
keys.add(getYear());
keys.addAll(getAliasNames());
@ -1116,14 +1116,9 @@ public class MediaBindingBean {
}
// word list for exclude pattern
List<String> words = new ArrayList<String>(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

View File

@ -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)) {

View File

@ -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) {

View File

@ -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<Episode> episodes) {
Function<Episode, String> seriesName = it -> it.getSeriesName();
Function<Episode, String> episodeNumber = it -> formatSxE(it);
Function<Episode, String> episodeTitle = it -> removeTrailingBrackets(it.getTitle());
Function<Episode, String> 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<Episode> 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<Episode> episodes) {