diff --git a/source/net/sourceforge/filebot/FileBotUtilities.java b/source/net/sourceforge/filebot/FileBotUtilities.java index 13b5c1b9..6075d7cb 100644 --- a/source/net/sourceforge/filebot/FileBotUtilities.java +++ b/source/net/sourceforge/filebot/FileBotUtilities.java @@ -8,7 +8,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import net.sourceforge.tuned.FileUtilities; -import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter; public final class FileBotUtilities { @@ -61,20 +60,20 @@ public final class FileBotUtilities { return string.replaceAll("[\\(\\[]\\p{XDigit}{8}[\\]\\)]", ""); } - public static final FileFilter TORRENT_FILES = new ExtensionFileFilter("torrent"); - public static final FileFilter SFV_FILES = new ExtensionFileFilter("sfv"); - public static final FileFilter LIST_FILES = new ExtensionFileFilter("txt", "list", ""); - public static final FileFilter SUBTITLE_FILES = new ExtensionFileFilter("srt", "sub", "ssa", "ass", "smi"); + public static final FileFilter TORRENT_FILES = MediaTypes.getDefault().filter("application/torrent"); + public static final FileFilter LIST_FILES = MediaTypes.getDefault().filter("application/list"); + public static final FileFilter VIDEO_FILES = MediaTypes.getDefault().filter("video"); + public static final FileFilter SUBTITLE_FILES = MediaTypes.getDefault().filter("subtitle"); + public static final FileFilter SFV_FILES = MediaTypes.getDefault().filter("verification/sfv"); /** - * This filter does not filter by extension, but file size. All files larger than 10 MB - * will be accepted. + * This filter will accept all video files larger than 20 MB. */ public static final FileFilter MOVIE_FILES = new FileFilter() { @Override public boolean accept(File file) { - return file.length() > 10 * FileUtilities.MEGA; + return VIDEO_FILES.accept(file) && file.length() > 20 * FileUtilities.MEGA; } }; diff --git a/source/net/sourceforge/filebot/MediaTypes.java b/source/net/sourceforge/filebot/MediaTypes.java new file mode 100644 index 00000000..97bc652d --- /dev/null +++ b/source/net/sourceforge/filebot/MediaTypes.java @@ -0,0 +1,72 @@ + +package net.sourceforge.filebot; + + +import static java.util.Collections.*; + +import java.io.FileFilter; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter; + + +@XmlRootElement(name = "media-types") +public class MediaTypes { + + @XmlElement(name = "type") + private Type[] types; + + + private static class Type { + @XmlAttribute(name = "name") + private String name; + + @XmlElement(name = "extension") + private String[] extensions; + } + + private static MediaTypes instance; + + + public static synchronized MediaTypes getDefault() { + if (instance == null) { + try { + Unmarshaller unmarshaller = JAXBContext.newInstance(MediaTypes.class).createUnmarshaller(); + + // initialize singleton instance + instance = (MediaTypes) unmarshaller.unmarshal(MediaTypes.class.getResource("media.types")); + } catch (JAXBException e) { + throw new RuntimeException(e); + } + } + + return instance; + } + + + public FileFilter filter(String path) { + return new ExtensionFileFilter(extensions(path)); + } + + + public String[] extensions(String path) { + List extensions = new ArrayList(); + + for (Type type : types) { + if (type.name.startsWith(path)) { + addAll(extensions, type.extensions); + } + } + + return extensions.toArray(new String[0]); + } + +} diff --git a/source/net/sourceforge/filebot/media.types b/source/net/sourceforge/filebot/media.types new file mode 100644 index 00000000..d5f2157f --- /dev/null +++ b/source/net/sourceforge/filebot/media.types @@ -0,0 +1,112 @@ + + + + + + torrent + + + + list + txt + + + + + + + sfv + + + + md5 + + + + sha1 + + + + + + mp3 + + + + mp4 + m4a + + + + flac + + + + wma + + + + ogg + + + + + + avi + + + + mkv + + + + ogm + + + + mp4 + + + + mov + + + + mpg + mpeg + + + + wmv + + + + + + srt + + + + sub + + + + ssa + ass + + + + smi + + +