mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-16 14:25:02 -05:00
Improve Subtitle Upload usability
This commit is contained in:
parent
07c64dbd61
commit
c3decda9cb
@ -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(() -> {
|
||||||
|
// 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
|
private Optional<File> findMatch(File file, List<File> options, Function<File, String> comparator) {
|
||||||
for (File it : videos) {
|
String name = comparator.apply(file).toLowerCase();
|
||||||
if (!baseName.isEmpty() && stripReleaseInfo(FileUtilities.getName(it)).toLowerCase().startsWith(baseName)) {
|
for (File it : options) {
|
||||||
return it;
|
if (name.length() > 0 && comparator.apply(it).toLowerCase().startsWith(name)) {
|
||||||
|
return Optional.of(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Optional.empty();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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);
|
||||||
|
@ -1705,6 +1705,7 @@ MRShanku
|
|||||||
MS
|
MS
|
||||||
mSD
|
mSD
|
||||||
MsR
|
MsR
|
||||||
|
MTeam
|
||||||
mthodmn101
|
mthodmn101
|
||||||
MUC
|
MUC
|
||||||
MURDER
|
MURDER
|
||||||
|
Loading…
Reference in New Issue
Block a user