* some finetuning + new sample script

This commit is contained in:
Reinhard Pointner 2011-11-05 00:29:59 +00:00
parent f65f84c593
commit 54df846c91
6 changed files with 26 additions and 21 deletions

View File

@ -5,12 +5,11 @@ package net.sourceforge.filebot.cli;
import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.Set;
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;

View File

@ -67,7 +67,7 @@ import net.sourceforge.filebot.web.VideoHashSubtitleService;
public class CmdlineOperations implements CmdlineInterface {
@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;
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()));
List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES);
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()));
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
final List<Entry<File, File>> renameLog = new ArrayList<Entry<File, File>>();
@ -471,11 +471,11 @@ public class CmdlineOperations implements CmdlineInterface {
}
// new file names
Set<File> newFiles = new LinkedHashSet<File>();
List<File> destinationList = new ArrayList<File>();
for (Entry<File, File> it : renameLog)
newFiles.add(it.getValue());
destinationList.add(it.getValue());
return newFiles;
return destinationList;
}

View File

@ -14,7 +14,6 @@ import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
import java.util.PropertyPermission;
import java.util.logging.Logger;
import javax.script.Bindings;
import javax.script.ScriptContext;
@ -28,7 +27,6 @@ import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory;
import net.sourceforge.filebot.MediaTypes;
import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.format.PrivilegedInvocation;
import net.sourceforge.filebot.mediainfo.MediaInfo;
import net.sourceforge.filebot.web.EpisodeListProvider;
import net.sourceforge.filebot.web.MovieIdentificationService;
@ -64,13 +62,6 @@ class ScriptShell {
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;
}

View File

@ -11,17 +11,20 @@ File.metaClass.hasFile = { c -> isDirectory() && listFiles().find{ c.call(it) }}
File.metaClass.plus = { path -> new File(delegate, path) }
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() }
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() }
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) }
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)

View File

@ -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*")
}

View File

@ -1,5 +1,8 @@
// filebot -script "http://filebot.sourceforge.net/data/shell/src.groovy" <folder>
/*
* Fetch subtitles, rename and calculate checksums for all video files
*/
args.eachMediaFolder {
getSubtitles(folder:it)
rename(folder:it)