mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 08:18:52 -05:00
Support for renaming episode files in linear order (without matching)
This commit is contained in:
parent
a338ab9a05
commit
2f7ee58707
@ -53,6 +53,11 @@ public class ArgumentProcessor {
|
||||
throw new CmdlineException("`filebot -get-subtitles -r` has been disabled due to abuse. Please see http://bit.ly/suball for details.");
|
||||
}
|
||||
|
||||
// rename files in linear order
|
||||
if (args.list && args.rename) {
|
||||
return cli.rename(args.getEpisodeListProvider(), args.getSearchQuery(), args.getExpressionFileFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale(), args.isStrict(), args.getFiles(true), args.getRenameAction(), args.getConflictAction(), args.getOutputPath()).isEmpty() ? 1 : 0;
|
||||
}
|
||||
|
||||
// print episode info
|
||||
if (args.list) {
|
||||
return print(cli.fetchEpisodeList(args.getEpisodeListProvider(), args.getSearchQuery(), args.getExpressionFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale(), args.isStrict()));
|
||||
|
@ -25,6 +25,8 @@ public interface CmdlineInterface {
|
||||
|
||||
List<File> rename(Collection<File> files, RenameAction action, ConflictAction conflict, File output, ExpressionFileFormat format, Datasource db, String query, SortOrder order, ExpressionFilter filter, Locale locale, boolean strict) throws Exception;
|
||||
|
||||
List<File> rename(EpisodeListProvider db, String query, ExpressionFileFormat format, ExpressionFilter filter, SortOrder order, Locale locale, boolean strict, List<File> files, RenameAction action, ConflictAction conflict, File output) throws Exception;
|
||||
|
||||
List<File> rename(Map<File, File> rename, RenameAction action, ConflictAction conflict) throws Exception;
|
||||
|
||||
List<File> revert(Collection<File> files, FileFilter filter, RenameAction action) throws Exception;
|
||||
|
@ -141,6 +141,31 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<File> rename(EpisodeListProvider db, String query, ExpressionFileFormat format, ExpressionFilter filter, SortOrder order, Locale locale, boolean strict, List<File> files, RenameAction action, ConflictAction conflict, File output) throws Exception {
|
||||
// match files and episodes in linear order
|
||||
List<Episode> episodes = fetchEpisodeList(db, query, filter, order, locale, strict);
|
||||
|
||||
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
|
||||
for (int i = 0; i < files.size() && i < episodes.size(); i++) {
|
||||
matches.add(new Match<File, Episode>(files.get(i), episodes.get(i)));
|
||||
}
|
||||
|
||||
// map old files to new paths by applying formatting and validating filenames
|
||||
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
||||
|
||||
for (Match<File, ?> match : matches) {
|
||||
File file = match.getValue();
|
||||
Object episode = match.getCandidate();
|
||||
String newName = format != null ? format.format(new MediaBindingBean(episode, file, getContext(matches))) : validateFileName(EpisodeFormat.SeasonEpisode.format(episode));
|
||||
|
||||
renameMap.put(file, getDestinationFile(file, newName, output));
|
||||
}
|
||||
|
||||
// rename episodes
|
||||
return renameAll(renameMap, action, conflict, matches);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<File> rename(Map<File, File> renameMap, RenameAction renameAction, ConflictAction conflict) throws Exception {
|
||||
// generic rename function that can be passed any set of files
|
||||
@ -985,13 +1010,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> fetchEpisodeList(EpisodeListProvider db, String query, ExpressionFormat format, ExpressionFilter filter, SortOrder order, Locale locale, boolean strict) throws Exception {
|
||||
// default episode format
|
||||
if (format == null) {
|
||||
return fetchEpisodeList(db, query, new ExpressionFormat("{episode}"), filter, order, locale, strict);
|
||||
}
|
||||
|
||||
private List<Episode> fetchEpisodeList(EpisodeListProvider db, String query, ExpressionFilter filter, SortOrder order, Locale locale, boolean strict) throws Exception {
|
||||
// sanity check
|
||||
if (query == null) {
|
||||
throw new CmdlineException(String.format("%s: query parameter is required", db.getName()));
|
||||
@ -1019,7 +1038,18 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||
}
|
||||
|
||||
// apply filter
|
||||
episodes = applyExpressionFilter(episodes, filter);
|
||||
return applyExpressionFilter(episodes, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> fetchEpisodeList(EpisodeListProvider db, String query, ExpressionFormat format, ExpressionFilter filter, SortOrder order, Locale locale, boolean strict) throws Exception {
|
||||
// default episode format
|
||||
if (format == null) {
|
||||
return fetchEpisodeList(db, query, new ExpressionFormat("{episode}"), filter, order, locale, strict);
|
||||
}
|
||||
|
||||
// collect all episode objects first
|
||||
List<Episode> episodes = fetchEpisodeList(db, query, filter, order, locale, strict);
|
||||
|
||||
// lazy format
|
||||
Map<File, Episode> context = new EntryList<File, Episode>(null, episodes);
|
||||
|
Loading…
Reference in New Issue
Block a user