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

* fix potential movie detection issue

This commit is contained in:
Reinhard Pointner 2014-06-24 10:59:00 +00:00
parent 9d2ce30d58
commit 18959a8dd1
6 changed files with 29 additions and 74 deletions

View File

@ -39,7 +39,6 @@ import net.filebot.StandardRenameAction;
import net.filebot.WebServices;
import net.filebot.format.AssociativeScriptObject;
import net.filebot.media.MediaDetection;
import net.filebot.media.MetaAttributes;
import net.filebot.similarity.SeasonEpisodeMatcher.SxE;
import net.filebot.util.FileUtilities;
import net.filebot.web.Movie;
@ -209,10 +208,9 @@ public abstract class ScriptShellBaseClass extends Script {
public Movie detectMovie(File file, boolean strict) {
// 1. xattr
try {
return (Movie) new MetaAttributes(file).getObject();
} catch (Exception e) {
// ignore and move on
Object metaObject = MediaDetection.readMetaInfo(file);
if (metaObject instanceof Movie) {
return (Movie) metaObject;
}
// 2. perfect filename match

View File

@ -26,7 +26,6 @@ import net.filebot.MediaTypes;
import net.filebot.MetaAttributeView;
import net.filebot.Settings;
import net.filebot.media.MediaDetection;
import net.filebot.media.MetaAttributes;
import net.filebot.similarity.NameSimilarityMetric;
import net.filebot.similarity.Normalization;
import net.filebot.similarity.SimilarityMetric;
@ -377,14 +376,7 @@ public class ScriptShellMethods {
}
public static Object getMetadata(File self) {
try {
if (Settings.useExtendedFileAttributes()) {
return new MetaAttributes(self);
}
} catch (Exception e) {
// ignore
}
return null;
return MediaDetection.readMetaInfo(self);
}
}

View File

@ -290,19 +290,10 @@ public class MediaDetection {
List<String> names = new ArrayList<String>();
// try xattr metadata if enabled
if (useExtendedFileAttributes()) {
try {
for (File it : files) {
MetaAttributes xattr = new MetaAttributes(it);
try {
Episode episode = (Episode) xattr.getObject();
names.add(episode.getSeriesName());
} catch (Exception e) {
// can't read meta attributes => ignore
}
}
} catch (Throwable e) {
// ignore
for (File it : files) {
Object metaObject = readMetaInfo(it);
if (metaObject instanceof Episode) {
names.add(((Episode) metaObject).getSeriesName());
}
}
@ -551,20 +542,9 @@ public class MediaDetection {
Set<Movie> options = new LinkedHashSet<Movie>();
// try xattr metadata if enabled
if (useExtendedFileAttributes()) {
try {
MetaAttributes xattr = new MetaAttributes(movieFile);
try {
Movie movie = (Movie) xattr.getObject();
if (movie != null) {
options.add(movie.clone()); // normalize as movie object
}
} catch (Exception e) {
// can't read meta attributes => ignore
}
} catch (Throwable e) {
// ignore
}
Object metaObject = readMetaInfo(movieFile);
if (metaObject instanceof Movie) {
options.add((Movie) metaObject);
}
// lookup by file hash
@ -1391,13 +1371,13 @@ public class MediaDetection {
}
};
public static Object loadMetaInfo(File file) {
public static Object readMetaInfo(File file) {
if (useExtendedFileAttributes()) {
try {
MetaAttributes xattr = new MetaAttributes(file);
Object meta = xattr.getObject();
if (meta instanceof Episode || meta instanceof Movie) {
return meta;
Object metaObject = xattr.getObject();
if (metaObject instanceof Episode || metaObject instanceof Movie) {
return metaObject;
}
} catch (Throwable e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Unable to read xattr: " + e.getMessage());

View File

@ -47,16 +47,16 @@ public class MetaAttributes {
public void setObject(Object object) {
try {
metaAttributeView.put(METADATA_KEY, JsonWriter.objectToJson(object));
} catch (IOException e) {
throw new IllegalStateException(e);
} catch (Exception e) {
throw new RuntimeException(e); // unlikely to ever happen JSON serialization issues
}
}
public Object getObject() {
try {
return JsonReader.jsonToJava(metaAttributeView.get(METADATA_KEY));
} catch (IOException e) {
return null;
} catch (Exception e) {
return null; // ignore JSON serialization issues
}
}

View File

@ -3,7 +3,6 @@ package net.filebot.similarity;
import static java.lang.Math.*;
import static java.util.Collections.*;
import static java.util.regex.Pattern.*;
import static net.filebot.Settings.*;
import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
@ -28,14 +27,15 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.filebot.WebServices;
import net.filebot.media.MediaDetection;
import net.filebot.media.ReleaseInfo;
import net.filebot.media.SmartSeasonEpisodeMatcher;
import net.filebot.similarity.SeasonEpisodeMatcher.SxE;
import net.filebot.vfs.FileInfo;
import net.filebot.web.SimpleDate;
import net.filebot.web.Episode;
import net.filebot.web.EpisodeFormat;
import net.filebot.web.Movie;
import net.filebot.web.SimpleDate;
import net.filebot.web.TheTVDBClient.SeriesInfo;
import net.filebot.web.TheTVDBSearchResult;
@ -643,11 +643,10 @@ public enum EpisodeMetrics implements SimilarityMetric {
}
// deserialize MetaAttributes if enabled and available
if (object instanceof File && useExtendedFileAttributes()) {
try {
return super.getProperties(new net.filebot.media.MetaAttributes((File) object).getObject());
} catch (Throwable e) {
// ignore
if (object instanceof File) {
Object metaObject = MediaDetection.readMetaInfo((File) object);
if (metaObject != null) {
return super.getProperties(metaObject);
}
}

View File

@ -1,7 +1,6 @@
package net.filebot.ui.rename;
import static net.filebot.MediaTypes.*;
import static net.filebot.Settings.*;
import static net.filebot.ui.NotificationLogging.*;
import static net.filebot.util.ui.TunedUtilities.*;
@ -27,7 +26,6 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptException;
import javax.swing.AbstractAction;
@ -52,17 +50,16 @@ import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import net.miginfocom.swing.MigLayout;
import net.filebot.ResourceManager;
import net.filebot.format.ExpressionFormat;
import net.filebot.format.MediaBindingBean;
import net.filebot.media.MediaDetection;
import net.filebot.media.MetaAttributes;
import net.filebot.mediainfo.MediaInfo;
import net.filebot.mediainfo.MediaInfo.StreamKind;
import net.filebot.mediainfo.MediaInfoException;
import net.filebot.util.DefaultThreadFactory;
import net.filebot.util.ui.LazyDocumentListener;
import net.miginfocom.swing.MigLayout;
class BindingDialog extends JDialog {
@ -378,20 +375,9 @@ class BindingDialog extends JDialog {
mediaFileTextField.setText(file.getAbsolutePath());
// set info object from xattr if possible
if (useExtendedFileAttributes()) {
try {
MetaAttributes xattr = new MetaAttributes(file);
try {
Object object = xattr.getObject();
if (infoObjectFormat.format(object) != null) {
setInfoObject(object);
}
} catch (Exception e) {
// ignore invalid data
}
} catch (Throwable e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to read xattr: " + e.getMessage());
}
Object object = MediaDetection.readMetaInfo(file);
if (object != null && infoObjectFormat.format(object) != null) {
setInfoObject(object);
}
}
}