1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-02 08:25:02 -04:00

* read type/extension mapping from xml file

This commit is contained in:
Reinhard Pointner 2009-05-21 09:56:25 +00:00
parent f0414361ee
commit 67d53605af
3 changed files with 191 additions and 8 deletions

View File

@ -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;
}
};

View File

@ -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<String> extensions = new ArrayList<String>();
for (Type type : types) {
if (type.name.startsWith(path)) {
addAll(extensions, type.extensions);
}
}
return extensions.toArray(new String[0]);
}
}

View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<media-types>
<!--
Application
-->
<type name="application/torrent">
<extension>torrent</extension>
</type>
<type name="application/list">
<extension>list</extension>
<extension>txt</extension>
<extension></extension>
</type>
<!--
Verification
-->
<type name="verification/sfv">
<extension>sfv</extension>
</type>
<type name="verification/md5">
<extension>md5</extension>
</type>
<type name="verification/sha-1">
<extension>sha1</extension>
</type>
<!--
Audio
-->
<type name="audio/mp3">
<extension>mp3</extension>
</type>
<type name="audio/mp4">
<extension>mp4</extension>
<extension>m4a</extension>
</type>
<type name="audio/flac">
<extension>flac</extension>
</type>
<type name="audio/wma">
<extension>wma</extension>
</type>
<type name="audio/ogg">
<extension>ogg</extension>
</type>
<!--
Video
-->
<type name="video/avi">
<extension>avi</extension>
</type>
<type name="video/mkv">
<extension>mkv</extension>
</type>
<type name="video/ogm">
<extension>ogm</extension>
</type>
<type name="video/mp4">
<extension>mp4</extension>
</type>
<type name="video/mov">
<extension>mov</extension>
</type>
<type name="video/mpg">
<extension>mpg</extension>
<extension>mpeg</extension>
</type>
<type name="video/wmv">
<extension>wmv</extension>
</type>
<!--
Subtitles
-->
<type name="subtitle/srt">
<extension>srt</extension>
</type>
<type name="subtitle/sub">
<extension>sub</extension>
</type>
<type name="subtitle/ssa">
<extension>ssa</extension>
<extension>ass</extension>
</type>
<type name="subtitle/smi">
<extension>smi</extension>
</type>
</media-types>