Skip to content

Commit

Permalink
Fix XvideosRipper: update URL pattern to match current URL scheme. (#…
Browse files Browse the repository at this point in the history
…2054)

* Fix XvideosRipper: update URL pattern to match current URL scheme. Also, extract patterns to be compiled once in static members to avoid repeating the match patterns and make the code read a little more clearly. Improve album name for the video case.
  • Loading branch information
metaprime authored Jan 2, 2025
1 parent 7be6f82 commit 2621a27
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
40 changes: 25 additions & 15 deletions src/main/java/com/rarchives/ripme/ripper/rippers/XvideosRipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;


import com.rarchives.ripme.ripper.AbstractSingleFileRipper;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.rarchives.ripme.utils.Http;

public class XvideosRipper extends AbstractSingleFileRipper {

private static final String HOST = "xvideos";

private static final Pattern videoPattern = Pattern.compile("^https?://[wm.]*xvideos\\.com/video\\.([^/]*)(.*)$");
private static final Pattern albumPattern = Pattern.compile("^https?://[wm.]*xvideos\\.com/(profiles|amateurs)/([a-zA-Z0-9_-]+)/photos/(\\d+)/([a-zA-Z0-9_-]+)$");

public XvideosRipper(URL url) throws IOException {
super(url);
}
Expand All @@ -37,12 +38,12 @@ public String getDomain() {

@Override
public boolean canRip(URL url) {
Pattern p = Pattern.compile("^https?://[wm.]*xvideos\\.com/video[0-9]+.*$");
Pattern p = videoPattern;
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return true;
}
p = Pattern.compile("^https?://[wm.]*xvideos\\.com/profiles/[a-zA-Z0-9_-]+/photos/\\d+/[a-zA-Z0-9_-]+$");
p = albumPattern;
m = p.matcher(url.toExternalForm());
if (m.matches()) {
return true;
Expand All @@ -52,15 +53,15 @@ public boolean canRip(URL url) {

@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://[wm.]*xvideos\\.com/video([0-9]+).*$");
Pattern p = videoPattern;
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);
}
p = Pattern.compile("^https?://[wm.]*xvideos\\.com/profiles/[a-zA-Z0-9_-]+/photos/(\\d+)/[a-zA-Z0-9_-]+$");
p = albumPattern;
m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);
return m.group(3);
}

throw new MalformedURLException(
Expand All @@ -72,7 +73,7 @@ public String getGID(URL url) throws MalformedURLException {
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> results = new ArrayList<>();
Pattern p = Pattern.compile("^https?://[wm.]*xvideos\\.com/video([0-9]+).*$");
Pattern p = videoPattern;
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
Elements scripts = doc.select("script");
Expand Down Expand Up @@ -106,12 +107,21 @@ public void downloadURL(URL url, int index) {

@Override
public String getAlbumTitle(URL url) throws MalformedURLException, URISyntaxException {
Pattern p = Pattern.compile("^https?://[wm.]*xvideos\\.com/profiles/([a-zA-Z0-9_-]+)/photos/(\\d+)/([a-zA-Z0-9_-]+)$");
Matcher m = p.matcher(url.toExternalForm());
Pattern p;
Matcher m;

p = videoPattern;
m = p.matcher(url.toExternalForm());
if (m.matches()) {
return getHost() + "_" + m.group(1) + "_" + m.group(3) + "_" + m.group(2);
} else {
return super.getAlbumTitle(url);
return getHost() + "_" + m.group(1) + "_" + m.group(2);
}

p = albumPattern;
m = p.matcher(url.toExternalForm());
if (m.matches()) {
return getHost() + "_" + m.group(1) + "_" + m.group(2) + "_" + m.group(4) + "_" + m.group(3);
}

return super.getAlbumTitle(url);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,29 @@

public class XvideosRipperTest extends RippersTest {
@Test
public void testXhamsterAlbum1() throws IOException, URISyntaxException {
XvideosRipper ripper = new XvideosRipper(new URI("https://www.xvideos.com/video23515878/dee_s_pool_toys").toURL());
public void testXvideosVideo1() throws IOException, URISyntaxException {
// This format is obsolete
// XvideosRipper ripper = new XvideosRipper(new URI("https://www.xvideos.com/video23515878/dee_s_pool_toys").toURL());
// The website now redirects that video to this page
XvideosRipper ripper = new XvideosRipper(new URI("https://www.xvideos.com/video.hppdiepcbfe/dee_s_pool_toys").toURL());
testRipper(ripper);
}

@Test
public void testXvideosVideo2() throws IOException, URISyntaxException {
XvideosRipper ripper = new XvideosRipper(new URI("https://www.xvideos.com/video.ufkmptkc4ae/big_tit_step_sis_made_me_cum_inside_her").toURL());
testRipper(ripper);
}

@Test
public void testXvideosAmateursAlbum() throws IOException, URISyntaxException {
XvideosRipper ripper = new XvideosRipper(new URI("https://www.xvideos.com/amateurs/nikibeee/photos/2476083/lanikki").toURL());
testRipper(ripper);
}

@Test
public void testXvideosProfilesAlbum() throws IOException, URISyntaxException {
XvideosRipper ripper = new XvideosRipper(new URI("https://www.xvideos.com/profiles/dmthate/photos/8259625/sexy").toURL());
testRipper(ripper);
}
}

0 comments on commit 2621a27

Please sign in to comment.