From e1635f39e17476b1e02df150d0aac070b67b351e Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Tue, 26 Jun 2018 02:28:14 -0400 Subject: [PATCH] GfycatRipper now uses AbstractHTMLRipper --- .../rippers/{video => }/GfycatRipper.java | 75 ++++++++++++++++--- .../com/rarchives/ripme/utils/RipUtils.java | 2 +- 2 files changed, 66 insertions(+), 11 deletions(-) rename src/main/java/com/rarchives/ripme/ripper/rippers/{video => }/GfycatRipper.java (54%) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/video/GfycatRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/GfycatRipper.java similarity index 54% rename from src/main/java/com/rarchives/ripme/ripper/rippers/video/GfycatRipper.java rename to src/main/java/com/rarchives/ripme/ripper/rippers/GfycatRipper.java index 75577597..78a0af19 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/video/GfycatRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/GfycatRipper.java @@ -1,18 +1,23 @@ -package com.rarchives.ripme.ripper.rippers.video; +package com.rarchives.ripme.ripper.rippers; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +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.Utils; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; -import com.rarchives.ripme.ripper.VideoRipper; import com.rarchives.ripme.utils.Http; -public class GfycatRipper extends VideoRipper { + +public class GfycatRipper extends AbstractHTMLRipper { private static final String HOST = "gfycat.com"; @@ -20,9 +25,14 @@ public class GfycatRipper extends VideoRipper { super(url); } + @Override + public String getDomain() { + return "gfycat.com"; + } + @Override public String getHost() { - return HOST; + return "gfycat"; } @Override @@ -37,6 +47,16 @@ public class GfycatRipper extends VideoRipper { return url; } + @Override + public Document getFirstPage() throws IOException { + return Http.url(url).get(); + } + + @Override + public void downloadURL(URL url, int index) { + addURLToDownload(url, getPrefix(index)); + } + @Override public String getGID(URL url) throws MalformedURLException { Pattern p = Pattern.compile("^https?://[wm.]*gfycat\\.com/([a-zA-Z0-9]+).*$"); @@ -52,10 +72,15 @@ public class GfycatRipper extends VideoRipper { } @Override - public void rip() throws IOException { - String vidUrl = getVideoURL(this.url); - addURLToDownload(new URL(vidUrl), "gfycat_" + getGID(this.url)); - waitForThreads(); + public List getURLsFromPage(Document doc) { + List result = new ArrayList<>(); + Elements videos = doc.select("source#mp4Source"); + String vidUrl = videos.first().attr("src"); + if (vidUrl.startsWith("//")) { + vidUrl = "http:" + vidUrl; + } + result.add(vidUrl); + return result; } /** @@ -66,10 +91,10 @@ public class GfycatRipper extends VideoRipper { */ public static String getVideoURL(URL url) throws IOException { LOGGER.info("Retrieving " + url.toExternalForm()); - + //Sanitize the URL first url = new URL(url.toExternalForm().replace("/gifs/detail", "")); - + Document doc = Http.url(url).get(); Elements videos = doc.select("source#mp4Source"); if (videos.isEmpty()) { @@ -81,4 +106,34 @@ public class GfycatRipper extends VideoRipper { } return vidUrl; } + + private int bytesTotal = 1; + private int bytesCompleted = 1; + + @Override + public String getStatusText() { + return String.valueOf(getCompletionPercentage()) + + "% - " + + Utils.bytesToHumanReadable(bytesCompleted) + + " / " + + Utils.bytesToHumanReadable(bytesTotal); + } + + @Override + public int getCompletionPercentage() { + return (int) (100 * (bytesCompleted / (float) bytesTotal)); + } + + @Override + public void setBytesTotal(int bytes) { + this.bytesTotal = bytes; + } + + @Override + public void setBytesCompleted(int bytes) { + this.bytesCompleted = bytes; + } + + @Override + public boolean useByteProgessBar() {return true;} } \ No newline at end of file diff --git a/src/main/java/com/rarchives/ripme/utils/RipUtils.java b/src/main/java/com/rarchives/ripme/utils/RipUtils.java index 34081852..9845145c 100644 --- a/src/main/java/com/rarchives/ripme/utils/RipUtils.java +++ b/src/main/java/com/rarchives/ripme/utils/RipUtils.java @@ -12,7 +12,7 @@ import com.rarchives.ripme.ripper.rippers.EroShareRipper; import com.rarchives.ripme.ripper.rippers.EromeRipper; import com.rarchives.ripme.ripper.rippers.ImgurRipper; import com.rarchives.ripme.ripper.rippers.VidbleRipper; -import com.rarchives.ripme.ripper.rippers.video.GfycatRipper; +import com.rarchives.ripme.ripper.rippers.GfycatRipper; import org.apache.commons.lang.math.NumberUtils; import org.apache.log4j.Logger; import org.jsoup.Jsoup;