1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

Improve Subtitle Upload usability

This commit is contained in:
Reinhard Pointner 2016-02-01 10:09:06 +00:00
parent 07c64dbd61
commit c3decda9cb
3 changed files with 16 additions and 8 deletions

View File

@ -23,7 +23,9 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeSet;
import java.util.function.Function;
import java.util.logging.Level;
import javax.swing.Icon;
@ -284,16 +286,21 @@ abstract class SubtitleDropTarget extends JButton {
}
protected File getVideoForSubtitle(File subtitle, List<File> videos) {
String baseName = stripReleaseInfo(FileUtilities.getName(subtitle)).toLowerCase();
// 1. try to find exact match in drop data
return findMatch(subtitle, videos, FileUtilities::getName).orElseGet(() -> {
// 2. guess movie file from the parent folder if only a subtitle file was dropped in
return findMatch(subtitle, getChildren(subtitle.getParentFile(), VIDEO_FILES), FileUtilities::getName).get();
});
}
// find corresponding movie file
for (File it : videos) {
if (!baseName.isEmpty() && stripReleaseInfo(FileUtilities.getName(it)).toLowerCase().startsWith(baseName)) {
return it;
private Optional<File> findMatch(File file, List<File> options, Function<File, String> comparator) {
String name = comparator.apply(file).toLowerCase();
for (File it : options) {
if (name.length() > 0 && comparator.apply(it).toLowerCase().startsWith(name)) {
return Optional.of(it);
}
}
return null;
return Optional.empty();
}
@Override

View File

@ -200,7 +200,7 @@ public class SubtitleUploadDialog extends JDialog {
}
}
} else {
UILogger.warning(String.format("%s: \"%s\" not found.", database.getName(), input));
UILogger.warning(String.format("%s: \"%s\" has not been found", database.getName(), input));
}
} catch (Exception e) {
Logger.getLogger(SubtitleUploadDialog.class.getClass().getName()).log(Level.WARNING, e.getMessage(), e);

View File

@ -1705,6 +1705,7 @@ MRShanku
MS
mSD
MsR
MTeam
mthodmn101
MUC
MURDER