* all users will now require authentication when using OpenSubtitles

This commit is contained in:
Reinhard Pointner 2014-10-28 16:52:08 +00:00
parent f14aa89625
commit 8fe8e4d400
5 changed files with 50 additions and 72 deletions

View File

@ -166,7 +166,10 @@ public abstract class AbstractSearchPanel<S, E> extends JComponent {
return; return;
} }
search(createRequestProcessor()); RequestProcessor<?, E> request = createRequestProcessor();
if (request != null) {
search(request);
}
} }
}; };

View File

@ -31,6 +31,7 @@ import javax.swing.JButton;
import javax.swing.JDialog; import javax.swing.JDialog;
import net.filebot.ResourceManager; import net.filebot.ResourceManager;
import net.filebot.Settings;
import net.filebot.util.FileUtilities; import net.filebot.util.FileUtilities;
import net.filebot.util.FileUtilities.ParentFilter; import net.filebot.util.FileUtilities.ParentFilter;
import net.filebot.web.OpenSubtitlesClient; import net.filebot.web.OpenSubtitlesClient;
@ -69,6 +70,8 @@ abstract class SubtitleDropTarget extends JButton {
setIcon(getIcon(dropAction)); setIcon(getIcon(dropAction));
} }
protected abstract OpenSubtitlesClient getSubtitleService();
protected abstract boolean handleDrop(List<File> files); protected abstract boolean handleDrop(List<File> files);
protected abstract DropAction getDropAction(List<File> files); protected abstract DropAction getDropAction(List<File> files);
@ -158,6 +161,11 @@ abstract class SubtitleDropTarget extends JButton {
return false; return false;
} }
if (getSubtitleService().isAnonymous() && !Settings.isAppStore()) {
UILogger.info(String.format("%s: Please enter your login details first.", getSubtitleService().getName()));
return false;
}
// perform a drop action depending on the given files // perform a drop action depending on the given files
final Collection<File> videoFiles = new TreeSet<File>(); final Collection<File> videoFiles = new TreeSet<File>();
@ -221,8 +229,6 @@ abstract class SubtitleDropTarget extends JButton {
public static abstract class Upload extends SubtitleDropTarget { public static abstract class Upload extends SubtitleDropTarget {
public abstract OpenSubtitlesClient getSubtitleService();
@Override @Override
protected DropAction getDropAction(List<File> input) { protected DropAction getDropAction(List<File> input) {
// accept video files and folders // accept video files and folders
@ -232,7 +238,7 @@ abstract class SubtitleDropTarget extends JButton {
@Override @Override
protected boolean handleDrop(List<File> input) { protected boolean handleDrop(List<File> input) {
if (getSubtitleService().isAnonymous()) { if (getSubtitleService().isAnonymous()) {
UILogger.info("Please login. Anonymous user is not allowed to upload subtitles."); UILogger.info(String.format("%s: Please enter your login details first.", getSubtitleService().getName()));
return false; return false;
} }

View File

@ -30,6 +30,7 @@ import javax.swing.JPanel;
import javax.swing.JPasswordField; import javax.swing.JPasswordField;
import javax.swing.JRootPane; import javax.swing.JRootPane;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import net.filebot.Language; import net.filebot.Language;
@ -109,6 +110,10 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
return WebServices.getSubtitleProviders(); return WebServices.getSubtitleProviders();
} }
public OpenSubtitlesClient getSubtitleService() {
return WebServices.OpenSubtitles;
};
@Override @Override
public String getQueryLanguage() { public String getQueryLanguage() {
// use currently selected language for drop target // use currently selected language for drop target
@ -165,6 +170,15 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
String text = searchTextField.getText().trim(); String text = searchTextField.getText().trim();
Language language = languageComboBox.getModel().getSelectedItem(); Language language = languageComboBox.getModel().getSelectedItem();
if (provider instanceof OpenSubtitlesClient && ((OpenSubtitlesClient) provider).isAnonymous() && !Settings.isAppStore()) {
UILogger.info(String.format("%s: Please enter your login details first.", ((OpenSubtitlesClient) provider).getName()));
// automatically open login dialog
SwingUtilities.invokeLater(() -> setUserAction.actionPerformed(new ActionEvent(searchTextField, 0, "login")));
return null;
}
return new SubtitleRequestProcessor(new SubtitleRequest(provider, text, language)); return new SubtitleRequestProcessor(new SubtitleRequest(provider, text, language));
} }

View File

@ -91,25 +91,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
@Override @Override
public List<SearchResult> search(String query) throws Exception { public List<SearchResult> search(String query) throws Exception {
List<SearchResult> result = getCache().getSearchResult("search", query, null); throw new UnsupportedOperationException("SearchMoviesOnIMDB is not supported due to abuse");
if (result != null) {
return result;
}
// require login
login();
try {
// search for movies / series
List<Movie> resultSet = xmlrpc.searchMoviesOnIMDB(query);
result = asList(resultSet.toArray(new SearchResult[0]));
} catch (ClassCastException e) {
// unexpected xmlrpc responses (e.g. error messages instead of results) will trigger this
throw new XmlRpcException("Illegal XMLRPC response on searchMoviesOnIMDB");
}
getCache().putSearchResult("search", query, null, result);
return result;
} }
@Override @Override
@ -378,41 +360,14 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
} }
} }
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override @Override
public List<Movie> searchMovie(String query, Locale locale) throws Exception { public List<Movie> searchMovie(String query, Locale locale) throws Exception {
List<SearchResult> result = getCache().getSearchResult("searchMovie", query, locale); throw new UnsupportedOperationException("SearchMoviesOnIMDB is not supported due to abuse");
if (result != null) {
return (List) result;
}
// require login
login();
List<Movie> movies = xmlrpc.searchMoviesOnIMDB(query);
getCache().putSearchResult("searchMovie", query, locale, movies);
return movies;
} }
@Override @Override
public Movie getMovieDescriptor(Movie id, Locale locale) throws Exception { public Movie getMovieDescriptor(Movie id, Locale locale) throws Exception {
if (id.getImdbId() <= 0) { throw new UnsupportedOperationException("GetIMDBMovieDetails is not supported due to abuse");
throw new IllegalArgumentException("id must not be " + id.getImdbId());
}
Movie result = getCache().getData("getMovieDescriptor", id.getImdbId(), locale, Movie.class);
if (result != null) {
return result;
}
// require login
login();
Movie movie = xmlrpc.getIMDBMovieDetails(id.getImdbId());
getCache().putData("getMovieDescriptor", id.getImdbId(), locale, movie);
return movie;
} }
public Movie getMovieDescriptor(File movieFile, Locale locale) throws Exception { public Movie getMovieDescriptor(File movieFile, Locale locale) throws Exception {

View File

@ -145,6 +145,26 @@ public class OpenSubtitlesXmlRpc {
return movies; return movies;
} }
@SuppressWarnings("unchecked")
@Deprecated
public Movie getIMDBMovieDetails(int imdbid) throws XmlRpcFault {
Map<?, ?> response = invoke("GetIMDBMovieDetails", token, imdbid);
try {
Map<String, String> data = (Map<String, String>) response.get("data");
String name = data.get("title");
int year = Integer.parseInt(data.get("year"));
return new Movie(name, year, imdbid, -1);
} catch (RuntimeException e) {
// ignore, invalid response
Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Failed to lookup movie by imdbid %s: %s", imdbid, e.getMessage()));
}
return null;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public TryUploadResponse tryUploadSubtitles(SubFile... subtitles) throws XmlRpcFault { public TryUploadResponse tryUploadSubtitles(SubFile... subtitles) throws XmlRpcFault {
Map<String, SubFile> struct = new HashMap<String, SubFile>(); Map<String, SubFile> struct = new HashMap<String, SubFile>();
@ -265,26 +285,6 @@ public class OpenSubtitlesXmlRpc {
return getSubLanguages("en"); return getSubLanguages("en");
} }
@SuppressWarnings("unchecked")
@Deprecated
public Movie getIMDBMovieDetails(int imdbid) throws XmlRpcFault {
Map<?, ?> response = invoke("GetIMDBMovieDetails", token, imdbid);
try {
Map<String, String> data = (Map<String, String>) response.get("data");
String name = data.get("title");
int year = Integer.parseInt(data.get("year"));
return new Movie(name, year, imdbid, -1);
} catch (RuntimeException e) {
// ignore, invalid response
Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Failed to lookup movie by imdbid %s: %s", imdbid, e.getMessage()));
}
return null;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Map<String, String> getSubLanguages(String languageCode) throws XmlRpcFault { public Map<String, String> getSubLanguages(String languageCode) throws XmlRpcFault {
Map<String, List<Map<String, String>>> response = (Map<String, List<Map<String, String>>>) invoke("GetSubLanguages", languageCode); Map<String, List<Map<String, String>>> response = (Map<String, List<Map<String, String>>>) invoke("GetSubLanguages", languageCode);