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

View File

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

View File

@ -290,19 +290,10 @@ public class MediaDetection {
List<String> names = new ArrayList<String>(); List<String> names = new ArrayList<String>();
// try xattr metadata if enabled // try xattr metadata if enabled
if (useExtendedFileAttributes()) {
try {
for (File it : files) { for (File it : files) {
MetaAttributes xattr = new MetaAttributes(it); Object metaObject = readMetaInfo(it);
try { if (metaObject instanceof Episode) {
Episode episode = (Episode) xattr.getObject(); names.add(((Episode) metaObject).getSeriesName());
names.add(episode.getSeriesName());
} catch (Exception e) {
// can't read meta attributes => ignore
}
}
} catch (Throwable e) {
// ignore
} }
} }
@ -551,20 +542,9 @@ public class MediaDetection {
Set<Movie> options = new LinkedHashSet<Movie>(); Set<Movie> options = new LinkedHashSet<Movie>();
// try xattr metadata if enabled // try xattr metadata if enabled
if (useExtendedFileAttributes()) { Object metaObject = readMetaInfo(movieFile);
try { if (metaObject instanceof Movie) {
MetaAttributes xattr = new MetaAttributes(movieFile); options.add((Movie) metaObject);
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
}
} }
// lookup by file hash // 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()) { if (useExtendedFileAttributes()) {
try { try {
MetaAttributes xattr = new MetaAttributes(file); MetaAttributes xattr = new MetaAttributes(file);
Object meta = xattr.getObject(); Object metaObject = xattr.getObject();
if (meta instanceof Episode || meta instanceof Movie) { if (metaObject instanceof Episode || metaObject instanceof Movie) {
return meta; return metaObject;
} }
} catch (Throwable e) { } catch (Throwable e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Unable to read xattr: " + e.getMessage()); 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) { public void setObject(Object object) {
try { try {
metaAttributeView.put(METADATA_KEY, JsonWriter.objectToJson(object)); metaAttributeView.put(METADATA_KEY, JsonWriter.objectToJson(object));
} catch (IOException e) { } catch (Exception e) {
throw new IllegalStateException(e); throw new RuntimeException(e); // unlikely to ever happen JSON serialization issues
} }
} }
public Object getObject() { public Object getObject() {
try { try {
return JsonReader.jsonToJava(metaAttributeView.get(METADATA_KEY)); return JsonReader.jsonToJava(metaAttributeView.get(METADATA_KEY));
} catch (IOException e) { } catch (Exception e) {
return null; return null; // ignore JSON serialization issues
} }
} }

View File

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

View File

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