forked from RipMeApp/ripme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RipMeApp#1827 from PaaaulZ/cyberdrop-ripper
Added support for Cyberdrop.me
- Loading branch information
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/main/java/com/rarchives/ripme/ripper/rippers/CyberdropRipper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/com/rarchives/ripme/tst/ripper/rippers/CyberdropRipperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
|
||
} |