Merge branch 'master' into xhamsterFixes

This commit is contained in:
cyian-1756 2018-10-06 08:10:11 -05:00 committed by GitHub
commit 181ce934b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 9 deletions

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) {
@ -126,14 +146,17 @@ public class XhamsterRipper extends AbstractHTMLRipper {
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
LOGGER.debug("Checking for urls"); LOGGER.debug("Checking for urls");
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
for (Element page : doc.select("div.items > div.item-container > a.item")) { if (!isVideoUrl(url)) {
String pageWithImageUrl = page.attr("href"); for (Element page : doc.select("div.items > div.item-container > a.item")) {
try { String pageWithImageUrl = page.attr("href");
String image = Http.url(new URL(pageWithImageUrl)).get().select("div.picture_container > a > img").attr("src"); try {
result.add(image); String image = Http.url(new URL(pageWithImageUrl)).get().select("div.picture_container > a > img").attr("src");
} catch (IOException e) { result.add(image);
LOGGER.error("Was unable to load page " + pageWithImageUrl); } catch (IOException e) {
} LOGGER.error("Was unable to load page " + pageWithImageUrl);
}
} else {
result.add(doc.select("div.player-container > a").attr("href"));
} }
return result; return result;
} }

View File

@ -18,6 +18,11 @@ public class XhamsterRipperTest extends RippersTest {
testRipper(ripper); testRipper(ripper);
} }
public void testXhamsterVideo() throws IOException {
XhamsterRipper ripper = new XhamsterRipper(new URL("https://xhamster.com/videos/brazzers-busty-big-booty-milf-lisa-ann-fucks-her-masseur-1492828"));
testRipper(ripper);
}
public void testBrazilianXhamster() throws IOException { public void testBrazilianXhamster() throws IOException {
XhamsterRipper ripper = new XhamsterRipper(new URL("https://pt.xhamster.com/photos/gallery/silvana-7105696")); XhamsterRipper ripper = new XhamsterRipper(new URL("https://pt.xhamster.com/photos/gallery/silvana-7105696"));
testRipper(ripper); testRipper(ripper);