Added support for video downloading

This commit is contained in:
cyian-1756 2018-10-02 06:40:03 -04:00
parent 7e890bce2f
commit 2eadcd675e

View File

@ -43,6 +43,9 @@ public class XhamsterRipper extends AbstractHTMLRipper {
URLToReturn = URLToReturn.replaceAll("\\w\\w.xhamster.com", "xhamster.com"); URLToReturn = URLToReturn.replaceAll("\\w\\w.xhamster.com", "xhamster.com");
URL san_url = new URL(URLToReturn.replaceAll("xhamster.com", "m.xhamster.com")); URL san_url = new URL(URLToReturn.replaceAll("xhamster.com", "m.xhamster.com"));
LOGGER.info("sanitized URL is " + san_url.toExternalForm()); LOGGER.info("sanitized URL is " + san_url.toExternalForm());
if (isVideoUrl(url)) {
return url;
}
return san_url; return san_url;
} }
@ -58,7 +61,13 @@ public class XhamsterRipper extends AbstractHTMLRipper {
if (m.matches()) { if (m.matches()) {
return "user_" + m.group(1); return "user_" + m.group(1);
} }
throw new MalformedURLException( p = Pattern.compile("^https?://.*xhamster\\.com/(movies|videos)/(.*)$");
m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(2);
}
throw new MalformedURLException(
"Expected xhamster.com gallery formats: " "Expected xhamster.com gallery formats: "
+ "xhamster.com/photos/gallery/xxxxx-#####" + "xhamster.com/photos/gallery/xxxxx-#####"
+ " Got: " + url); + " Got: " + url);
@ -108,9 +117,20 @@ public class XhamsterRipper extends AbstractHTMLRipper {
if (m.matches()) { if (m.matches()) {
return true; return true;
} }
p = Pattern.compile("^https?://.*xhamster\\.com/(movies|videos)/.*$");
m = p.matcher(url.toExternalForm());
if (m.matches()) {
return true;
}
return false; return false;
} }
private boolean isVideoUrl(URL url) {
Pattern p = Pattern.compile("^https?://.*xhamster\\.com/(movies|videos)/.*$");
Matcher m = p.matcher(url.toExternalForm());
return m.matches();
}
@Override @Override
public Document getNextPage(Document doc) throws IOException { public Document getNextPage(Document doc) throws IOException {
if (doc.select("a[data-page=next]").first() != null) { if (doc.select("a[data-page=next]").first() != null) {
@ -125,19 +145,23 @@ public class XhamsterRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
for (Element thumb : doc.select("div.picture_view > div.pictures_block > div.items > div.item-container > a > div.thumb_container > div.img > img")) { if (!isVideoUrl(url)) {
String image = thumb.attr("src"); for (Element thumb : doc.select("div.picture_view > div.pictures_block > div.items > div.item-container > a > div.thumb_container > div.img > img")) {
// replace thumbnail urls with the urls to the full sized images String image = thumb.attr("src");
image = image.replaceAll( // replace thumbnail urls with the urls to the full sized images
"https://upt.xhcdn\\.", image = image.replaceAll(
"http://up.xhamster."); "https://upt.xhcdn\\.",
image = image.replaceAll("ept\\.xhcdn", "ep.xhamster"); "http://up.xhamster.");
image = image.replaceAll( image = image.replaceAll("ept\\.xhcdn", "ep.xhamster");
"_160\\.", image = image.replaceAll(
"_1000."); "_160\\.",
// Xhamster has bad cert management and uses invalid certs for some cdns, so we change all our requests to http "_1000.");
image = image.replaceAll("https", "http"); // Xhamster has bad cert management and uses invalid certs for some cdns, so we change all our requests to http
result.add(image); image = image.replaceAll("https", "http");
result.add(image);
}
} else {
result.add(doc.select("div.player-container > a").attr("href"));
} }
return result; return result;
} }