Vinebox ripper

This commit is contained in:
4pr0n 2014-03-08 02:38:52 -08:00
parent 7c63f3a492
commit 8bfae563d2
2 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,85 @@
package com.rarchives.ripme.ripper.rippers;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import org.jsoup.HttpStatusException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AbstractRipper;
public class VineboxRipper extends AbstractRipper {
private static final String DOMAIN = "vinebox.co",
HOST = "vinebox";
private static final Logger logger = Logger.getLogger(VineboxRipper.class);
public VineboxRipper(URL url) throws IOException {
super(url);
}
@Override
public boolean canRip(URL url) {
return url.getHost().endsWith(DOMAIN);
}
@Override
public URL sanitizeURL(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://(www\\.)?vinebox\\.co/u/([a-zA-Z0-9]{1,}).*$");
Matcher m = p.matcher(url.toExternalForm());
if (!m.matches()) {
throw new MalformedURLException("Expected format: http://vinebox.co/u/USERNAME");
}
return new URL("http://vinebox.co/u/" + m.group(m.groupCount()));
}
@Override
public void rip() throws IOException {
int page = 0;
Document doc;
while (true) {
page++;
String urlPaged = this.url.toExternalForm() + "?page=" + page;
logger.info("[ ] Retrieving " + urlPaged);
try {
doc = Jsoup.connect(urlPaged).get();
} catch (HttpStatusException e) {
logger.debug("Hit end of pages at page " + page, e);
break;
}
for (Element element : doc.select("video")) {
addURLToDownload(new URL(element.attr("src")));
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.error("[!] Interrupted while waiting to load next page", e);
break;
}
}
waitForThreads();
}
@Override
public String getHost() {
return HOST;
}
@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://(www\\.)?vinebox\\.co/u/([a-zA-Z0-9]{1,}).*$");
System.err.println(url);
Matcher m = p.matcher(url.toExternalForm());
if (!m.matches()) {
throw new MalformedURLException("Expected format: http://vinebox.co/u/USERNAME");
}
return m.group(m.groupCount());
}
}

View File

@ -0,0 +1,31 @@
package com.rarchives.ripme.tst.ripper.rippers;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import com.rarchives.ripme.ripper.rippers.VineboxRipper;
public class VineboxRipperTest extends RippersTest {
public void testVineboxAlbums() throws IOException {
if (false && !DOWNLOAD_CONTENT) {
return;
}
List<URL> contentURLs = new ArrayList<URL>();
contentURLs.add(new URL("http://vinebox.co/u/wiZS1MvkgEo"));
for (URL url : contentURLs) {
try {
VineboxRipper ripper = new VineboxRipper(url);
ripper.rip();
assert(ripper.getWorkingDir().listFiles().length > 1);
deleteDir(ripper.getWorkingDir());
} catch (Exception e) {
e.printStackTrace();
fail("Error while ripping URL " + url + ": " + e.getMessage());
}
}
}
}