Beispiel #1
0
 public String getPrefix(int index) {
   String prefix = "";
   if (keepSortOrder() && Utils.getConfigBoolean("download.save_order", true)) {
     prefix = String.format("%03d_", index);
   }
   return prefix;
 }
Beispiel #2
0
 private void ripVideos() throws IOException {
   String oid = getGID(this.url).replace("videos", "");
   String u = "http://vk.com/al_video.php";
   Map<String, String> postData = new HashMap<String, String>();
   postData.put("al", "1");
   postData.put("act", "load_videos_silent");
   postData.put("offset", "0");
   postData.put("oid", oid);
   Document doc = Http.url(u).referrer(this.url).ignoreContentType().data(postData).post();
   String[] jsonStrings = doc.toString().split("<!>");
   JSONObject json = new JSONObject(jsonStrings[jsonStrings.length - 1]);
   JSONArray videos = json.getJSONArray("all");
   logger.info("Found " + videos.length() + " videos");
   for (int i = 0; i < videos.length(); i++) {
     JSONArray jsonVideo = videos.getJSONArray(i);
     int vidid = jsonVideo.getInt(1);
     String videoURL =
         com.rarchives.ripme.ripper.rippers.video.VkRipper.getVideoURLAtPage(
             "http://vk.com/video" + oid + "_" + vidid);
     String prefix = "";
     if (Utils.getConfigBoolean("download.save_order", true)) {
       prefix = String.format("%03d_", i + 1);
     }
     addURLToDownload(new URL(videoURL), prefix);
     try {
       Thread.sleep(500);
     } catch (InterruptedException e) {
       logger.error("Interrupted while waiting to fetch next video URL", e);
       break;
     }
   }
   waitForThreads();
 }
Beispiel #3
0
  private void handleEvent(StatusEvent evt) {
    RipStatusMessage msg = evt.msg;

    int completedPercent = evt.ripper.getCompletionPercentage();
    statusProgress.setValue(completedPercent);
    status(evt.ripper.getStatusText());

    switch (msg.getStatus()) {
      case LOADING_RESOURCE:
      case DOWNLOAD_STARTED:
        appendLog("Downloading: " + (String) msg.getObject(), Color.BLACK);
        break;
      case DOWNLOAD_COMPLETE:
        appendLog("Completed: " + (String) msg.getObject(), Color.GREEN);
        break;
      case DOWNLOAD_ERRORED:
        appendLog("Error: " + (String) msg.getObject(), Color.RED);
        break;

      case DOWNLOAD_WARN:
        appendLog("Warn: " + (String) msg.getObject(), Color.ORANGE);
        break;

      case RIP_COMPLETE:
        if (!historyListModel.contains(ripTextfield.getText())) {
          historyListModel.addElement(ripTextfield.getText());
        }
        saveHistory();
        ripButton.setEnabled(true);
        ripTextfield.setEnabled(true);
        statusProgress.setValue(100);
        statusLabel.setVisible(false);
        openButton.setVisible(true);
        File f = (File) msg.getObject();
        String prettyFile = Utils.removeCWD(f);
        openButton.setText("Open " + prettyFile);
        appendLog("Rip complete, saved to " + prettyFile, Color.GREEN);
        openButton.setActionCommand(f.toString());
        openButton.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent event) {
                try {
                  Desktop.getDesktop().open(new File(event.getActionCommand()));
                } catch (Exception e) {
                  logger.error(e);
                }
              }
            });
        mainFrame.pack();
    }
  }
Beispiel #4
0
  public static void main(String[] args) throws MalformedURLException {
    Utils.configureLogger();
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "RipMe");
    logger = Logger.getLogger(App.class);
    logger.info("Initialized ripme v" + UpdateUtils.getThisJarVersion());

    if (args.length > 0) {
      handleArguments(args);
    } else {
      MainWindow mw = new MainWindow();
      SwingUtilities.invokeLater(mw);
    }
  }
