* support renaming folders via scripting rename(...) call
* improved nfo/imdb lookup for disk folders
This commit is contained in:
parent
165c66a319
commit
441063f257
|
@ -92,11 +92,6 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
Locale locale = getLanguage(lang).toLocale();
|
Locale locale = getLanguage(lang).toLocale();
|
||||||
ConflictAction conflictAction = ConflictAction.forName(conflict);
|
ConflictAction conflictAction = ConflictAction.forName(conflict);
|
||||||
|
|
||||||
List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES);
|
|
||||||
if (mediaFiles.isEmpty()) {
|
|
||||||
throw new Exception("No media files: " + files);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getEpisodeListProvider(db) != null) {
|
if (getEpisodeListProvider(db) != null) {
|
||||||
// tv series mode
|
// tv series mode
|
||||||
return renameSeries(files, action, conflictAction, outputDir, format, getEpisodeListProvider(db), query, SortOrder.forName(sortOrder), filter, locale, strict);
|
return renameSeries(files, action, conflictAction, outputDir, format, getEpisodeListProvider(db), query, SortOrder.forName(sortOrder), filter, locale, strict);
|
||||||
|
@ -108,9 +103,10 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto-determine mode
|
// auto-determine mode
|
||||||
|
List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES);
|
||||||
|
double max = mediaFiles.size();
|
||||||
int sxe = 0; // SxE
|
int sxe = 0; // SxE
|
||||||
int cws = 0; // common word sequence
|
int cws = 0; // common word sequence
|
||||||
double max = mediaFiles.size();
|
|
||||||
|
|
||||||
SeriesNameMatcher nameMatcher = new SeriesNameMatcher(locale);
|
SeriesNameMatcher nameMatcher = new SeriesNameMatcher(locale);
|
||||||
Collection<String> cwsList = emptySet();
|
Collection<String> cwsList = emptySet();
|
||||||
|
@ -144,7 +140,11 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
public List<File> renameSeries(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, EpisodeListProvider db, String query, SortOrder sortOrder, ExpressionFilter filter, Locale locale, boolean strict) throws Exception {
|
public List<File> renameSeries(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, EpisodeListProvider db, String query, SortOrder sortOrder, ExpressionFilter filter, Locale locale, boolean strict) throws Exception {
|
||||||
CLILogger.config(format("Rename episodes using [%s]", db.getName()));
|
CLILogger.config(format("Rename episodes using [%s]", db.getName()));
|
||||||
|
|
||||||
List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES);
|
List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES);
|
||||||
|
if (mediaFiles.isEmpty()) {
|
||||||
|
throw new Exception("No media files: " + files);
|
||||||
|
}
|
||||||
|
|
||||||
// similarity metrics for matching
|
// similarity metrics for matching
|
||||||
List<Match<File, Object>> matches = new ArrayList<Match<File, Object>>();
|
List<Match<File, Object>> matches = new ArrayList<Match<File, Object>>();
|
||||||
|
@ -296,7 +296,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
// handle movie files
|
// handle movie files
|
||||||
Set<File> movieFiles = new TreeSet<File>(filter(fileset, VIDEO_FILES));
|
Set<File> movieFiles = new TreeSet<File>(filter(fileset, VIDEO_FILES));
|
||||||
Set<File> nfoFiles = new TreeSet<File>(filter(fileset, MediaTypes.getDefaultFilter("application/nfo")));
|
Set<File> nfoFiles = new TreeSet<File>(filter(fileset, NFO_FILES));
|
||||||
|
|
||||||
List<File> orphanedFiles = new ArrayList<File>(filter(fileset, FILES));
|
List<File> orphanedFiles = new ArrayList<File>(filter(fileset, FILES));
|
||||||
orphanedFiles.removeAll(movieFiles);
|
orphanedFiles.removeAll(movieFiles);
|
||||||
|
@ -336,7 +336,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
// collect useful nfo files even if they are not part of the selected fileset
|
// collect useful nfo files even if they are not part of the selected fileset
|
||||||
Set<File> effectiveNfoFileSet = new TreeSet<File>(nfoFiles);
|
Set<File> effectiveNfoFileSet = new TreeSet<File>(nfoFiles);
|
||||||
for (File dir : mapByFolder(movieFiles).keySet()) {
|
for (File dir : mapByFolder(movieFiles).keySet()) {
|
||||||
addAll(effectiveNfoFileSet, dir.listFiles(MediaTypes.getDefaultFilter("application/nfo")));
|
addAll(effectiveNfoFileSet, dir.listFiles(NFO_FILES));
|
||||||
}
|
}
|
||||||
for (File nfo : effectiveNfoFileSet) {
|
for (File nfo : effectiveNfoFileSet) {
|
||||||
try {
|
try {
|
||||||
|
@ -372,9 +372,14 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
List<File> movieMatchFiles = new ArrayList<File>();
|
List<File> movieMatchFiles = new ArrayList<File>();
|
||||||
movieMatchFiles.addAll(movieFiles);
|
movieMatchFiles.addAll(movieFiles);
|
||||||
movieMatchFiles.addAll(nfoFiles);
|
movieMatchFiles.addAll(nfoFiles);
|
||||||
movieMatchFiles.addAll(filter(files, DISK_FOLDERS));
|
movieMatchFiles.addAll(filter(files, FOLDERS));
|
||||||
movieMatchFiles.addAll(filter(orphanedFiles, SUBTITLE_FILES)); // run movie detection only on orphaned subtitle files
|
movieMatchFiles.addAll(filter(orphanedFiles, SUBTITLE_FILES)); // run movie detection only on orphaned subtitle files
|
||||||
|
|
||||||
|
// sanity check that we have something to do
|
||||||
|
if (fileset.isEmpty() || movieMatchFiles.isEmpty()) {
|
||||||
|
throw new Exception("No media files: " + files);
|
||||||
|
}
|
||||||
|
|
||||||
// map movies to (possibly multiple) files (in natural order)
|
// map movies to (possibly multiple) files (in natural order)
|
||||||
Map<Movie, SortedSet<File>> filesByMovie = new HashMap<Movie, SortedSet<File>>();
|
Map<Movie, SortedSet<File>> filesByMovie = new HashMap<Movie, SortedSet<File>>();
|
||||||
|
|
||||||
|
@ -454,7 +459,8 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
|
|
||||||
private File getDestinationFile(File original, String newName, File outputDir) {
|
private File getDestinationFile(File original, String newName, File outputDir) {
|
||||||
File newFile = new File(newName + "." + getExtension(original));
|
String extension = getExtension(original);
|
||||||
|
File newFile = new File(extension != null ? newName + '.' + extension : newName);
|
||||||
|
|
||||||
// resolve against output dir
|
// resolve against output dir
|
||||||
if (outputDir != null && !newFile.isAbsolute()) {
|
if (outputDir != null && !newFile.isAbsolute()) {
|
||||||
|
|
|
@ -515,7 +515,7 @@ public class MediaBindingBean {
|
||||||
// make sure media file is defined
|
// make sure media file is defined
|
||||||
checkMediaFile();
|
checkMediaFile();
|
||||||
|
|
||||||
if (SUBTITLE_FILES.accept(mediaFile) || getDefaultFilter("application/nfo").accept(mediaFile)) {
|
if (SUBTITLE_FILES.accept(mediaFile) || NFO_FILES.accept(mediaFile)) {
|
||||||
// file is a subtitle
|
// file is a subtitle
|
||||||
String baseName = stripReleaseInfo(FileUtilities.getName(mediaFile)).toLowerCase();
|
String baseName = stripReleaseInfo(FileUtilities.getName(mediaFile)).toLowerCase();
|
||||||
|
|
||||||
|
|
|
@ -568,15 +568,19 @@ public class MediaDetection {
|
||||||
Set<Integer> collection = new LinkedHashSet<Integer>();
|
Set<Integer> collection = new LinkedHashSet<Integer>();
|
||||||
List<File> nfoFiles = new ArrayList<File>();
|
List<File> nfoFiles = new ArrayList<File>();
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
nfoFiles.addAll(listFiles(singleton(file), 10, false));
|
nfoFiles.addAll(filter(listFiles(singleton(file), 10, false), NFO_FILES));
|
||||||
} else {
|
} else {
|
||||||
addAll(nfoFiles, file.getParentFile().listFiles(NFO_FILES));
|
addAll(nfoFiles, file.getParentFile().listFiles(NFO_FILES));
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse ids from nfo files
|
// parse ids from nfo files
|
||||||
for (File nfo : nfoFiles) {
|
for (File nfo : nfoFiles) {
|
||||||
String text = new String(readFile(nfo), "UTF-8");
|
try {
|
||||||
collection.addAll(grepImdbId(text));
|
String text = new String(readFile(nfo), "UTF-8");
|
||||||
|
collection.addAll(grepImdbId(text));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to read nfo: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collection;
|
return collection;
|
||||||
|
|
|
@ -144,7 +144,7 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
||||||
List<File> movieMatchFiles = new ArrayList<File>();
|
List<File> movieMatchFiles = new ArrayList<File>();
|
||||||
movieMatchFiles.addAll(movieFiles);
|
movieMatchFiles.addAll(movieFiles);
|
||||||
movieMatchFiles.addAll(nfoFiles);
|
movieMatchFiles.addAll(nfoFiles);
|
||||||
movieMatchFiles.addAll(filter(files, DISK_FOLDERS));
|
movieMatchFiles.addAll(filter(files, FOLDERS));
|
||||||
movieMatchFiles.addAll(filter(orphanedFiles, SUBTITLE_FILES)); // run movie detection only on orphaned subtitle files
|
movieMatchFiles.addAll(filter(orphanedFiles, SUBTITLE_FILES)); // run movie detection only on orphaned subtitle files
|
||||||
|
|
||||||
// match remaining movies file by file in parallel
|
// match remaining movies file by file in parallel
|
||||||
|
|
|
@ -105,7 +105,12 @@ public final class FileUtilities {
|
||||||
InputStream in = new FileInputStream(source);
|
InputStream in = new FileInputStream(source);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] data = new byte[(int) source.length()];
|
long size = source.length();
|
||||||
|
if (size < 0 || size > Integer.MAX_VALUE) {
|
||||||
|
throw new IllegalArgumentException("Unable to read file: " + source);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] data = new byte[(int) size];
|
||||||
|
|
||||||
int position = 0;
|
int position = 0;
|
||||||
int read = 0;
|
int read = 0;
|
||||||
|
@ -177,7 +182,6 @@ public final class FileUtilities {
|
||||||
return Charset.forName("UTF-8").decode(data).toString();
|
return Charset.forName("UTF-8").decode(data).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pattern used for matching file extensions.
|
* Pattern used for matching file extensions.
|
||||||
*
|
*
|
||||||
|
@ -421,7 +425,6 @@ public final class FileUtilities {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalid file name characters: \, /, :, *, ?, ", <, >, |, \r and \n
|
* Invalid file name characters: \, /, :, *, ?, ", <, >, |, \r and \n
|
||||||
*/
|
*/
|
||||||
|
@ -508,7 +511,6 @@ public final class FileUtilities {
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final long KILO = 1024;
|
public static final long KILO = 1024;
|
||||||
public static final long MEGA = KILO * 1024;
|
public static final long MEGA = KILO * 1024;
|
||||||
public static final long GIGA = MEGA * 1024;
|
public static final long GIGA = MEGA * 1024;
|
||||||
|
@ -523,7 +525,6 @@ public final class FileUtilities {
|
||||||
return String.format("%,d Byte", size);
|
return String.format("%,d Byte", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final FileFilter FOLDERS = new FileFilter() {
|
public static final FileFilter FOLDERS = new FileFilter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -532,7 +533,6 @@ public final class FileUtilities {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public static final FileFilter FILES = new FileFilter() {
|
public static final FileFilter FILES = new FileFilter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -541,7 +541,6 @@ public final class FileUtilities {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public static final FileFilter TEMPORARY = new FileFilter() {
|
public static final FileFilter TEMPORARY = new FileFilter() {
|
||||||
|
|
||||||
private final String tmpdir = System.getProperty("java.io.tmpdir");
|
private final String tmpdir = System.getProperty("java.io.tmpdir");
|
||||||
|
|
Loading…
Reference in New Issue