diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/video/BeegRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/video/BeegRipper.java new file mode 100644 index 00000000..d6be0d4c --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/video/BeegRipper.java @@ -0,0 +1,88 @@ +package com.rarchives.ripme.ripper.rippers.video; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.log4j.Logger; +import org.json.JSONException; +import org.json.JSONObject; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; + +import com.rarchives.ripme.ripper.VideoRipper; + +public class BeegRipper extends VideoRipper { + + private static final String HOST = "beeg"; + private static final Logger logger = Logger.getLogger(BeegRipper.class); + + public BeegRipper(URL url) throws IOException { + super(url); + } + + @Override + public String getHost() { + return HOST; + } + + @Override + public boolean canRip(URL url) { + Pattern p = Pattern.compile("^https?://[wm.]*beeg\\.com/[0-9]+.*$"); + Matcher m = p.matcher(url.toExternalForm()); + return m.matches(); + } + + @Override + public URL sanitizeURL(URL url) throws MalformedURLException { + return url; + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p = Pattern.compile("^https?://[wm.]*beeg\\.com/([0-9]+).*$"); + Matcher m = p.matcher(url.toExternalForm()); + if (m.matches()) { + return m.group(1); + } + + throw new MalformedURLException( + "Expected beeg format:" + + "beeg.com/####" + + " Got: " + url); + } + + @Override + public void rip() throws IOException { + logger.info(" Retrieving " + this.url.toExternalForm()); + Document doc = Jsoup.connect(this.url.toExternalForm()) + .userAgent(USER_AGENT) + .get(); + Pattern p = Pattern.compile("^.*var qualityArr = (.*});.*$", Pattern.DOTALL); + Matcher m = p.matcher(doc.html()); + if (m.matches()) { + try { + JSONObject json = new JSONObject(m.group(1)); + String vidUrl = null; + for (String quality : new String[] {"1080p", "720p", "480p", "240p"}) { + if (json.has(quality)) { + vidUrl = json.getString(quality); + break; + } + } + if (vidUrl == null) { + throw new IOException("Unable to find video URL at " + this.url); + } + addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url)); + waitForThreads(); + return; + } catch (JSONException e) { + logger.error("Error while parsing JSON at " + url, e); + throw e; + } + } + throw new IOException("Failed to rip video at " + this.url); + } +} \ No newline at end of file diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/video/YoupornRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/video/YoupornRipper.java new file mode 100644 index 00000000..d00ea84b --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/video/YoupornRipper.java @@ -0,0 +1,72 @@ +package com.rarchives.ripme.ripper.rippers.video; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.log4j.Logger; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import com.rarchives.ripme.ripper.VideoRipper; + +public class YoupornRipper extends VideoRipper { + + private static final String HOST = "youporn"; + private static final Logger logger = Logger.getLogger(YoupornRipper.class); + + public YoupornRipper(URL url) throws IOException { + super(url); + } + + @Override + public String getHost() { + return HOST; + } + + @Override + public boolean canRip(URL url) { + Pattern p = Pattern.compile("^https?://[wm.]*youporn\\.com/watch/[0-9]+.*$"); + Matcher m = p.matcher(url.toExternalForm()); + return m.matches(); + } + + @Override + public URL sanitizeURL(URL url) throws MalformedURLException { + return url; + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p = Pattern.compile("^https?://[wm.]*youporn\\.com/watch/([0-9]+).*$"); + Matcher m = p.matcher(url.toExternalForm()); + if (m.matches()) { + return m.group(1); + } + + throw new MalformedURLException( + "Expected youporn format:" + + "youporn.com/watch/####" + + " Got: " + url); + } + + @Override + public void rip() throws IOException { + logger.info(" Retrieving " + this.url.toExternalForm()); + Document doc = Jsoup.connect(this.url.toExternalForm()) + .userAgent(USER_AGENT) + .get(); + Elements videos = doc.select("video"); + if (videos.size() == 0) { + 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(); + } +} \ No newline at end of file diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/VideoRippersTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/VideoRippersTest.java index 996fe736..ddacaf6d 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/VideoRippersTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/VideoRippersTest.java @@ -5,9 +5,11 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import com.rarchives.ripme.ripper.rippers.video.BeegRipper; import com.rarchives.ripme.ripper.rippers.video.PornhubRipper; import com.rarchives.ripme.ripper.rippers.video.VineRipper; import com.rarchives.ripme.ripper.rippers.video.XvideosRipper; +import com.rarchives.ripme.ripper.rippers.video.YoupornRipper; public class VideoRippersTest extends RippersTest { @@ -69,4 +71,43 @@ public class VideoRippersTest extends RippersTest { } } + public void testYoupornRipper() throws IOException { + if (!DOWNLOAD_CONTENT) { + return; + } + List contentURLs = new ArrayList(); + contentURLs.add(new URL("http://www.youporn.com/watch/7669155/mrs-li-amateur-69-orgasm/?from=categ")); + for (URL url : contentURLs) { + try { + YoupornRipper ripper = new YoupornRipper(url); + ripper.rip(); + assert(ripper.getWorkingDir().listFiles().length > 1); + deleteDir(ripper.getWorkingDir()); + } catch (Exception e) { + e.printStackTrace(); + fail("Error while ripping URL " + url + ": " + e.getMessage()); + } + } + } + + public void testBeegRipper() throws IOException { + if (!DOWNLOAD_CONTENT) { + return; + } + List contentURLs = new ArrayList(); + contentURLs.add(new URL("http://beeg.com/4554321")); + for (URL url : contentURLs) { + try { + BeegRipper ripper = new BeegRipper(url); + ripper.rip(); + assert(ripper.getWorkingDir().listFiles().length > 1); + deleteDir(ripper.getWorkingDir()); + } catch (Exception e) { + e.printStackTrace(); + fail("Error while ripping URL " + url + ": " + e.getMessage()); + } + } + } + + }