From ffdc8f43f268b711caa9e621137203b479b0ff42 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 3 Sep 2014 04:16:50 +0000 Subject: [PATCH] * refactor --- .../net/filebot/format/MediaBindingBean.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 9dfaba4e..78753417 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Scanner; import java.util.Set; import java.util.SortedSet; @@ -213,7 +214,7 @@ public class MediaBindingBean { return asList(getSeriesObject().getAliasNames()); } - return null; + return emptyList(); } @Define("primaryTitle") @@ -457,20 +458,7 @@ public class MediaBindingBean { String[] filenames = new String[] { inferredMediaFile.getParentFile().getName(), inferredMediaFile.getName(), getOriginalFileName(inferredMediaFile) }; // reduce false positives by removing the know titles from the name - List titles = new ArrayList(); - titles.add(getName()); - titles.add(getYear().toString()); - titles.addAll(getAliasNames()); - if (infoObject instanceof Episode) { - for (Episode it : getEpisodes()) { - titles.add(it.getTitle()); - } - } - for (int i = 0; i < titles.size(); i++) { - titles.set(i, normalizePunctuation(normalizeSpace(titles.get(i), " "))); - } - - Pattern nonGroupPattern = releaseInfo.getCustomRemovePattern(titles); + Pattern nonGroupPattern = releaseInfo.getCustomRemovePattern(getKeywords()); for (int i = 0; i < filenames.length; i++) { if (filenames[i] == null) continue; @@ -981,6 +969,27 @@ public class MediaBindingBean { return s.toString().trim(); } + private List getKeywords() { + List keys = new ArrayList(); + keys.add(getName()); + keys.add(getYear()); + keys.addAll(getAliasNames()); + if (infoObject instanceof Episode) { + for (Episode it : getEpisodes()) { + keys.add(it.getTitle()); + } + } + + List words = new ArrayList(); + for (Object it : keys) { + String w = normalizePunctuation(normalizeSpace(Objects.toString(it, ""), " ")); + if (w != null && w.length() > 0) { + words.add(w); + } + } + return words; + } + @Override public String toString() { return String.format("%s ⇔ %s", infoObject, mediaFile == null ? null : mediaFile.getName());