1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00

* expose file media.types entry as {mediaType} binding

This commit is contained in:
Reinhard Pointner 2013-12-22 08:33:19 +00:00
parent 1525623ccd
commit 30d3134f81
3 changed files with 36 additions and 26 deletions

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot;
import static java.util.Collections.*;
import static net.sourceforge.tuned.XPathUtilities.*;
@ -18,12 +16,10 @@ import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
public class MediaTypes {
private static final MediaTypes defaultInstance = parseDefault();
private static MediaTypes parseDefault() {
try {
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(MediaTypes.class.getResourceAsStream("media.types"));
@ -47,12 +43,10 @@ public class MediaTypes {
private Map<String, List<String>> types;
private Map<String, ExtensionFileFilter> filters = synchronizedMap(new HashMap<String, ExtensionFileFilter>());
public MediaTypes(Map<String, List<String>> types) {
this.types = types;
}
public List<String> getExtensionList(String name) {
List<String> list = new ArrayList<String>();
@ -65,7 +59,6 @@ public class MediaTypes {
return list;
}
public ExtensionFileFilter getFilter(String name) {
ExtensionFileFilter filter = filters.get(name);
@ -77,11 +70,22 @@ public class MediaTypes {
return filter;
}
public static MediaTypes getDefault() {
return defaultInstance;
}
public Map<String, List<String>> getTypes() {
return types;
}
public String getMediaType(String extension) {
for (Entry<String, List<String>> it : getTypes().entrySet()) {
if (it.getValue().contains(extension)) {
return it.getKey();
}
}
return null;
}
public static ExtensionFileFilter getDefaultFilter(String name) {
return defaultInstance.getFilter(name);

View File

@ -27,6 +27,7 @@ import java.util.SortedSet;
import java.util.TreeSet;
import net.sourceforge.filebot.Cache;
import net.sourceforge.filebot.MediaTypes;
import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.hash.HashType;
import net.sourceforge.filebot.media.MetaAttributes;
@ -626,6 +627,11 @@ public class MediaBindingBean {
return null;
}
@Define("mediaType")
public List<String> getMediaType() throws Exception {
return asList(MediaTypes.getDefault().getMediaType(getExtension()).split("/")); // format engine does not allow / in binding value
}
@Define("file")
public File getMediaFile() {
return mediaFile;

View File

@ -225,7 +225,7 @@ public class FormatDialog extends JDialog {
// initialize window properties
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setSize(620, 445);
setSize(650, 450);
// initialize data
setState(initMode, lockOnBinding != null ? lockOnBinding : restoreSample(initMode), lockOnBinding != null);