1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 22:35:04 -05: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.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.function.Function;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.Icon; import javax.swing.Icon;
@ -284,16 +286,21 @@ abstract class SubtitleDropTarget extends JButton {
} }
protected File getVideoForSubtitle(File subtitle, List<File> videos) { 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(() -> {
// find corresponding movie file // 2. guess movie file from the parent folder if only a subtitle file was dropped in
for (File it : videos) { return findMatch(subtitle, getChildren(subtitle.getParentFile(), VIDEO_FILES), FileUtilities::getName).get();
if (!baseName.isEmpty() && stripReleaseInfo(FileUtilities.getName(it)).toLowerCase().startsWith(baseName)) { });
return it;
}
} }
return null; 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 Optional.empty();
} }
@Override @Override

View File

@ -200,7 +200,7 @@ public class SubtitleUploadDialog extends JDialog {
} }
} }
} else { } 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) { } catch (Exception e) {
Logger.getLogger(SubtitleUploadDialog.class.getClass().getName()).log(Level.WARNING, e.getMessage(), e); Logger.getLogger(SubtitleUploadDialog.class.getClass().getName()).log(Level.WARNING, e.getMessage(), e);

View File

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