Reddit ripper can now rip videos from v.redd.it

This commit is contained in:
cyian-1756 2018-06-15 22:23:29 -04:00
parent 6cae35ccfb
commit c2938af568
2 changed files with 38 additions and 0 deletions

View File

@ -17,6 +17,10 @@ import com.rarchives.ripme.ui.UpdateUtils;
import com.rarchives.ripme.utils.Http;
import com.rarchives.ripme.utils.RipUtils;
import com.rarchives.ripme.utils.Utils;
import org.jsoup.Jsoup;
import javax.swing.text.Document;
import javax.swing.text.Element;
public class RedditRipper extends AlbumRipper {
@ -179,6 +183,32 @@ public class RedditRipper extends AlbumRipper {
}
}
private URL parseRedditVideoMPD(String vidURL) {
org.jsoup.nodes.Document doc = null;
try {
doc = Http.url(vidURL + "/DASHPlaylist.mpd").ignoreContentType().get();
int largestHeight = 0;
String baseURL = null;
// Loops over all the videos and finds the one with the largest height and sets baseURL to the base url of that video
for (org.jsoup.nodes.Element e : doc.select("MPD > Period > AdaptationSet > Representation")) {
String height = e.attr("height");
if (height.equals("")) {
height = "0";
}
if (largestHeight < Integer.parseInt(height)) {
largestHeight = Integer.parseInt(height);
baseURL = doc.select("MPD > Period > AdaptationSet > Representation[height=" + height + "]").select("BaseURL").text();
}
LOGGER.info("H " + e.attr("height") + " V " + e.attr("width"));
}
return new URL(vidURL + "/" + baseURL);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private void handleURL(String theUrl, String id) {
URL originalURL;
try {
@ -198,6 +228,11 @@ public class RedditRipper extends AlbumRipper {
savePath += id + "-" + m.group(1) + ".jpg";
addURLToDownload(urls.get(0), new File(savePath));
}
if (url.contains("v.redd.it")) {
String savePath = this.workingDir + File.separator;
savePath += id + "-" + url.split("/")[3] + ".mp4";
addURLToDownload(parseRedditVideoMPD(urls.get(0).toExternalForm()), new File(savePath));
}
else {
addURLToDownload(urls.get(0), id + "-", "", theUrl, null);
}

View File

@ -86,6 +86,9 @@ public class RipUtils {
logger.warn("Exception while retrieving eroshare page:", e);
}
return result;
} else if (url.toExternalForm().contains("v.redd.it")) {
result.add(url);
return result;
}
else if (url.toExternalForm().contains("erome.com")) {