Skip to content

Commit

Permalink
Merge pull request RipMeApp#1827 from PaaaulZ/cyberdrop-ripper
Browse files Browse the repository at this point in the history
Added support for Cyberdrop.me
  • Loading branch information
cyian-1756 authored May 10, 2021
2 parents d823b79 + 0f83a2a commit 3c4e303
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.rarchives.ripme.ripper.rippers;

import java.io.IOException;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Http;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class CyberdropRipper extends AbstractHTMLRipper {

public CyberdropRipper(URL url) throws IOException {
super(url);
}

@Override
public String getHost() {
return "cyberdrop";
}

@Override
protected Document getFirstPage() throws IOException {
return Http.url(url).get();
}

@Override
public String getDomain() {
return "cyberdrop.me";
}

@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://cyberdrop\\.me/a/([a-zA-Z0-9]+).*?$");
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);
}
throw new MalformedURLException("Expected cyberdrop.me URL format: " +
"https://cyberdrop.me/a/xxxxxxxx - got " + url + "instead");
}

@Override
public void downloadURL(URL url, int index) {
addURLToDownload(url, getPrefix(index));
}

@Override
protected List<String> getURLsFromPage(Document page) {
ArrayList<String> urls = new ArrayList<>();
for (Element element: page.getElementsByClass("image")) {
urls.add(element.attr("href"));
}
return urls;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.rarchives.ripme.tst.ripper.rippers;

import com.rarchives.ripme.ripper.rippers.CyberdropRipper;
import com.rarchives.ripme.utils.Http;
import org.jsoup.nodes.Document;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CyberdropRipperTest extends RippersTest {
@Test
public void testScrolllerGID() throws IOException {
Map<URL, String> testURLs = new HashMap<>();

testURLs.put(new URL("https://cyberdrop.me/a/n4umdBjw"), "n4umdBjw");
testURLs.put(new URL("https://cyberdrop.me/a/iLtp4BjW"), "iLtp4BjW");
for (URL url : testURLs.keySet()) {
CyberdropRipper ripper = new CyberdropRipper(url);
ripper.setup();
Assertions.assertEquals(testURLs.get(url), ripper.getGID(ripper.getURL()));
deleteDir(ripper.getWorkingDir());
}
}

@Test
public void testCyberdropNumberOfFiles() throws IOException {
List<URL> testURLs = new ArrayList<URL>();

testURLs.add(new URL("https://cyberdrop.me/a/n4umdBjw"));
testURLs.add(new URL("https://cyberdrop.me/a/iLtp4BjW"));
for (URL url : testURLs) {
Assertions.assertTrue(willDownloadAllFiles(url));
}
}

public boolean willDownloadAllFiles(URL url) throws IOException {
Document doc = Http.url(url).get();
long numberOfLinks = doc.getElementsByClass("image").stream().count();
int numberOfFiles = Integer.parseInt(doc.getElementById("totalFilesAmount").text());
return numberOfLinks == numberOfFiles;
}



}

0 comments on commit 3c4e303

Please sign in to comment.