mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-24 06:23:52 +02:00
Merge pull request #1176 from buzzlightmonth/master
Fixed and cleaned up Pornhub video ripper
This commit is contained in:
@@ -8,6 +8,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
import com.rarchives.ripme.ripper.VideoRipper;
|
import com.rarchives.ripme.ripper.VideoRipper;
|
||||||
@@ -60,26 +61,24 @@ public class PornhubRipper extends VideoRipper {
|
|||||||
Pattern p = Pattern.compile("^.*flashvars_[0-9]+ = (.+});.*$", Pattern.DOTALL);
|
Pattern p = Pattern.compile("^.*flashvars_[0-9]+ = (.+});.*$", Pattern.DOTALL);
|
||||||
Matcher m = p.matcher(html);
|
Matcher m = p.matcher(html);
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
String title = null, vidUrl = null;
|
String vidUrl = null;
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(m.group(1));
|
JSONObject json = new JSONObject(m.group(1));
|
||||||
|
|
||||||
title = json.getString("video_title");
|
JSONArray mediaDef = (JSONArray) json.get("mediaDefinitions");
|
||||||
title = title.replaceAll("\\+", " ");
|
int bestQual = 0;
|
||||||
|
for (int i = 0; i < mediaDef.length(); i++) {
|
||||||
vidUrl = null;
|
JSONObject e = (JSONObject) mediaDef.get(i);
|
||||||
for (String quality : new String[] {"1080", "720", "480", "240"}) {
|
int quality = Integer.parseInt((String)e.get("quality"));
|
||||||
Pattern pv = Pattern.compile("\"format\":\"\",\"quality\":\"" + quality + "\",\"videoUrl\":\"(.*?)\"");
|
if (quality > bestQual) {
|
||||||
Matcher mv = pv.matcher(html);
|
bestQual = quality;
|
||||||
if (mv.find()) {
|
vidUrl = (String)e.get("videoUrl");
|
||||||
vidUrl = mv.group(1).replace("\\/", "/");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vidUrl == null) {
|
if (vidUrl == null) {
|
||||||
throw new IOException("Unable to find encrypted video URL at " + this.url);
|
throw new IOException("Unable to find encrypted video URL at " + this.url);
|
||||||
}
|
}
|
||||||
addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url));
|
addURLToDownload(new URL(vidUrl), HOST + "_" + bestQual + "p_" + getGID(this.url));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
LOGGER.error("Error while parsing JSON at " + url, e);
|
LOGGER.error("Error while parsing JSON at " + url, e);
|
||||||
throw e;
|
throw e;
|
||||||
@@ -94,3 +93,4 @@ public class PornhubRipper extends VideoRipper {
|
|||||||
waitForThreads();
|
waitForThreads();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user