Ported YoupornRipper to AbstractSingleFileRipper

This commit is contained in:
cyian-1756 2018-09-28 09:52:55 -04:00
parent 2a71a30b4f
commit a7dc1414e7
2 changed files with 45 additions and 17 deletions

View File

@ -1,11 +1,14 @@
package com.rarchives.ripme.ripper.rippers.video; package com.rarchives.ripme.ripper.rippers;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.rarchives.ripme.ripper.AbstractSingleFileRipper;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
@ -13,9 +16,8 @@ import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.VideoRipper; import com.rarchives.ripme.ripper.VideoRipper;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
public class YoupornRipper extends VideoRipper { public class YoupornRipper extends AbstractSingleFileRipper {
private static final String HOST = "youporn";
public YoupornRipper(URL url) throws IOException { public YoupornRipper(URL url) throws IOException {
super(url); super(url);
@ -23,7 +25,12 @@ public class YoupornRipper extends VideoRipper {
@Override @Override
public String getHost() { public String getHost() {
return HOST; return "youporn";
}
@Override
public String getDomain() {
return "youporn.com";
} }
@Override @Override
@ -34,10 +41,21 @@ public class YoupornRipper extends VideoRipper {
} }
@Override @Override
public URL sanitizeURL(URL url) throws MalformedURLException { public Document getFirstPage() throws IOException {
return url; return Http.url(this.url).get();
} }
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> results = new ArrayList<>();
Elements videos = doc.select("video");
Element video = videos.get(0);
results.add(video.attr("src"));
return results;
}
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://[wm.]*youporn\\.com/watch/([0-9]+).*$"); Pattern p = Pattern.compile("^https?://[wm.]*youporn\\.com/watch/([0-9]+).*$");
@ -53,16 +71,7 @@ public class YoupornRipper extends VideoRipper {
} }
@Override @Override
public void rip() throws IOException { public void downloadURL(URL url, int index) {
LOGGER.info(" Retrieving " + this.url); addURLToDownload(url, getPrefix(index));
Document doc = Http.url(this.url).get();
Elements videos = doc.select("video");
if (videos.isEmpty()) {
throw new IOException("Could not find Embed code at " + url);
}
Element video = videos.get(0);
String vidUrl = video.attr("src");
addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url));
waitForThreads();
} }
} }

View File

@ -0,0 +1,19 @@
package com.rarchives.ripme.tst.ripper.rippers;
import com.rarchives.ripme.ripper.rippers.YoupornRipper;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class YoupornRipperTest extends RippersTest {
public void testYoupornRipper() throws IOException {
List<URL> contentURLs = new ArrayList<>();
contentURLs.add(new URL("http://www.youporn.com/watch/7669155/mrs-li-amateur-69-orgasm/?from=categ"));
for (URL url : contentURLs) {
YoupornRipper ripper = new YoupornRipper(url);
testRipper(ripper);
}
}
}