From 06a342cdef982d9f53b1c3efcf2cbb3878e45c3f Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 29 Jun 2014 11:04:04 +0000 Subject: [PATCH] + new bindings {tags} --- .../net/filebot/format/MediaBindingBean.java | 20 ++++++++++++++ source/net/filebot/media/ReleaseInfo.java | 27 ++++++++++++++++--- .../net/filebot/media/ReleaseInfo.properties | 5 +++- .../ui/rename/BindingDialog.properties | 2 +- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 005f2b5a..dc223a19 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -3,6 +3,7 @@ package net.filebot.format; import static java.util.Arrays.*; import static net.filebot.MediaTypes.*; import static net.filebot.format.Define.*; +import static net.filebot.format.ExpressionFormatMethods.*; import static net.filebot.hash.VerificationUtilities.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.similarity.Normalization.*; @@ -426,6 +427,25 @@ public class MediaBindingBean { return releaseInfo.getVideoSource(inferredMediaFile.getParent(), inferredMediaFile.getName(), getOriginalFileName(inferredMediaFile)); } + @Define("tags") + public List getVideoTags() { + // use inferred media file + File inferredMediaFile = getInferredMediaFile(); + + // look for video source patterns in media file and it's parent folder + List matches = releaseInfo.getVideoTags(inferredMediaFile.getParent(), inferredMediaFile.getName(), getOriginalFileName(inferredMediaFile)); + if (matches.isEmpty()) { + return null; + } + + Set tags = new TreeSet(String.CASE_INSENSITIVE_ORDER); + for (String m : matches) { + // heavy normalization of whatever pattern was matched with the regex pattern + tags.add(lowerTrail(upperInitial(normalizePunctuation(normalizeSpace(m, " "))))); + } + return new ArrayList(tags); + } + @Define("group") public String getReleaseGroup() throws IOException { // use inferred media file diff --git a/source/net/filebot/media/ReleaseInfo.java b/source/net/filebot/media/ReleaseInfo.java index f4239ad7..ad048800 100644 --- a/source/net/filebot/media/ReleaseInfo.java +++ b/source/net/filebot/media/ReleaseInfo.java @@ -42,9 +42,24 @@ import org.tukaani.xz.XZInputStream; public class ReleaseInfo { - public String getVideoSource(String... strings) { + public String getVideoSource(String... input) { // check parent and itself for group names - return matchLast(getVideoSourcePattern(), getBundle(getClass().getName()).getString("pattern.video.source").split("[|]"), strings); + return matchLast(getVideoSourcePattern(), getBundle(getClass().getName()).getString("pattern.video.source").split("[|]"), input); + } + + public List getVideoTags(String... input) { + Pattern videoTagPattern = getVideoTagPattern(); + List tags = new ArrayList(); + for (String s : input) { + if (s == null) + continue; + + Matcher m = videoTagPattern.matcher(s); + while (m.find()) { + tags.add(m.group()); + } + } + return tags; } public String getReleaseGroup(String... strings) throws IOException { @@ -240,11 +255,17 @@ public class ReleaseInfo { } public Pattern getVideoSourcePattern() { - // pattern matching any video source name + // pattern matching any video source name, like BluRay String pattern = getBundle(getClass().getName()).getString("pattern.video.source"); return compile("(?