1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

* make use of original-filename xattr in {source} and {group} bindings

This commit is contained in:
Reinhard Pointner 2012-10-24 11:57:36 +00:00
parent 2d9242a13b
commit c2398cc6b0
5 changed files with 32 additions and 15 deletions

View File

@ -27,6 +27,7 @@ import java.util.TreeSet;
import net.sourceforge.filebot.Cache; import net.sourceforge.filebot.Cache;
import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.hash.HashType; import net.sourceforge.filebot.hash.HashType;
import net.sourceforge.filebot.media.MetaAttributes;
import net.sourceforge.filebot.mediainfo.MediaInfo; import net.sourceforge.filebot.mediainfo.MediaInfo;
import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind; import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind;
import net.sourceforge.filebot.web.Date; import net.sourceforge.filebot.web.Date;
@ -278,6 +279,12 @@ public class MediaBindingBean {
} }
@Define("original")
public String getOriginalFileName() {
return getOriginalFileName(mediaFile);
}
@Define("crc32") @Define("crc32")
public String getCRC32() throws IOException, InterruptedException { public String getCRC32() throws IOException, InterruptedException {
// use inferred media file // use inferred media file
@ -326,7 +333,7 @@ public class MediaBindingBean {
File inferredMediaFile = getInferredMediaFile(); File inferredMediaFile = getInferredMediaFile();
// look for video source patterns in media file and it's parent folder // 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(); File inferredMediaFile = getInferredMediaFile();
// look for release group names in media file and it's parent folder // 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); cache.put(file, hash);
return hash; return hash;
} }
private String getOriginalFileName(File file) {
try {
return new MetaAttributes(file).getOriginalName();
} catch (Throwable e) {
return null;
}
}
} }

View File

@ -782,11 +782,11 @@ public class MediaDetection {
public static void storeMetaInfo(File file, Object model) { public static void storeMetaInfo(File file, Object model) {
// original filename // original filename
MetaAttributes metadata = new MetaAttributes(file); MetaAttributes metadata = new MetaAttributes(file);
metadata.putFileName(file.getName()); metadata.setOriginalName(file.getName());
// store model as metadata // store model as metadata
if (model instanceof Episode || model instanceof Movie) { if (model instanceof Episode || model instanceof Movie) {
metadata.putMetaData(model); metadata.setMetaData(model);
} }
// set creation date to episode / movie release date // set creation date to episode / movie release date

View File

@ -41,23 +41,23 @@ public class MetaAttributes {
public long getCreationDate(long time) { public long getCreationDate(long time) {
try { try {
return fileAttributeView.readAttributes().creationTime().toMillis(); return fileAttributeView.readAttributes().creationTime().toMillis();
} catch (IOException e) { } catch (Exception e) {
return 0; return 0;
} }
} }
public void putFileName(String name) { public void setOriginalName(String name) {
metaAttributeView.put(FILENAME_KEY, name); metaAttributeView.put(FILENAME_KEY, name);
} }
public void getFileName(String name) { public String getOriginalName() {
metaAttributeView.get(FILENAME_KEY); return metaAttributeView.get(FILENAME_KEY);
} }
public void putMetaData(Object object) { public void setMetaData(Object object) {
metaAttributeView.put(METADATA_KEY, JsonWriter.toJson(object)); metaAttributeView.put(METADATA_KEY, JsonWriter.toJson(object));
} }

View File

@ -43,23 +43,22 @@ import net.sourceforge.tuned.ByteBufferInputStream;
public class ReleaseInfo { public class ReleaseInfo {
public String getVideoSource(File file) { public String getVideoSource(String... strings) {
// check parent and itself for group names // 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 // check file and folder for release group names
String[] groups = releaseGroupResource.get(); String[] groups = releaseGroupResource.get();
String[] files = new String[] { file.getParentFile().getName(), file.getName() };
// try case-sensitive match // try case-sensitive match
String match = matchLast(getReleaseGroupPattern(true), groups, files); String match = matchLast(getReleaseGroupPattern(true), groups, strings);
// try case-insensitive match as fallback // try case-insensitive match as fallback
if (match == null) { if (match == null) {
match = matchLast(getReleaseGroupPattern(false), groups, files); match = matchLast(getReleaseGroupPattern(false), groups, strings);
} }
return match; return match;

View File

@ -161,6 +161,7 @@ unrated
unrated.edition unrated.edition
UsaBit.com UsaBit.com
video[s]? video[s]?
VOSTFR
www[.][\w-.]+[.](com|net|tk|ro|cd) www[.][\w-.]+[.](com|net|tk|ro|cd)
xRipp xRipp
Zune Zune