diff --git a/source/net/sourceforge/filebot/Main.java b/source/net/sourceforge/filebot/Main.java index 445dc4aa..49b9dd71 100644 --- a/source/net/sourceforge/filebot/Main.java +++ b/source/net/sourceforge/filebot/Main.java @@ -210,7 +210,6 @@ public class Main { // hook donation reminder into rename history if (useDonationReminder()) { - System.out.println("Main.main()"); final HistoryStorage fileStorage = HistorySpooler.getInstance().getPersistentHistory(); HistorySpooler.getInstance().setPersistentHistory(new HistoryStorage() { diff --git a/source/net/sourceforge/filebot/Settings.java b/source/net/sourceforge/filebot/Settings.java index 2e35077b..06e5fbce 100644 --- a/source/net/sourceforge/filebot/Settings.java +++ b/source/net/sourceforge/filebot/Settings.java @@ -144,7 +144,11 @@ public final class Settings { public void put(String key, String value) { - prefs.put(key, value); + if (value != null) { + prefs.put(key, value); + } else { + remove(key); + } } diff --git a/source/net/sourceforge/filebot/Settings.properties b/source/net/sourceforge/filebot/Settings.properties index 4039a3b6..b7f87601 100644 --- a/source/net/sourceforge/filebot/Settings.properties +++ b/source/net/sourceforge/filebot/Settings.properties @@ -21,3 +21,5 @@ serienjunkies.apikey: 9fbhw9uebfiwvbefzuwv fanart.tv.apikey: 780b986b22c35e6f7a134a2f392c2deb acoustid.apikey: 0B3qZnQc pushover.apikey: wcckDz3oygHSU2SdIptvnHxJ92SQKK +sublight.clientid: FileBot2 +sublight.apikey: 79f7a868-c28c-446f-a58e-3637ca24c87a diff --git a/source/net/sourceforge/filebot/WebServices.java b/source/net/sourceforge/filebot/WebServices.java index 26fd90fc..2f01d596 100644 --- a/source/net/sourceforge/filebot/WebServices.java +++ b/source/net/sourceforge/filebot/WebServices.java @@ -224,16 +224,31 @@ public final class WebServices { } - private static String[] getLogin(String key) { - // try system property first - String login = System.getProperty(key); - - // try settings second - if (login == null) { - login = Settings.forPackage(WebServices.class).get(key, ":"); + public static String[] getLogin(String key) { + return Settings.forPackage(WebServices.class).get(key, ":").split(":", 2); + } + + + public static void setLogin(String id, String user, String password) { + Settings settings = Settings.forPackage(WebServices.class); + String value = user.length() > 0 && password.length() > 0 ? user + ":" + password : null; + if (value == null) { + user = ""; + password = ""; } - return login.split(":", 2); + if (id.equals("osdb.user")) { + settings.put(id, value); + OpenSubtitles.setUser(user, password); + } else if (id.equals("sublight.user")) { + settings.put(id, value); + Sublight.setUser(user, password); + } else if (id.equals("sublight.client")) { + settings.put(id, value); + Sublight.setClient(user, password); + } else { + throw new IllegalArgumentException(); + } } } diff --git a/source/net/sourceforge/filebot/resources/action.user.png b/source/net/sourceforge/filebot/resources/action.user.png new file mode 100644 index 00000000..899553aa Binary files /dev/null and b/source/net/sourceforge/filebot/resources/action.user.png differ diff --git a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java index 3b470c64..b5265c40 100644 --- a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java +++ b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java @@ -68,15 +68,13 @@ public abstract class AbstractSearchPanel extends JComponent { tabbedPaneGroup.setBorder(BorderFactory.createTitledBorder("Search Results")); tabbedPaneGroup.add(tabbedPane, "grow, wrap"); - setLayout(new MigLayout("nogrid, fill, insets 10px 10px 15px 10px", "align center", "[pref!]10px[fill]")); add(searchTextField); - add(new JButton(searchAction), "gap 18px, wrap"); - add(tabbedPaneGroup, "grow"); + add(new JButton(searchAction), "gap 18px, id search"); + add(tabbedPaneGroup, "newline, grow"); searchTextField.getEditor().setAction(searchAction); - searchTextField.getSelectButton().setModel(Arrays.asList(getSearchEngines())); searchTextField.getSelectButton().setLabelProvider(getSearchEngineLabelProvider()); @@ -98,7 +96,6 @@ public abstract class AbstractSearchPanel extends JComponent { }); AutoCompleteSupport.install(searchTextField.getEditor(), searchHistory).setFilterMode(TextMatcherEditor.CONTAINS); - installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), searchAction); } diff --git a/source/net/sourceforge/filebot/ui/subtitle/SubtitlePanel.java b/source/net/sourceforge/filebot/ui/subtitle/SubtitlePanel.java index 25f60133..5552efe1 100644 --- a/source/net/sourceforge/filebot/ui/subtitle/SubtitlePanel.java +++ b/source/net/sourceforge/filebot/ui/subtitle/SubtitlePanel.java @@ -2,27 +2,48 @@ package net.sourceforge.filebot.ui.subtitle; +import static net.sourceforge.filebot.Settings.*; import static net.sourceforge.filebot.ui.LanguageComboBoxModel.*; +import static net.sourceforge.filebot.ui.NotificationLogging.*; +import static net.sourceforge.tuned.ui.TunedUtilities.*; import java.awt.Color; +import java.awt.Cursor; +import java.awt.Dialog.ModalityType; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; +import java.awt.event.ActionEvent; import java.awt.geom.Path2D; import java.net.URI; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.logging.Level; +import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JRootPane; +import javax.swing.JTextField; +import javax.swing.border.TitledBorder; +import net.miginfocom.swing.MigLayout; +import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.Settings; import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.ui.AbstractSearchPanel; import net.sourceforge.filebot.ui.Language; import net.sourceforge.filebot.ui.LanguageComboBox; import net.sourceforge.filebot.ui.SelectDialog; +import net.sourceforge.filebot.web.OpenSubtitlesClient; import net.sourceforge.filebot.web.SearchResult; +import net.sourceforge.filebot.web.SublightSubtitleClient; import net.sourceforge.filebot.web.SubtitleDescriptor; import net.sourceforge.filebot.web.SubtitleProvider; import net.sourceforge.filebot.web.VideoHashSubtitleService; @@ -34,19 +55,19 @@ public class SubtitlePanel extends AbstractSearchPanel getSearchEngineLabelProvider() { return SimpleLabelProvider.forClass(SubtitleProvider.class); } - + @Override protected Settings getSettings() { return Settings.forPackage(SubtitlePanel.class); } - + @Override protected SubtitleRequestProcessor createRequestProcessor() { SubtitleProvider provider = searchTextField.getSelectButton().getSelectedValue(); @@ -120,13 +141,13 @@ public class SubtitlePanel extends AbstractSearchPanel { public SubtitleRequestProcessor(SubtitleRequest request) { super(request, new SubtitleDownloadComponent()); } - + @Override public Collection search() throws Exception { return request.getProvider().search(request.getSearchText()); } - + @Override public Collection fetch() throws Exception { List packages = new ArrayList(); @@ -171,38 +192,38 @@ public class SubtitlePanel extends AbstractSearchPanel subtitles) { getComponent().setLanguageVisible(request.getLanguageName() == null); getComponent().getPackageModel().addAll(subtitles); } - + @Override public SubtitleDownloadComponent getComponent() { return (SubtitleDownloadComponent) super.getComponent(); } - + @Override public String getStatusMessage(Collection result) { return (result.isEmpty()) ? "No subtitles found" : String.format("%d subtitles", result.size()); } - + @Override public Icon getIcon() { return request.provider.getIcon(); } - + @Override protected void configureSelectDialog(SelectDialog selectDialog) { super.configureSelectDialog(selectDialog); @@ -211,4 +232,99 @@ public class SubtitlePanel extends AbstractSearchPanel 0 && osdbPass.getPassword().length > 0) { + OpenSubtitlesClient osdb = new OpenSubtitlesClient(String.format("%s %s", getApplicationName(), getApplicationVersion())); + osdb.setUser(osdbUser.getText(), new String(osdbPass.getPassword())); + osdb.login(); + } + } catch (Exception e) { + UILogger.log(Level.WARNING, "OpenSubtitles: " + e.getMessage()); + approved = false; + } + try { + if (sublUser.getText().length() > 0 && sublPass.getPassword().length > 0) { + SublightSubtitleClient sublight = new SublightSubtitleClient(); + sublight.setClient(getApplicationProperty("sublight.clientid"), getApplicationProperty("sublight.apikey")); + sublight.setUser(sublUser.getText(), new String(sublPass.getPassword())); + sublight.login(); + } + } catch (Exception e) { + UILogger.log(Level.WARNING, "Sublight: " + e.getMessage()); + approved = false; + } + authPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + if (approved) { + WebServices.setLogin("osdb.user", osdbUser.getText(), new String(osdbPass.getPassword())); + WebServices.setLogin("sublight.user", sublUser.getText(), new String(sublPass.getPassword())); + WebServices.setLogin("sublight.client", getApplicationProperty("sublight.clientid"), getApplicationProperty("sublight.apikey")); + authPanel.setVisible(false); + } + } + }; + Action cancel = new AbstractAction("Cancel") { + + @Override + public void actionPerformed(ActionEvent evt) { + authPanel.setVisible(false); + } + }; + container.add(new JButton(cancel), "tag cancel, split 2"); + container.add(new JButton(ok), "tag ok"); + + // restore values + String[] osdbAuth = WebServices.getLogin("osdb.user"); + osdbUser.setText(osdbAuth[0]); + osdbPass.setText(osdbAuth[1]); + String[] sublAuth = WebServices.getLogin("sublight.user"); + sublUser.setText(sublAuth[0]); + sublPass.setText(sublAuth[1]); + + authPanel.pack(); + authPanel.setVisible(true); + } + }; + } diff --git a/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java b/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java index f0fa4857..a3e0a9fc 100644 --- a/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java +++ b/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java @@ -322,7 +322,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS } - protected synchronized void login() throws Exception { + public synchronized void login() throws Exception { if (!xmlrpc.isLoggedOn()) { xmlrpc.login(username, password, "en"); } diff --git a/source/net/sourceforge/filebot/web/SublightSubtitleClient.java b/source/net/sourceforge/filebot/web/SublightSubtitleClient.java index a57a46da..25f48a9d 100644 --- a/source/net/sourceforge/filebot/web/SublightSubtitleClient.java +++ b/source/net/sourceforge/filebot/web/SublightSubtitleClient.java @@ -358,13 +358,12 @@ public class SublightSubtitleClient implements SubtitleProvider, VideoHashSubtit public synchronized void setClient(String id, String key) { clientInfo.setClientId(id); clientInfo.setApiKey(key); - } public synchronized void setUser(String username, String password) { this.username = username; - this.passwordHash = getPasswordHash(password); + this.passwordHash = password != null && password.length() > 0 ? getPasswordHash(password) : null; } @@ -379,7 +378,7 @@ public class SublightSubtitleClient implements SubtitleProvider, VideoHashSubtit } - protected synchronized void login() throws WebServiceException { + public synchronized void login() throws WebServiceException { if (clientInfo.getClientId() == null || clientInfo.getClientId().isEmpty()) { throw new IllegalStateException("Sublight login has not been configured"); } @@ -439,7 +438,6 @@ public class SublightSubtitleClient implements SubtitleProvider, VideoHashSubtit } } - protected final Timer logoutTimer = new Timer() { @Override