mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-04 08:25:03 -05:00
* added CLI for specifically fetching missing subtitles
This commit is contained in:
parent
5d5f52da69
commit
98349be576
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
@ -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()));
|
||||
|
Loading…
Reference in New Issue
Block a user