* enhanced support for uploading subtitles for episode files

This commit is contained in:
Reinhard Pointner 2014-03-05 16:17:43 +00:00
parent 9a6adb4a85
commit b6eee5d405
1 changed files with 48 additions and 16 deletions

View File

@ -15,6 +15,7 @@ import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.EventObject;
import java.util.List;
@ -58,6 +59,9 @@ import net.sourceforge.filebot.ui.LanguageComboBox;
import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.web.Movie;
import net.sourceforge.filebot.web.OpenSubtitlesClient;
import net.sourceforge.filebot.web.SearchResult;
import net.sourceforge.filebot.web.TheTVDBClient.SeriesInfo;
import net.sourceforge.filebot.web.TheTVDBSearchResult;
import net.sourceforge.filebot.web.VideoHashSubtitleService.CheckResult;
import net.sourceforge.tuned.FileUtilities;
import net.sourceforge.tuned.ui.AbstractBean;
@ -170,6 +174,7 @@ public class SubtitleUploadDialog extends JDialog {
if (selectedValue != null) {
mapping.setIdentity(selectedValue);
if (mapping.getIdentity() != null && mapping.getLanguage() != null) {
mapping.setForceIdentity(true);
mapping.setState(SubtitleMapping.Status.CheckPending);
startChecking();
}
@ -579,6 +584,7 @@ public class SubtitleUploadDialog extends JDialog {
private Status status = Status.CheckPending;
private String message = null;
private boolean forceIdentity = false;
public SubtitleMapping(File subtitle, File video, Language language) {
this.subtitle = subtitle;
@ -626,6 +632,13 @@ public class SubtitleUploadDialog extends JDialog {
firePropertyChange("status", null, this.status);
}
public boolean getForceIdentity() {
return this.forceIdentity;
}
public void setForceIdentity(boolean forceIdentity) {
this.forceIdentity = forceIdentity;
}
}
private class CheckTask extends SwingWorker<Object, Void> {
@ -639,9 +652,12 @@ public class SubtitleUploadDialog extends JDialog {
@Override
protected Object doInBackground() throws Exception {
try {
mapping.setState(SubtitleMapping.Status.Checking);
CheckResult checkResult = database.checkSubtitle(mapping.getVideo(), mapping.getSubtitle());
CheckResult checkResult = null;
if (!mapping.getForceIdentity()) {
mapping.setState(SubtitleMapping.Status.Checking);
checkResult = database.checkSubtitle(mapping.getVideo(), mapping.getSubtitle());
Analytics.trackEvent(database.getName(), "CheckSubtitle", null, checkResult.exists ? 1 : 0);
// accept identity hint from search result
@ -652,6 +668,7 @@ public class SubtitleUploadDialog extends JDialog {
mapping.setState(SubtitleMapping.Status.AlreadyExists);
return checkResult;
}
}
if (mapping.getLanguage() == null) {
mapping.setState(SubtitleMapping.Status.Identifying);
@ -666,6 +683,20 @@ public class SubtitleUploadDialog extends JDialog {
if (mapping.getIdentity() == null) {
mapping.setState(SubtitleMapping.Status.Identifying);
try {
if (MediaDetection.isEpisode(mapping.getVideo().getPath(), true)) {
List<String> seriesNames = MediaDetection.detectSeriesNames(Collections.singleton(mapping.getVideo()), true, false, Locale.ENGLISH);
for (String name : seriesNames) {
List<SearchResult> options = WebServices.TheTVDB.search(name, Locale.ENGLISH);
for (SearchResult entry : options) {
SeriesInfo seriesInfo = WebServices.TheTVDB.getSeriesInfo((TheTVDBSearchResult) entry, Locale.ENGLISH);
Integer imdbid = seriesInfo.getImdbId();
if (imdbid != null && imdbid > 0) {
mapping.setIdentity(WebServices.OpenSubtitles.getMovieDescriptor(imdbid, Locale.ENGLISH));
break;
}
}
}
} else {
Collection<Movie> identity = MediaDetection.detectMovie(mapping.getVideo(), database, database, Locale.ENGLISH, true);
for (Movie it : identity) {
if (it.getImdbId() <= 0 && it.getTmdbId() > 0) {
@ -676,6 +707,7 @@ public class SubtitleUploadDialog extends JDialog {
break;
}
}
}
} catch (Exception e) {
Logger.getLogger(CheckTask.class.getClass().getName()).log(Level.WARNING, "Failed to auto-detect movie: " + e.getMessage());
}