GfycatRipper now uses AbstractHTMLRipper

This commit is contained in:
cyian-1756 2018-06-26 02:28:14 -04:00
parent 9b70350b33
commit e1635f39e1
2 changed files with 66 additions and 11 deletions

View File

@ -1,18 +1,23 @@
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.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Utils;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.VideoRipper;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
public class GfycatRipper extends VideoRipper {
public class GfycatRipper extends AbstractHTMLRipper {
private static final String HOST = "gfycat.com"; private static final String HOST = "gfycat.com";
@ -20,9 +25,14 @@ public class GfycatRipper extends VideoRipper {
super(url); super(url);
} }
@Override
public String getDomain() {
return "gfycat.com";
}
@Override @Override
public String getHost() { public String getHost() {
return HOST; return "gfycat";
} }
@Override @Override
@ -37,6 +47,16 @@ public class GfycatRipper extends VideoRipper {
return url; 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 @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://[wm.]*gfycat\\.com/([a-zA-Z0-9]+).*$"); Pattern p = Pattern.compile("^https?://[wm.]*gfycat\\.com/([a-zA-Z0-9]+).*$");
@ -52,10 +72,15 @@ public class GfycatRipper extends VideoRipper {
} }
@Override @Override
public void rip() throws IOException { public List<String> getURLsFromPage(Document doc) {
String vidUrl = getVideoURL(this.url); List<String> result = new ArrayList<>();
addURLToDownload(new URL(vidUrl), "gfycat_" + getGID(this.url)); Elements videos = doc.select("source#mp4Source");
waitForThreads(); String vidUrl = videos.first().attr("src");
if (vidUrl.startsWith("//")) {
vidUrl = "http:" + vidUrl;
}
result.add(vidUrl);
return result;
} }
/** /**
@ -81,4 +106,34 @@ public class GfycatRipper extends VideoRipper {
} }
return vidUrl; 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;}
} }

View File

@ -12,7 +12,7 @@ import com.rarchives.ripme.ripper.rippers.EroShareRipper;
import com.rarchives.ripme.ripper.rippers.EromeRipper; import com.rarchives.ripme.ripper.rippers.EromeRipper;
import com.rarchives.ripme.ripper.rippers.ImgurRipper; import com.rarchives.ripme.ripper.rippers.ImgurRipper;
import com.rarchives.ripme.ripper.rippers.VidbleRipper; 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.commons.lang.math.NumberUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;