* 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.EventObject; import java.util.EventObject;
import java.util.List; import java.util.List;
@ -58,6 +59,9 @@ import net.sourceforge.filebot.ui.LanguageComboBox;
import net.sourceforge.filebot.ui.SelectDialog; import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.web.Movie; import net.sourceforge.filebot.web.Movie;
import net.sourceforge.filebot.web.OpenSubtitlesClient; 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.filebot.web.VideoHashSubtitleService.CheckResult;
import net.sourceforge.tuned.FileUtilities; import net.sourceforge.tuned.FileUtilities;
import net.sourceforge.tuned.ui.AbstractBean; import net.sourceforge.tuned.ui.AbstractBean;
@ -170,6 +174,7 @@ public class SubtitleUploadDialog extends JDialog {
if (selectedValue != null) { if (selectedValue != null) {
mapping.setIdentity(selectedValue); mapping.setIdentity(selectedValue);
if (mapping.getIdentity() != null && mapping.getLanguage() != null) { if (mapping.getIdentity() != null && mapping.getLanguage() != null) {
mapping.setForceIdentity(true);
mapping.setState(SubtitleMapping.Status.CheckPending); mapping.setState(SubtitleMapping.Status.CheckPending);
startChecking(); startChecking();
} }
@ -579,6 +584,7 @@ public class SubtitleUploadDialog extends JDialog {
private Status status = Status.CheckPending; private Status status = Status.CheckPending;
private String message = null; private String message = null;
private boolean forceIdentity = false;
public SubtitleMapping(File subtitle, File video, Language language) { public SubtitleMapping(File subtitle, File video, Language language) {
this.subtitle = subtitle; this.subtitle = subtitle;
@ -626,6 +632,13 @@ public class SubtitleUploadDialog extends JDialog {
firePropertyChange("status", null, this.status); 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> { private class CheckTask extends SwingWorker<Object, Void> {
@ -639,18 +652,22 @@ public class SubtitleUploadDialog extends JDialog {
@Override @Override
protected Object doInBackground() throws Exception { protected Object doInBackground() throws Exception {
try { try {
mapping.setState(SubtitleMapping.Status.Checking); CheckResult checkResult = null;
CheckResult checkResult = database.checkSubtitle(mapping.getVideo(), mapping.getSubtitle());
Analytics.trackEvent(database.getName(), "CheckSubtitle", null, checkResult.exists ? 1 : 0); if (!mapping.getForceIdentity()) {
mapping.setState(SubtitleMapping.Status.Checking);
// accept identity hint from search result checkResult = database.checkSubtitle(mapping.getVideo(), mapping.getSubtitle());
mapping.setIdentity(checkResult.identity); Analytics.trackEvent(database.getName(), "CheckSubtitle", null, checkResult.exists ? 1 : 0);
if (checkResult.exists) { // accept identity hint from search result
mapping.setLanguage(Language.getLanguage(checkResult.language)); // trust language hint only if upload not required mapping.setIdentity(checkResult.identity);
mapping.setState(SubtitleMapping.Status.AlreadyExists);
return checkResult; if (checkResult.exists) {
mapping.setLanguage(Language.getLanguage(checkResult.language)); // trust language hint only if upload not required
mapping.setState(SubtitleMapping.Status.AlreadyExists);
return checkResult;
}
} }
if (mapping.getLanguage() == null) { if (mapping.getLanguage() == null) {
@ -666,14 +683,29 @@ public class SubtitleUploadDialog extends JDialog {
if (mapping.getIdentity() == null) { if (mapping.getIdentity() == null) {
mapping.setState(SubtitleMapping.Status.Identifying); mapping.setState(SubtitleMapping.Status.Identifying);
try { try {
Collection<Movie> identity = MediaDetection.detectMovie(mapping.getVideo(), database, database, Locale.ENGLISH, true); if (MediaDetection.isEpisode(mapping.getVideo().getPath(), true)) {
for (Movie it : identity) { List<String> seriesNames = MediaDetection.detectSeriesNames(Collections.singleton(mapping.getVideo()), true, false, Locale.ENGLISH);
if (it.getImdbId() <= 0 && it.getTmdbId() > 0) { for (String name : seriesNames) {
it = WebServices.TMDb.getMovieDescriptor(it.getTmdbId(), Locale.ENGLISH, false); 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;
}
}
} }
if (it != null && it.getImdbId() > 0) { } else {
mapping.setIdentity(it); Collection<Movie> identity = MediaDetection.detectMovie(mapping.getVideo(), database, database, Locale.ENGLISH, true);
break; for (Movie it : identity) {
if (it.getImdbId() <= 0 && it.getTmdbId() > 0) {
it = WebServices.TMDb.getMovieDescriptor(it.getTmdbId(), Locale.ENGLISH, false);
}
if (it != null && it.getImdbId() > 0) {
mapping.setIdentity(it);
break;
}
} }
} }
} catch (Exception e) { } catch (Exception e) {