@Override
    public void actionPerformed(ActionEvent e) {
      final short videoCount = (short) TABLE.getSelectedRows().length;

      // can't happen, but just in case.
      if (videoCount < 1) {
        return;
      }

      // get selected files before we switch to audio and loose the selection
      final List<File> selectedFiles = getSelectedFiles();

      selectAudio();

      String status = I18n.tr("Extracting audio from " + videoCount + " selected videos...");
      if (videoCount == 1) {
        status = I18n.tr("Extracting audio from selected video...");
      }
      LibraryMediator.instance().getLibrarySearch().pushStatus(status);

      SwingWorker<Void, Void> demuxWorker =
          new SwingWorker<Void, Void>() {

            @Override
            protected Void doInBackground() throws Exception {
              isDemuxing = true;
              demuxFiles(selectedFiles);
              isDemuxing = false;
              return null;
            }

            @Override
            protected void done() {
              int failed = videoCount - demuxedFiles.size();
              String failedStr = (failed > 0) ? " (" + failed + " " + I18n.tr("failed") + ")" : "";
              LibraryMediator.instance()
                  .getLibrarySearch()
                  .pushStatus(I18n.tr("Done extracting audio.") + failedStr);
            }
          };
      demuxWorker.execute();
    }
 @Override
 protected void done() {
   super.done();
   try {
     this.get();
     listener.done();
   } catch (InterruptedException e) {
     listener.setStatus("Interrupted Exception: " + e.getMessage());
     e.printStackTrace(new PrintStream(callbacks.getStderr()));
   } catch (ExecutionException e) {
     listener.setStatus("Execution Exception: " + e.getMessage());
     e.printStackTrace(new PrintStream(callbacks.getStderr()));
   } catch (Throwable e) {
     listener.setStatus(e.getMessage());
     e.printStackTrace(new PrintStream(callbacks.getStderr()));
   }
 }
  @Override
  protected void process(List<Object> chunks) {
    super.process(chunks);
    String lastMessage = null;
    int lastPercent = -1;

    for (Object chunk : chunks) {
      if (chunk instanceof String) {
        lastMessage = (String) chunk;
      } else if (chunk instanceof Integer) {
        lastPercent = (Integer) chunk;
      }
    }

    if (lastMessage != null) {
      listener.setStatus(lastMessage);
    }
    if (lastPercent > -1) {
      listener.setProgress(lastPercent);
    }
  }
  public static EventHandler<ActionEvent> getUploadHandler(
      FXController controller, ProgressBar progressBar, CheckBox stem) {
    return e -> {
      Alert a;
      if (selectedFiles != null) {
        controller.selectedFiles = new File[selectedFiles.size()];
        for (int i = 0; i < selectedFiles.size(); i++) {
          String filepath = selectedFiles.get(i).getAbsolutePath();
          if (lastUpload.contains(filepath)) {
            a = new Alert(Alert.AlertType.CONFIRMATION);
            a.setTitle("Are you sure?");
            a.setContentText(
                "You just uploaded " + filepath + ", are you sure you want to upload it again?");
            Optional<ButtonType> result = a.showAndWait();
            if (result.get() != ButtonType.OK) {
              return;
            }
          }
          if (selectedFiles.get(i).isAbsolute() && selectedFiles.get(i).exists()) {
            controller.selectedFiles[i] = selectedFiles.get(i);
          } else {
            a = new Alert(Alert.AlertType.INFORMATION, "Invalid path to file.", ButtonType.OK);
            a.setTitle("Information");
            a.showAndWait();
            return;
          }
        }
      } else {
        a = new Alert(Alert.AlertType.INFORMATION, "Please select a file.", ButtonType.OK);
        a.initStyle(StageStyle.UTILITY);
        a.setTitle("Information");
        a.showAndWait();
        return;
      }

      progressBar.setProgress(0);
      controller.writeLog("Uploading file(s)...");
      Button source = (Button) e.getSource();
      source.setDisable(true);

      SwingWorker<Boolean, Double> worker =
          new SwingWorker<Boolean, Double>() {
            @Override
            protected Boolean doInBackground() throws Exception {
              String[] key = new String[FXController.selectedFiles.length];
              publish(0.05);

              for (int i = 0; i < FXController.selectedFiles.length; i++) {
                key[i] = UUID.randomUUID().toString();
                FileUtils.uploadFile(FXController.selectedFiles[i], key[i], AESCTR.secretKey);
              }
              publish(0.4);

              Map<String, ArrayList<StringPair>> map =
                  SSE.EDBSetup(
                      FXController.selectedFiles, AESCTR.secretKey, key, stem.isSelected());
              publish(0.6);

              ObjectMapper mapper = new ObjectMapper();
              try {
                String json = mapper.writeValueAsString(map);
                publish(0.8);
                HttpUtil.HttpPost(json);
              } catch (JsonProcessingException e1) {
                e1.printStackTrace();
                return false;
              }

              publish(1.0);
              return true;
            }

            @Override
            protected void done() {
              Platform.runLater(
                  new TimerTask() {
                    @Override
                    public void run() {
                      Alert a;
                      try {
                        if (get()) {
                          controller.writeLog("Upload successful!");
                          a =
                              new Alert(
                                  Alert.AlertType.INFORMATION, "Upload successful!", ButtonType.OK);
                          a.setTitle("Success!");
                          a.showAndWait();
                          lastUpload.clear();
                          for (File f : FXController.selectedFiles) {
                            lastUpload.add(f.getAbsolutePath());
                          }
                        } else {
                          controller.writeLog("Upload failed!");
                          a = new Alert(Alert.AlertType.ERROR, "Upload failed!", ButtonType.OK);
                          a.setTitle("Error!");
                          a.showAndWait();
                        }
                      } catch (Exception ex) {
                        a = new Alert(Alert.AlertType.ERROR, "Upload error!", ButtonType.OK);
                        a.setTitle("Error!");
                        a.showAndWait();
                        ex.printStackTrace();
                      }
                      source.setDisable(false);
                    }
                  });
            }

            @Override
            protected void process(List<Double> n) {
              progressBar.setProgress(n.get(n.size() - 1));
            }
          };

      worker.execute();
    };
  }