* some finetuning + new sample script
This commit is contained in:
parent
f65f84c593
commit
54df846c91
|
@ -5,12 +5,11 @@ package net.sourceforge.filebot.cli;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
|
|
||||||
public interface CmdlineInterface {
|
public interface CmdlineInterface {
|
||||||
|
|
||||||
Set<File> rename(Collection<File> files, String query, String format, String db, String lang, boolean strict) throws Exception;
|
List<File> rename(Collection<File> files, String query, String format, String db, String lang, boolean strict) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
List<File> getSubtitles(Collection<File> files, String query, String lang, String output, String encoding) throws Exception;
|
List<File> getSubtitles(Collection<File> files, String query, String lang, String output, String encoding) throws Exception;
|
||||||
|
|
|
@ -67,7 +67,7 @@ import net.sourceforge.filebot.web.VideoHashSubtitleService;
|
||||||
public class CmdlineOperations implements CmdlineInterface {
|
public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<File> rename(Collection<File> files, String query, String expression, String db, String languageName, boolean strict) throws Exception {
|
public List<File> rename(Collection<File> files, String query, String expression, String db, String languageName, boolean strict) throws Exception {
|
||||||
ExpressionFormat format = (expression != null) ? new ExpressionFormat(expression) : null;
|
ExpressionFormat format = (expression != null) ? new ExpressionFormat(expression) : null;
|
||||||
Locale locale = getLanguage(languageName).toLocale();
|
Locale locale = getLanguage(languageName).toLocale();
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Set<File> renameSeries(Collection<File> files, String query, ExpressionFormat format, EpisodeListProvider db, Locale locale, boolean strict) throws Exception {
|
public List<File> renameSeries(Collection<File> files, String query, ExpressionFormat format, EpisodeListProvider db, 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);
|
||||||
Collection<String> seriesNames;
|
Collection<String> seriesNames;
|
||||||
|
@ -235,7 +235,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Set<File> renameMovie(Collection<File> mediaFiles, String query, ExpressionFormat format, MovieIdentificationService db, Locale locale, boolean strict) throws Exception {
|
public List<File> renameMovie(Collection<File> mediaFiles, String query, ExpressionFormat format, MovieIdentificationService db, Locale locale, boolean strict) throws Exception {
|
||||||
CLILogger.config(format("Rename movies using [%s]", db.getName()));
|
CLILogger.config(format("Rename movies using [%s]", db.getName()));
|
||||||
|
|
||||||
File[] movieFiles = filter(mediaFiles, VIDEO_FILES).toArray(new File[0]);
|
File[] movieFiles = filter(mediaFiles, VIDEO_FILES).toArray(new File[0]);
|
||||||
|
@ -423,7 +423,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Set<File> renameAll(Map<File, File> renameMap) throws Exception {
|
private List<File> renameAll(Map<File, File> renameMap) throws Exception {
|
||||||
// rename files
|
// rename files
|
||||||
final List<Entry<File, File>> renameLog = new ArrayList<Entry<File, File>>();
|
final List<Entry<File, File>> renameLog = new ArrayList<Entry<File, File>>();
|
||||||
|
|
||||||
|
@ -471,11 +471,11 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// new file names
|
// new file names
|
||||||
Set<File> newFiles = new LinkedHashSet<File>();
|
List<File> destinationList = new ArrayList<File>();
|
||||||
for (Entry<File, File> it : renameLog)
|
for (Entry<File, File> it : renameLog)
|
||||||
newFiles.add(it.getValue());
|
destinationList.add(it.getValue());
|
||||||
|
|
||||||
return newFiles;
|
return destinationList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ import java.security.PrivilegedActionException;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
import java.util.PropertyPermission;
|
import java.util.PropertyPermission;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.script.Bindings;
|
import javax.script.Bindings;
|
||||||
import javax.script.ScriptContext;
|
import javax.script.ScriptContext;
|
||||||
|
@ -28,7 +27,6 @@ import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory;
|
||||||
import net.sourceforge.filebot.MediaTypes;
|
import net.sourceforge.filebot.MediaTypes;
|
||||||
import net.sourceforge.filebot.WebServices;
|
import net.sourceforge.filebot.WebServices;
|
||||||
import net.sourceforge.filebot.format.PrivilegedInvocation;
|
import net.sourceforge.filebot.format.PrivilegedInvocation;
|
||||||
import net.sourceforge.filebot.mediainfo.MediaInfo;
|
|
||||||
import net.sourceforge.filebot.web.EpisodeListProvider;
|
import net.sourceforge.filebot.web.EpisodeListProvider;
|
||||||
import net.sourceforge.filebot.web.MovieIdentificationService;
|
import net.sourceforge.filebot.web.MovieIdentificationService;
|
||||||
|
|
||||||
|
@ -64,13 +62,6 @@ class ScriptShell {
|
||||||
bindings.put(service.getName().toLowerCase(), PrivilegedInvocation.newProxy(MovieIdentificationService.class, service, acc));
|
bindings.put(service.getName().toLowerCase(), PrivilegedInvocation.newProxy(MovieIdentificationService.class, service, acc));
|
||||||
}
|
}
|
||||||
|
|
||||||
// load media info native lib
|
|
||||||
try {
|
|
||||||
bindings.put("mi", new MediaInfo());
|
|
||||||
} catch (LinkageError e) {
|
|
||||||
Logger.getLogger(MediaInfo.class.getName()).warning("Failed to load MediaInfo");
|
|
||||||
}
|
|
||||||
|
|
||||||
return bindings;
|
return bindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,17 +11,20 @@ File.metaClass.hasFile = { c -> isDirectory() && listFiles().find{ c.call(it) }}
|
||||||
File.metaClass.plus = { path -> new File(delegate, path) }
|
File.metaClass.plus = { path -> new File(delegate, path) }
|
||||||
|
|
||||||
File.metaClass.getFiles = { def files = []; traverse(type:FILES) { files += it }; return files }
|
File.metaClass.getFiles = { def files = []; traverse(type:FILES) { files += it }; return files }
|
||||||
|
String.metaClass.getFiles = { new File(delegate).getFiles() }
|
||||||
List.metaClass.getFiles = { findResults{ it.getFiles() }.flatten().unique() }
|
List.metaClass.getFiles = { findResults{ it.getFiles() }.flatten().unique() }
|
||||||
|
|
||||||
|
|
||||||
File.metaClass.getFolders = { def folders = []; traverse(type:DIRECTORIES, visitRoot:true) { folders += it }; return folders }
|
File.metaClass.getFolders = { def folders = []; traverse(type:DIRECTORIES, visitRoot:true) { folders += it }; return folders }
|
||||||
|
String.metaClass.getFolders = { new File(delegate).getFolders() }
|
||||||
List.metaClass.getFolders = { findResults{ it.getFolders() }.flatten().unique() }
|
List.metaClass.getFolders = { findResults{ it.getFolders() }.flatten().unique() }
|
||||||
|
|
||||||
File.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) }
|
File.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) }
|
||||||
|
String.metaClass.eachMediaFolder = { c -> new File(delegate).eachMediaFolder(c) }
|
||||||
List.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) }
|
List.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) }
|
||||||
|
|
||||||
def require(cond) {
|
|
||||||
if (!cond()) throw new Exception('Require failed')
|
def require(cond) { if (!cond()) throw new Exception('Require failed') }
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def rename(args) { args = _defaults(args)
|
def rename(args) { args = _defaults(args)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
// filebot -script "http://filebot.sourceforge.net/data/shell/chkall.groovy" <folder>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check all sfv/md5/sha1 files and stop if a conflict is found
|
||||||
|
*/
|
||||||
|
args.getFiles().findAll { it.isVerification() }.each {
|
||||||
|
if (!check(file:it))
|
||||||
|
throw new Exception("*ERROR*")
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
// filebot -script "http://filebot.sourceforge.net/data/shell/src.groovy" <folder>
|
// filebot -script "http://filebot.sourceforge.net/data/shell/src.groovy" <folder>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fetch subtitles, rename and calculate checksums for all video files
|
||||||
|
*/
|
||||||
args.eachMediaFolder {
|
args.eachMediaFolder {
|
||||||
getSubtitles(folder:it)
|
getSubtitles(folder:it)
|
||||||
rename(folder:it)
|
rename(folder:it)
|
||||||
|
|
Loading…
Reference in New Issue