Ported the SpankBangRipper to AbstractSingleFileRipper

This commit is contained in:
cyian-1756 2018-09-25 04:05:02 -04:00
parent 5bcf3b4a18
commit c50b1539d3
2 changed files with 34 additions and 19 deletions

View File

@ -1,18 +1,21 @@
package com.rarchives.ripme.ripper.rippers.video; package com.rarchives.ripme.ripper.rippers;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.rarchives.ripme.ripper.AbstractSingleFileRipper;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.VideoRipper; import com.rarchives.ripme.ripper.VideoRipper;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
public class SpankbangRipper extends VideoRipper { public class SpankbangRipper extends AbstractSingleFileRipper {
private static final String HOST = "spankbang"; private static final String HOST = "spankbang";
@ -20,6 +23,29 @@ public class SpankbangRipper extends VideoRipper {
super(url); super(url);
} }
@Override
public String getDomain() {
return "spankbang.com";
}
@Override
public Document getFirstPage() throws IOException {
return Http.url(url).get();
}
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<>();
Elements videos = doc.select(".video-js > source");
if (videos.isEmpty()) {
LOGGER.error("Could not find Embed code at " + url);
return null;
}
result.add(videos.attr("src"));
return result;
}
@Override @Override
public String getHost() { public String getHost() {
return HOST; return HOST;
@ -52,15 +78,7 @@ public class SpankbangRipper extends VideoRipper {
} }
@Override @Override
public void rip() throws IOException { public void downloadURL(URL url, int index) {
LOGGER.info("Retrieving " + this.url); addURLToDownload(url, getPrefix(index));
Document doc = Http.url(url).get();
Elements videos = doc.select(".video-js > source");
if (videos.isEmpty()) {
throw new IOException("Could not find Embed code at " + url);
}
String vidUrl = videos.attr("src");
addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url));
waitForThreads();
} }
} }

View File

@ -3,16 +3,13 @@ package com.rarchives.ripme.tst.ripper.rippers;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import com.rarchives.ripme.ripper.rippers.video.SpankbangRipper; import com.rarchives.ripme.ripper.rippers.SpankbangRipper;
import com.rarchives.ripme.utils.Utils;
public class SpankBangRipperTest extends RippersTest { public class SpankBangRipperTest extends RippersTest {
public void testSpankBangVideo() throws IOException { public void testSpankBangVideo() throws IOException {
// This test fails on the CI so we skip it unless running locally SpankbangRipper ripper = new SpankbangRipper(new URL("https://spankbang.com/2a7fh/video/mdb901")); //most popular video of all time on site; should stay up
if (Utils.getConfigBoolean("test.run_flaky_tests", false)) { testRipper(ripper);
SpankbangRipper ripper = new SpankbangRipper(new URL("https://spankbang.com/2a7fh/video/mdb901")); //most popular video of all time on site; should stay up
testRipper(ripper);
}
} }
} }