Exemple #1
0
 @Override
 public VideoHashSubtitleService[] getVideoHashSubtitleServices() {
   Locale locale =
       languageComboBox.getModel().getSelectedItem() == ALL_LANGUAGES
           ? Locale.ROOT
           : languageComboBox.getModel().getSelectedItem().getLocale();
   return WebServices.getVideoHashSubtitleServices(locale);
 }
Exemple #2
0
        @Override
        public void actionPerformed(ActionEvent evt) {
          final JDialog authPanel =
              new JDialog(getWindow(SubtitlePanel.this), ModalityType.APPLICATION_MODAL);
          authPanel.setTitle("Login");
          authPanel.setLocation(getOffsetLocation(authPanel.getOwner()));

          JPanel osdbGroup = new JPanel(new MigLayout("fill, insets panel"));
          osdbGroup.setBorder(new TitledBorder("OpenSubtitles"));
          osdbGroup.add(new JLabel("Username:"******"gap rel");
          final JTextField osdbUser = new JTextField(12);
          osdbGroup.add(osdbUser, "growx, wrap rel");

          osdbGroup.add(new JLabel("Password:"******"gap rel");
          final JPasswordField osdbPass = new JPasswordField(12);
          osdbGroup.add(osdbPass, "growx, wrap unrel");

          // restore values
          String[] osdbAuth = WebServices.getLogin(WebServices.LOGIN_OPENSUBTITLES);
          osdbUser.setText(osdbAuth[0]);
          // osdbPass.setText(osdbAuth[1]); // password is stored as MD5 hash so we can't restore it

          if (osdbUser.getText().isEmpty()) {
            osdbGroup.add(
                new LinkButton(
                    "Register Account",
                    "Register to increase your download quota",
                    WebServices.OpenSubtitles.getIcon(),
                    URI.create("http://www.opensubtitles.org/en/newuser")),
                "spanx 2, tag left");
          } else {
            osdbGroup.add(
                new LinkButton(
                    "Upgrade Account",
                    "Upgrade to increase your download quota",
                    WebServices.OpenSubtitles.getIcon(),
                    URI.create("http://www.opensubtitles.org/en/support")),
                "spanx 2, tag left");
          }

          JRootPane container = authPanel.getRootPane();
          container.setLayout(new MigLayout("fill, insets dialog"));
          container.removeAll();

          container.add(osdbGroup, "growx, wrap");

          Action ok =
              new AbstractAction("OK", ResourceManager.getIcon("dialog.continue")) {

                @Override
                public void actionPerformed(ActionEvent evt) {
                  authPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                  boolean approved = true;

                  try {
                    if (osdbUser.getText().length() > 0 && osdbPass.getPassword().length > 0) {
                      final OpenSubtitlesClient osdb =
                          new OpenSubtitlesClient(getApplicationName(), getApplicationVersion());
                      osdb.setUser(osdbUser.getText(), md5(new String(osdbPass.getPassword())));
                      osdb.login();

                      // do some status checks in background (since OpenSubtitles can be really
                      // really slow)
                      WebServices.requestThreadPool.submit(
                          () -> {
                            try {
                              // check download quota for the current user
                              Map<?, ?> limits =
                                  (Map<?, ?>) osdb.getServerInfo().get("download_limits");
                              log.log(
                                  Level.INFO,
                                  String.format(
                                      "Your daily download quota is at %s of %s.",
                                      limits.get("client_24h_download_count"),
                                      limits.get("client_24h_download_limit")));

                              // logout from test session
                              osdb.logout();
                            } catch (Exception e) {
                              debug.warning(e.getMessage());
                            }
                          });
                    } else if (osdbUser.getText().isEmpty()) {
                      WebServices.setLogin(
                          WebServices.LOGIN_OPENSUBTITLES, null, null); // delete login details
                    }
                  } catch (Exception e) {
                    log.log(Level.WARNING, "OpenSubtitles: " + e.getMessage());
                    approved = false;
                  }

                  authPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                  if (approved) {
                    WebServices.setLogin(
                        WebServices.LOGIN_OPENSUBTITLES,
                        osdbUser.getText(),
                        new String(osdbPass.getPassword()));
                    authPanel.setVisible(false);
                  }
                }
              };
          Action cancel =
              new AbstractAction("Cancel", ResourceManager.getIcon("dialog.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");

          authPanel.pack();
          authPanel.setVisible(true);
        }
Exemple #3
0
 @Override
 protected SubtitleProvider[] getSearchEngines() {
   return WebServices.getSubtitleProviders();
 }
Exemple #4
0
 @Override
 public SubtitleProvider[] getSubtitleProviders() {
   return WebServices.getSubtitleProviders();
 }