* added CLI for specifically fetching missing subtitles

This commit is contained in:
Reinhard Pointner 2011-11-28 12:47:11 +00:00
parent 5d5f52da69
commit 98349be576
4 changed files with 45 additions and 4 deletions

View File

@ -37,6 +37,9 @@ public class ArgumentBean {
@Option(name = "-get-subtitles", usage = "Fetch subtitles", metaVar = "fileset")
public boolean getSubtitles;
@Option(name = "-get-missing-subtitles", usage = "Fetch missing subtitles", metaVar = "fileset")
public boolean getMissingSubtitles;
@Option(name = "--q", usage = "Search query", metaVar = "title")
public String query;
@ -84,7 +87,7 @@ public class ArgumentBean {
public boolean runCLI() {
return rename || getSubtitles || check || list || mediaInfo || script != null;
return rename || getSubtitles || getMissingSubtitles || check || list || mediaInfo || script != null;
}

View File

@ -9,7 +9,6 @@ import java.io.File;
import java.io.InputStreamReader;
import java.security.AccessController;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.script.Bindings;
@ -63,8 +62,9 @@ public class ArgumentProcessor {
Set<File> files = new LinkedHashSet<File>(args.getFiles(true));
if (args.getSubtitles) {
List<File> subtitles = cli.getSubtitles(files, args.query, args.lang, args.output, args.encoding, !args.nonStrict);
files.addAll(subtitles);
files.addAll(cli.getSubtitles(files, args.query, args.lang, args.output, args.encoding, !args.nonStrict));
} else if (args.getMissingSubtitles) {
files.addAll(cli.getMissingSubtitles(files, args.query, args.lang, args.output, args.encoding, !args.nonStrict));
}
if (args.rename) {

View File

@ -15,6 +15,9 @@ public interface CmdlineInterface {
List<File> getSubtitles(Collection<File> files, String query, String lang, String output, String encoding, boolean strict) throws Exception;
List<File> getMissingSubtitles(Collection<File> files, String query, String lang, String output, String encoding, boolean strict) throws Exception;
boolean check(Collection<File> files) throws Exception;

View File

@ -13,6 +13,7 @@ import static net.sourceforge.filebot.subtitle.SubtitleUtilities.*;
import static net.sourceforge.tuned.FileUtilities.*;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
@ -451,6 +452,40 @@ public class CmdlineOperations implements CmdlineInterface {
}
public List<File> getMissingSubtitles(Collection<File> files, String query, String languageName, String output, String csn, boolean strict) throws Exception {
List<File> videoFiles = filter(filter(files, VIDEO_FILES), new FileFilter() {
// save time on repeating filesystem calls
private final Map<File, File[]> cache = new HashMap<File, File[]>();
@Override
public boolean accept(File video) {
File[] subtitlesByFolder = cache.get(video.getParentFile());
if (subtitlesByFolder == null) {
subtitlesByFolder = video.getParentFile().listFiles(SUBTITLE_FILES);
cache.put(video.getParentFile(), subtitlesByFolder);
}
for (File subtitle : subtitlesByFolder) {
if (isDerived(subtitle, video))
return false;
}
return true;
}
});
if (videoFiles.isEmpty()) {
CLILogger.info("No missing subtitles");
return emptyList();
}
CLILogger.finest(format("Missing subtitles for %d video files", videoFiles.size()));
return getSubtitles(videoFiles, query, languageName, output, csn, strict);
}
private File downloadSubtitle(SubtitleDescriptor descriptor, File movieFile, SubtitleFormat outputFormat, Charset outputEncoding) throws Exception {
// fetch subtitle archive
CLILogger.info(format("Fetching [%s]", descriptor.getPath()));