From c2398cc6b04000a0ae344358fdfc95f91081d480 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 24 Oct 2012 11:57:36 +0000 Subject: [PATCH] * make use of original-filename xattr in {source} and {group} bindings --- .../filebot/format/MediaBindingBean.java | 21 +++++++++++++++++-- .../filebot/media/MediaDetection.java | 4 ++-- .../filebot/media/MetaAttributes.java | 10 ++++----- .../filebot/media/ReleaseInfo.java | 11 +++++----- website/data/query-blacklist.txt | 1 + 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/source/net/sourceforge/filebot/format/MediaBindingBean.java b/source/net/sourceforge/filebot/format/MediaBindingBean.java index 918e2631..b449d69e 100644 --- a/source/net/sourceforge/filebot/format/MediaBindingBean.java +++ b/source/net/sourceforge/filebot/format/MediaBindingBean.java @@ -27,6 +27,7 @@ import java.util.TreeSet; import net.sourceforge.filebot.Cache; import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.hash.HashType; +import net.sourceforge.filebot.media.MetaAttributes; import net.sourceforge.filebot.mediainfo.MediaInfo; import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind; import net.sourceforge.filebot.web.Date; @@ -278,6 +279,12 @@ public class MediaBindingBean { } + @Define("original") + public String getOriginalFileName() { + return getOriginalFileName(mediaFile); + } + + @Define("crc32") public String getCRC32() throws IOException, InterruptedException { // use inferred media file @@ -326,7 +333,7 @@ public class MediaBindingBean { File inferredMediaFile = getInferredMediaFile(); // look for video source patterns in media file and it's parent folder - return releaseInfo.getVideoSource(inferredMediaFile); + return releaseInfo.getVideoSource(inferredMediaFile.getParent(), getOriginalFileName(inferredMediaFile), inferredMediaFile.getName()); } @@ -336,7 +343,7 @@ public class MediaBindingBean { File inferredMediaFile = getInferredMediaFile(); // look for release group names in media file and it's parent folder - return releaseInfo.getReleaseGroup(inferredMediaFile); + return releaseInfo.getReleaseGroup(inferredMediaFile.getParent(), getOriginalFileName(inferredMediaFile), inferredMediaFile.getName()); } @@ -619,4 +626,14 @@ public class MediaBindingBean { cache.put(file, hash); return hash; } + + + private String getOriginalFileName(File file) { + try { + return new MetaAttributes(file).getOriginalName(); + } catch (Throwable e) { + return null; + } + } + } diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 97733356..b1df2c77 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -782,11 +782,11 @@ public class MediaDetection { public static void storeMetaInfo(File file, Object model) { // original filename MetaAttributes metadata = new MetaAttributes(file); - metadata.putFileName(file.getName()); + metadata.setOriginalName(file.getName()); // store model as metadata if (model instanceof Episode || model instanceof Movie) { - metadata.putMetaData(model); + metadata.setMetaData(model); } // set creation date to episode / movie release date diff --git a/source/net/sourceforge/filebot/media/MetaAttributes.java b/source/net/sourceforge/filebot/media/MetaAttributes.java index e20d9f6f..c7aeb7af 100644 --- a/source/net/sourceforge/filebot/media/MetaAttributes.java +++ b/source/net/sourceforge/filebot/media/MetaAttributes.java @@ -41,23 +41,23 @@ public class MetaAttributes { public long getCreationDate(long time) { try { return fileAttributeView.readAttributes().creationTime().toMillis(); - } catch (IOException e) { + } catch (Exception e) { return 0; } } - public void putFileName(String name) { + public void setOriginalName(String name) { metaAttributeView.put(FILENAME_KEY, name); } - public void getFileName(String name) { - metaAttributeView.get(FILENAME_KEY); + public String getOriginalName() { + return metaAttributeView.get(FILENAME_KEY); } - public void putMetaData(Object object) { + public void setMetaData(Object object) { metaAttributeView.put(METADATA_KEY, JsonWriter.toJson(object)); } diff --git a/source/net/sourceforge/filebot/media/ReleaseInfo.java b/source/net/sourceforge/filebot/media/ReleaseInfo.java index a3ba60fb..64a2b9f2 100644 --- a/source/net/sourceforge/filebot/media/ReleaseInfo.java +++ b/source/net/sourceforge/filebot/media/ReleaseInfo.java @@ -43,23 +43,22 @@ import net.sourceforge.tuned.ByteBufferInputStream; public class ReleaseInfo { - public String getVideoSource(File file) { + public String getVideoSource(String... strings) { // check parent and itself for group names - return matchLast(getVideoSourcePattern(), getBundle(getClass().getName()).getString("pattern.video.source").split("[|]"), file.getParent(), file.getName()); + return matchLast(getVideoSourcePattern(), getBundle(getClass().getName()).getString("pattern.video.source").split("[|]"), strings); } - public String getReleaseGroup(File file) throws IOException { + public String getReleaseGroup(String... strings) throws IOException { // check file and folder for release group names String[] groups = releaseGroupResource.get(); - String[] files = new String[] { file.getParentFile().getName(), file.getName() }; // try case-sensitive match - String match = matchLast(getReleaseGroupPattern(true), groups, files); + String match = matchLast(getReleaseGroupPattern(true), groups, strings); // try case-insensitive match as fallback if (match == null) { - match = matchLast(getReleaseGroupPattern(false), groups, files); + match = matchLast(getReleaseGroupPattern(false), groups, strings); } return match; diff --git a/website/data/query-blacklist.txt b/website/data/query-blacklist.txt index 529a2b19..8c7a3bf5 100644 --- a/website/data/query-blacklist.txt +++ b/website/data/query-blacklist.txt @@ -161,6 +161,7 @@ unrated unrated.edition UsaBit.com video[s]? +VOSTFR www[.][\w-.]+[.](com|net|tk|ro|cd) xRipp Zune \ No newline at end of file