mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-26 15:24:51 +02:00
Fixed GfycatRipper not not ripping gifs.
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package com.rarchives.ripme.ripper.rippers;
|
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;
|
||||||
@@ -11,10 +10,11 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import com.rarchives.ripme.ripper.AbstractSingleFileRipper;
|
import com.rarchives.ripme.ripper.AbstractSingleFileRipper;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import com.rarchives.ripme.utils.Http;
|
import com.rarchives.ripme.utils.Http;
|
||||||
|
import com.rarchives.ripme.utils.Utils;
|
||||||
|
|
||||||
public class GfycatRipper extends AbstractSingleFileRipper {
|
public class GfycatRipper extends AbstractSingleFileRipper {
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ public class GfycatRipper extends AbstractSingleFileRipper {
|
|||||||
@Override
|
@Override
|
||||||
public URL sanitizeURL(URL url) throws MalformedURLException {
|
public URL sanitizeURL(URL url) throws MalformedURLException {
|
||||||
url = new URL(url.toExternalForm().replace("/gifs/detail", ""));
|
url = new URL(url.toExternalForm().replace("/gifs/detail", ""));
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,17 +64,23 @@ public class GfycatRipper extends AbstractSingleFileRipper {
|
|||||||
return m.group(1);
|
return m.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new MalformedURLException(
|
throw new MalformedURLException("Expected gfycat.com format:" + "gfycat.com/id" + " Got: " + url);
|
||||||
"Expected gfycat.com format:"
|
|
||||||
+ "gfycat.com/id"
|
|
||||||
+ " Got: " + url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getURLsFromPage(Document doc) {
|
public List<String> getURLsFromPage(Document doc) {
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
Elements videos = doc.select("source");
|
Elements videos = doc.select("video source");
|
||||||
String vidUrl = videos.first().attr("src");
|
String vidUrl = videos.first().attr("src");
|
||||||
|
// Check preference for mp4 over webm/gif.
|
||||||
|
if (Utils.getConfigBoolean("prefer.mp4", false)) {
|
||||||
|
for (Element e : videos) {
|
||||||
|
if (e.hasAttr("src") && e.attr("src").endsWith(".mp4")) {
|
||||||
|
vidUrl = e.attr("src");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (vidUrl.startsWith("//")) {
|
if (vidUrl.startsWith("//")) {
|
||||||
vidUrl = "http:" + vidUrl;
|
vidUrl = "http:" + vidUrl;
|
||||||
}
|
}
|
||||||
@@ -84,22 +90,33 @@ public class GfycatRipper extends AbstractSingleFileRipper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method for retrieving video URLs.
|
* Helper method for retrieving video URLs.
|
||||||
* @param url URL to gfycat page
|
*
|
||||||
|
* @param url
|
||||||
|
* URL to gfycat page
|
||||||
* @return URL to video
|
* @return URL to video
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static String getVideoURL(URL url) throws IOException {
|
public static String getVideoURL(URL url) throws IOException {
|
||||||
LOGGER.info("Retrieving " + url.toExternalForm());
|
LOGGER.info("Retrieving " + url.toExternalForm());
|
||||||
|
|
||||||
//Sanitize the URL first
|
// Sanitize the URL first
|
||||||
url = new URL(url.toExternalForm().replace("/gifs/detail", ""));
|
url = new URL(url.toExternalForm().replace("/gifs/detail", ""));
|
||||||
|
|
||||||
Document doc = Http.url(url).get();
|
Document doc = Http.url(url).get();
|
||||||
Elements videos = doc.select("source");
|
Elements videos = doc.select("video source");
|
||||||
if (videos.isEmpty()) {
|
if (videos.isEmpty()) {
|
||||||
throw new IOException("Could not find source at " + url);
|
throw new IOException("Could not find source at " + url);
|
||||||
}
|
}
|
||||||
String vidUrl = videos.first().attr("src");
|
String vidUrl = videos.first().attr("src");
|
||||||
|
// Check preference for mp4 over webm/gif.
|
||||||
|
if (Utils.getConfigBoolean("prefer.mp4", false)) {
|
||||||
|
for (Element e : videos) {
|
||||||
|
if (e.hasAttr("src") && e.attr("src").endsWith(".mp4")) {
|
||||||
|
vidUrl = e.attr("src");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (vidUrl.startsWith("//")) {
|
if (vidUrl.startsWith("//")) {
|
||||||
vidUrl = "http:" + vidUrl;
|
vidUrl = "http:" + vidUrl;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user