ImgScroll/src/main/java/com/rarchives/ripme/ripper/rippers/FineboxRipper.java

92 lines
2.9 KiB
Java
Raw Normal View History

2014-03-08 11:38:52 +01:00
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.jsoup.HttpStatusException;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Http;
2014-10-15 14:02:36 +02:00
import org.jsoup.select.Elements;
2014-03-08 11:38:52 +01:00
2014-10-15 14:02:36 +02:00
public class FineboxRipper extends AlbumRipper {
2014-03-08 11:38:52 +01:00
2014-10-15 14:02:36 +02:00
private static final String DOMAIN = "finebox.co",
DOMAIN_OLD = "vinebox.co",
HOST = "finebox";
2014-03-08 11:38:52 +01:00
2014-10-15 14:02:36 +02:00
public FineboxRipper(URL url) throws IOException {
2014-03-08 11:38:52 +01:00
super(url);
}
@Override
public boolean canRip(URL url) {
2014-10-15 14:02:36 +02:00
return url.getHost().endsWith(DOMAIN) || url.getHost().endsWith(DOMAIN_OLD);
2014-03-08 11:38:52 +01:00
}
@Override
public URL sanitizeURL(URL url) throws MalformedURLException {
2014-10-15 14:02:36 +02:00
return new URL("http://"+DOMAIN+"/u/" + getGID(url));
2014-03-08 11:38:52 +01:00
}
@Override
public void rip() throws IOException {
int page = 0;
Document doc;
2014-10-15 14:02:36 +02:00
Boolean hasPagesLeft = true;
while (hasPagesLeft) {
2014-03-08 11:38:52 +01:00
page++;
String urlPaged = this.url.toExternalForm() + "?page=" + page;
logger.info("Retrieving " + urlPaged);
sendUpdate(STATUS.LOADING_RESOURCE, urlPaged);
2014-03-08 11:38:52 +01:00
try {
doc = Http.url(this.url).get();
2014-03-08 11:38:52 +01:00
} catch (HttpStatusException e) {
logger.debug("Hit end of pages at page " + page, e);
break;
}
2014-10-15 14:02:36 +02:00
Elements videos = doc.select("video");
for (Element element : videos) {
2015-03-30 10:36:15 +02:00
String videourl = element.select("source").attr("src");
if (!videourl.startsWith("http")) {
videourl = "http://" + DOMAIN + videourl;
2014-10-15 14:02:36 +02:00
}
2015-03-30 10:36:15 +02:00
logger.info("URL to download: " + videourl);
if (!addURLToDownload(new URL(videourl))) {
2014-10-15 14:02:36 +02:00
hasPagesLeft = false;
break;
}
}
2014-03-08 11:38:52 +01:00
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 {
2014-10-15 14:02:36 +02:00
Pattern p = Pattern.compile("^https?://(www\\.)?(v|f)inebox\\.co/u/([a-zA-Z0-9]{1,}).*$");
2014-03-08 11:38:52 +01:00
Matcher m = p.matcher(url.toExternalForm());
if (!m.matches()) {
2014-10-15 14:02:36 +02:00
throw new MalformedURLException("Expected format: http://"+DOMAIN+"/u/USERNAME");
2014-03-08 11:38:52 +01:00
}
return m.group(m.groupCount());
}
}