mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 16:28:51 -05:00
Minor optimizations
This commit is contained in:
parent
fb8d6bd64c
commit
6c98f249d1
@ -1,6 +1,7 @@
|
||||
package net.filebot.media;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -9,31 +10,32 @@ import java.nio.file.attribute.BasicFileAttributeView;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.cedarsoftware.util.io.JsonReader;
|
||||
import com.cedarsoftware.util.io.JsonWriter;
|
||||
|
||||
import net.filebot.MetaAttributeView;
|
||||
import net.filebot.vfs.SimpleFileInfo;
|
||||
import net.filebot.web.AudioTrack;
|
||||
import net.filebot.web.Episode;
|
||||
import net.filebot.web.Movie;
|
||||
import net.filebot.web.MoviePart;
|
||||
import net.filebot.web.MultiEpisode;
|
||||
|
||||
public class MetaAttributes {
|
||||
|
||||
public static final String FILENAME_KEY = "net.filebot.filename";
|
||||
public static final String METADATA_KEY = "net.filebot.metadata";
|
||||
|
||||
public static final Map<String, String> JSON_TYPE_MAP = unmodifiableMap(Stream.of(Episode.class, MultiEpisode.class, Movie.class, MoviePart.class, AudioTrack.class, SimpleFileInfo.class).collect(toMap(Class::getName, Class::getSimpleName)));
|
||||
|
||||
private final BasicFileAttributeView fileAttributeView;
|
||||
private final MetaAttributeView metaAttributeView;
|
||||
|
||||
private final Map<String, String> jsonTypeMap;
|
||||
|
||||
// compatibility constructor for sysinfo.groovy script
|
||||
public MetaAttributes(File file) throws IOException {
|
||||
this(file, emptyMap());
|
||||
}
|
||||
|
||||
public MetaAttributes(File file, Map<String, String> jsonTypeMap) throws IOException {
|
||||
this.metaAttributeView = new MetaAttributeView(file);
|
||||
this.fileAttributeView = Files.getFileAttributeView(file.toPath(), BasicFileAttributeView.class);
|
||||
this.jsonTypeMap = jsonTypeMap;
|
||||
}
|
||||
|
||||
public void setCreationDate(long millis) throws IOException {
|
||||
@ -58,7 +60,7 @@ public class MetaAttributes {
|
||||
|
||||
public void setObject(Object object) {
|
||||
try {
|
||||
metaAttributeView.put(METADATA_KEY, JsonWriter.objectToJson(object, singletonMap(JsonWriter.TYPE_NAME_MAP, jsonTypeMap)));
|
||||
metaAttributeView.put(METADATA_KEY, JsonWriter.objectToJson(object, singletonMap(JsonWriter.TYPE_NAME_MAP, JSON_TYPE_MAP)));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -69,7 +71,7 @@ public class MetaAttributes {
|
||||
String jsonObject = metaAttributeView.get(METADATA_KEY);
|
||||
if (jsonObject != null && jsonObject.length() > 0) {
|
||||
Map<String, Object> options = new HashMap<String, Object>(2);
|
||||
options.put(JsonReader.TYPE_NAME_MAP, jsonTypeMap);
|
||||
options.put(JsonReader.TYPE_NAME_MAP, JSON_TYPE_MAP);
|
||||
|
||||
// options must be a modifiable map
|
||||
return JsonReader.jsonToJava(jsonObject, options);
|
||||
|
@ -1,27 +1,19 @@
|
||||
package net.filebot.media;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.Settings.*;
|
||||
import static net.filebot.util.ExceptionUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.filebot.Cache;
|
||||
import net.filebot.CacheType;
|
||||
import net.filebot.Resource;
|
||||
import net.filebot.WebServices;
|
||||
import net.filebot.vfs.SimpleFileInfo;
|
||||
import net.filebot.web.AudioTrack;
|
||||
import net.filebot.web.Episode;
|
||||
import net.filebot.web.Movie;
|
||||
import net.filebot.web.MoviePart;
|
||||
import net.filebot.web.MultiEpisode;
|
||||
import net.filebot.web.SimpleDate;
|
||||
|
||||
public class XattrMetaInfo {
|
||||
@ -34,8 +26,6 @@ public class XattrMetaInfo {
|
||||
private final Cache xattrMetaInfoCache = Cache.getCache(MetaAttributes.METADATA_KEY, CacheType.Ephemeral);
|
||||
private final Cache xattrOriginalNameCache = Cache.getCache(MetaAttributes.FILENAME_KEY, CacheType.Ephemeral);
|
||||
|
||||
private final Map<String, String> jsonTypeMap = unmodifiableMap(Stream.of(Episode.class, MultiEpisode.class, Movie.class, MoviePart.class, AudioTrack.class, SimpleFileInfo.class).collect(toMap(Class::getName, Class::getSimpleName)));
|
||||
|
||||
public XattrMetaInfo(boolean useExtendedFileAttributes, boolean useCreationDate) {
|
||||
this.useExtendedFileAttributes = useExtendedFileAttributes;
|
||||
this.useCreationDate = useCreationDate;
|
||||
@ -86,11 +76,7 @@ public class XattrMetaInfo {
|
||||
}
|
||||
|
||||
private MetaAttributes xattr(File file) throws Exception {
|
||||
return new MetaAttributes(file, getJsonTypeMap());
|
||||
}
|
||||
|
||||
public Map<String, String> getJsonTypeMap() {
|
||||
return jsonTypeMap;
|
||||
return new MetaAttributes(file);
|
||||
}
|
||||
|
||||
public synchronized void setMetaInfo(File file, Object model, String original) {
|
||||
|
@ -228,7 +228,7 @@ class BindingDialog extends JDialog {
|
||||
infoTextField.putClientProperty("model", info);
|
||||
|
||||
infoTextField.setText(info == null ? "" : infoObjectFormat.format(info));
|
||||
infoTextField.setToolTipText(info == null ? "null" : "<html><pre>" + escapeHTML(asPrettyJsonString(info)) + "</pre></html>");
|
||||
infoTextField.setToolTipText(info == null ? "null" : "<html><pre>" + escapeHTML(json(info, true)) + "</pre></html>");
|
||||
}
|
||||
|
||||
public Object getInfoObject() {
|
||||
|
@ -7,7 +7,6 @@ import static javax.swing.SwingUtilities.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.Settings.*;
|
||||
import static net.filebot.media.MediaDetection.*;
|
||||
import static net.filebot.media.XattrMetaInfo.*;
|
||||
import static net.filebot.util.ExceptionUtilities.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.ui.LoadingOverlayPane.*;
|
||||
@ -68,6 +67,7 @@ import net.filebot.UserFiles;
|
||||
import net.filebot.WebServices;
|
||||
import net.filebot.format.MediaBindingBean;
|
||||
import net.filebot.mac.MacAppUtilities;
|
||||
import net.filebot.media.MetaAttributes;
|
||||
import net.filebot.similarity.Match;
|
||||
import net.filebot.ui.rename.FormatDialog.Mode;
|
||||
import net.filebot.ui.rename.RenameModel.FormattedFuture;
|
||||
@ -362,8 +362,11 @@ public class RenamePanel extends JComponent {
|
||||
installAction(this, WHEN_IN_FOCUSED_WINDOW, getKeyStroke(VK_F7, 0), newAction("Copy Debug Information", evt -> {
|
||||
try {
|
||||
withWaitCursor(evt.getSource(), () -> {
|
||||
copyToClipboard(getDebugInfo());
|
||||
log.info("Match model has been copied to clipboard");
|
||||
String text = getDebugInfo();
|
||||
if (text.length() > 0) {
|
||||
copyToClipboard(text);
|
||||
log.info("Match model has been copied to clipboard");
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
debug.log(Level.WARNING, e, e::getMessage);
|
||||
@ -617,12 +620,12 @@ public class RenamePanel extends JComponent {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Map<String, Object> options = new HashMap<String, Object>(2);
|
||||
options.put(JsonWriter.TYPE_NAME_MAP, xattr.getJsonTypeMap());
|
||||
options.put(JsonWriter.TYPE_NAME_MAP, MetaAttributes.JSON_TYPE_MAP);
|
||||
options.put(JsonWriter.SKIP_NULL_FIELDS, true);
|
||||
|
||||
for (Match<Object, File> m : renameModel.matches()) {
|
||||
Object v = m.getValue();
|
||||
String f = getStructurePathTail(m.getCandidate()).getPath();
|
||||
Object v = m.getValue();
|
||||
|
||||
// convert FastFile items
|
||||
if (v instanceof File) {
|
||||
|
@ -24,12 +24,8 @@ public class JsonUtilities {
|
||||
return JsonReader.jsonToJava(json.toString(), singletonMap(JsonReader.USE_MAPS, true));
|
||||
}
|
||||
|
||||
public static String asJsonString(Object object) {
|
||||
return JsonWriter.objectToJson(object);
|
||||
}
|
||||
|
||||
public static String asPrettyJsonString(Object object) {
|
||||
return JsonWriter.objectToJson(object, singletonMap(JsonWriter.PRETTY_PRINT, true));
|
||||
public static String json(Object object, boolean pretty) {
|
||||
return JsonWriter.objectToJson(object, singletonMap(JsonWriter.PRETTY_PRINT, pretty));
|
||||
}
|
||||
|
||||
public static Map<?, ?> asMap(Object node) {
|
||||
|
@ -53,9 +53,9 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Object postJson(String path, Object json) throws Exception {
|
||||
protected Object postJson(String path, Object object) throws Exception {
|
||||
// curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' 'https://api.thetvdb.com/login' --data '{"apikey":"XXXXX"}'
|
||||
ByteBuffer response = post(getEndpoint(path), asJsonString(json).getBytes(UTF_8), "application/json", null);
|
||||
ByteBuffer response = post(getEndpoint(path), json(object, false).getBytes(UTF_8), "application/json", null);
|
||||
return readJson(UTF_8.decode(response));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user