* improved error handling if xattr/createDate are not supported

This commit is contained in:
Reinhard Pointner 2012-10-24 12:56:27 +00:00
parent cb4f1251bf
commit d0194aae25
5 changed files with 54 additions and 44 deletions

View File

@ -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<File, ?> 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<File, File> renameMap = new LinkedHashMap<File, File>();
@ -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<File, ?> 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<File, File> renameMap = new LinkedHashMap<File, File>();
@ -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));
}

View File

@ -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());
}
}

View File

@ -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));
}

View File

@ -84,12 +84,12 @@ class RenameAction extends AbstractAction {
// first write all the metadata if xattr is enabled
if (useExtendedFileAttributes()) {
for (Match<Object, File> match : model.matches()) {
try {
try {
for (Match<Object, File> 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());
}
}

View File

@ -161,7 +161,6 @@ unrated
unrated.edition
UsaBit.com
video[s]?
VOSTFR
www[.][\w-.]+[.](com|net|tk|ro|cd)
xRipp
Zune