Beispiel #5
0
 @Override
 public void rip() throws IOException {
   logger.info("    Retrieving " + this.url);
   String jsonString =
       Jsoup.connect(this.url.toExternalForm())
           .ignoreContentType(true)
           .timeout(TIMEOUT)
           .execute()
           .body();
   JSONObject json = new JSONObject(jsonString);
   JSONArray posts = json.getJSONArray("posts");
   if (posts.length() == 0) {
     logger.error("No posts found at " + this.url);
     sendUpdate(STATUS.DOWNLOAD_ERRORED, "No posts found at " + this.url);
     throw new IOException("No posts found at this URL");
   }
   for (int i = 0; i < posts.length(); i++) {
     JSONObject post = (JSONObject) posts.get(i);
     String theUrl = post.getString("url");
     if (theUrl.contains("imgur.com/a/")) {
       ImgurAlbum album = null;
       try {
         album = ImgurRipper.getImgurAlbum(new URL(theUrl));
       } catch (IOException e) {
         logger.error("Error loading imgur album " + theUrl, e);
         sendUpdate(STATUS.DOWNLOAD_ERRORED, "Can't download " + theUrl + " : " + e.getMessage());
         continue;
       }
       int albumIndex = 0;
       for (ImgurImage image : album.images) {
         albumIndex++;
         String saveAs = String.format("%s-", post.getString("hexid"));
         if (Utils.getConfigBoolean("download.save_order", true)) {
           saveAs += String.format("%03d_", albumIndex);
         }
         addURLToDownload(image.url, saveAs);
       }
     } else {
       theUrl = post.getString("imageurl");
       String saveAs = String.format("%s-", post.getString("hexid"));
       addURLToDownload(new URL(theUrl), saveAs);
     }
   }
   waitForThreads();
 }
Beispiel #6
0
 @Override
 public String getGID(URL url) throws MalformedURLException {
   String u = url.toExternalForm();
   String searchTerm = u.substring(u.indexOf("?") + 1);
   return Utils.filesystemSafe(searchTerm);
 }
Beispiel #7
0
 public static void handleArguments(String[] args) {
   CommandLine cl = getArgs(args);
   if (cl.hasOption('h')) {
     HelpFormatter hf = new HelpFormatter();
     hf.printHelp("java -jar ripme.jar [OPTIONS]", getOptions());
     System.exit(0);
   }
   if (cl.hasOption('w')) {
     Utils.setConfigBoolean("file.overwrite", true);
   }
   if (cl.hasOption('t')) {
     Utils.setConfigInteger("threads.size", Integer.parseInt(cl.getOptionValue('t')));
   }
   if (cl.hasOption('4')) {
     Utils.setConfigBoolean("errors.skip404", true);
   }
   if (cl.hasOption('r')) {
     // Re-rip all via command-line
     List<String> history = Utils.getConfigList("download.history");
     for (String urlString : history) {
       try {
         URL url = new URL(urlString.trim());
         rip(url);
       } catch (Exception e) {
         logger.error("[!] Failed to rip URL " + urlString, e);
         continue;
       }
       try {
         Thread.sleep(500);
       } catch (InterruptedException e) {
         logger.warn("[!] Interrupted while re-ripping history");
         System.exit(-1);
       }
     }
     // Exit
     System.exit(0);
   }
   if (cl.hasOption('u')) {
     // User provided URL, rip it.
     try {
       URL url = new URL(cl.getOptionValue('u').trim());
       rip(url);
       List<String> history = Utils.getConfigList("download.history");
       if (!history.contains(url.toExternalForm())) {
         history.add(url.toExternalForm());
         Utils.setConfigList("download.history", Arrays.asList(history.toArray()));
         Utils.saveConfig();
       }
     } catch (MalformedURLException e) {
       logger.error("[!] Given URL is not valid. Expected URL format is http://domain.com/...");
       System.exit(-1);
     } catch (Exception e) {
       logger.error("[!] Error while ripping URL " + cl.getOptionValue('u'), e);
       System.exit(-1);
     }
   }
   if (!cl.hasOption('u')) {
     System.err.println("\nRequired URL ('-u' or '--url') not provided");
     System.err.println("\n\tExample: java -jar ripme.jar -u http://imgur.com/a/abcde");
     System.exit(-1);
   }
 }