diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index 1946421b..4b15e91e 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -199,6 +199,19 @@ public class CmdlineOperations implements CmdlineInterface { throw new Exception("Unable to match files to episode data"); } + // first write all the metadata if xattr is enabled + if (useExtendedFileAttributes()) { + try { + for (Match match : matches) { + if (match.getCandidate() instanceof Episode) { + MediaDetection.storeMetaInfo(match.getValue(), match.getCandidate()); + } + } + } catch (Throwable e) { + CLILogger.warning("Failed to write xattr: " + e.getMessage()); + } + } + // map old files to new paths by applying formatting and validating filenames Map renameMap = new LinkedHashMap(); @@ -207,15 +220,6 @@ public class CmdlineOperations implements CmdlineInterface { Object episode = match.getCandidate(); String newName = (format != null) ? format.format(new MediaBindingBean(episode, file)) : validateFileName(EpisodeFormat.SeasonEpisode.format(episode)); - // first write all the metadata if xattr is enabled - if (useExtendedFileAttributes()) { - try { - MediaDetection.storeMetaInfo(file, episode); - } catch (Throwable e) { - CLILogger.warning("Failed to write xattr: " + e.getMessage()); - } - } - renameMap.put(file, getDestinationFile(file, newName, outputDir)); } @@ -468,6 +472,19 @@ public class CmdlineOperations implements CmdlineInterface { } } + // first write all the metadata if xattr is enabled + if (useExtendedFileAttributes()) { + try { + for (Match match : matches) { + if (match.getCandidate() instanceof Movie) { + MediaDetection.storeMetaInfo(match.getValue(), match.getCandidate()); + } + } + } catch (Throwable e) { + CLILogger.warning("Failed to write xattr: " + e.getMessage()); + } + } + // map old files to new paths by applying formatting and validating filenames Map renameMap = new LinkedHashMap(); @@ -476,15 +493,6 @@ public class CmdlineOperations implements CmdlineInterface { Object movie = match.getCandidate(); String newName = (format != null) ? format.format(new MediaBindingBean(movie, file)) : validateFileName(MovieFormat.NameYear.format(movie)); - // first write all the metadata if xattr is enabled - if (useExtendedFileAttributes()) { - try { - MediaDetection.storeMetaInfo(file, movie); - } catch (Throwable e) { - CLILogger.warning("Failed to write xattr: " + e.getMessage()); - } - } - renameMap.put(file, getDestinationFile(file, newName, outputDir)); } diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index b1df2c77..4be7b2f6 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -780,26 +780,33 @@ public class MediaDetection { public static void storeMetaInfo(File file, Object model) { - // original filename - MetaAttributes metadata = new MetaAttributes(file); - metadata.setOriginalName(file.getName()); + MetaAttributes xattr = new MetaAttributes(file); - // store model as metadata - if (model instanceof Episode || model instanceof Movie) { - metadata.setMetaData(model); + // store original name and model as xattr + try { + if (model instanceof Episode || model instanceof Movie) { + xattr.setMetaData(model); + } + xattr.setOriginalName(file.getName()); + } catch (Exception e) { + Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set xattr: " + e.getMessage()); } // set creation date to episode / movie release date - if (model instanceof Episode) { - Episode episode = (Episode) model; - if (episode.airdate() != null) { - metadata.setCreationDate(episode.airdate().getTimeStamp()); - } - } else if (model instanceof Movie) { - Movie movie = (Movie) model; - if (movie.getYear() > 0) { - metadata.setCreationDate(new Date(movie.getYear(), 1, 1).getTimeStamp()); + try { + if (model instanceof Episode) { + Episode episode = (Episode) model; + if (episode.airdate() != null) { + xattr.setCreationDate(episode.airdate().getTimeStamp()); + } + } else if (model instanceof Movie) { + Movie movie = (Movie) model; + if (movie.getYear() > 0) { + xattr.setCreationDate(new Date(movie.getYear(), 1, 1).getTimeStamp()); + } } + } catch (Exception e) { + Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set creation date: " + e.getMessage()); } } diff --git a/source/net/sourceforge/filebot/media/MetaAttributes.java b/source/net/sourceforge/filebot/media/MetaAttributes.java index 3aaca1c3..d1f773de 100644 --- a/source/net/sourceforge/filebot/media/MetaAttributes.java +++ b/source/net/sourceforge/filebot/media/MetaAttributes.java @@ -29,12 +29,8 @@ public class MetaAttributes { } - public void setCreationDate(long millis) { - try { - fileAttributeView.setTimes(null, null, FileTime.fromMillis(millis)); - } catch (IOException e) { - // creationTime not supported => ignore - } + public void setCreationDate(long millis) throws IOException { + fileAttributeView.setTimes(null, null, FileTime.fromMillis(millis)); } diff --git a/source/net/sourceforge/filebot/ui/rename/RenameAction.java b/source/net/sourceforge/filebot/ui/rename/RenameAction.java index 737f1fbf..c83d9e5f 100644 --- a/source/net/sourceforge/filebot/ui/rename/RenameAction.java +++ b/source/net/sourceforge/filebot/ui/rename/RenameAction.java @@ -84,12 +84,12 @@ class RenameAction extends AbstractAction { // first write all the metadata if xattr is enabled if (useExtendedFileAttributes()) { - for (Match match : model.matches()) { - try { + try { + for (Match match : model.matches()) { MediaDetection.storeMetaInfo(match.getCandidate(), match.getValue()); - } catch (Throwable e) { - Logger.getLogger(RenameAction.class.getName()).warning("Failed to write xattr: " + e.getMessage()); } + } catch (Throwable e) { + Logger.getLogger(RenameAction.class.getName()).warning("Failed to write xattr: " + e.getMessage()); } } diff --git a/website/data/query-blacklist.txt b/website/data/query-blacklist.txt index 8c7a3bf5..529a2b19 100644 --- a/website/data/query-blacklist.txt +++ b/website/data/query-blacklist.txt @@ -161,7 +161,6 @@ unrated unrated.edition UsaBit.com video[s]? -VOSTFR www[.][\w-.]+[.](com|net|tk|ro|cd) xRipp Zune \ No newline at end of file