|
| 1 | +package com.rarchives.ripme.ripper.rippers; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.net.MalformedURLException; |
| 5 | +import java.net.URL; |
| 6 | +import java.util.regex.Matcher; |
| 7 | +import java.util.regex.Pattern; |
| 8 | + |
| 9 | +import org.apache.log4j.Logger; |
| 10 | +import org.jsoup.HttpStatusException; |
| 11 | +import org.jsoup.Jsoup; |
| 12 | +import org.jsoup.nodes.Document; |
| 13 | +import org.jsoup.nodes.Element; |
| 14 | + |
| 15 | +import com.rarchives.ripme.ripper.AbstractRipper; |
| 16 | + |
| 17 | +public class VineboxRipper extends AbstractRipper { |
| 18 | + |
| 19 | + private static final String DOMAIN = "vinebox.co", |
| 20 | + HOST = "vinebox"; |
| 21 | + private static final Logger logger = Logger.getLogger(VineboxRipper.class); |
| 22 | + |
| 23 | + public VineboxRipper(URL url) throws IOException { |
| 24 | + super(url); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public boolean canRip(URL url) { |
| 29 | + return url.getHost().endsWith(DOMAIN); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public URL sanitizeURL(URL url) throws MalformedURLException { |
| 34 | + Pattern p = Pattern.compile("^https?://(www\\.)?vinebox\\.co/u/([a-zA-Z0-9]{1,}).*$"); |
| 35 | + Matcher m = p.matcher(url.toExternalForm()); |
| 36 | + if (!m.matches()) { |
| 37 | + throw new MalformedURLException("Expected format: http://vinebox.co/u/USERNAME"); |
| 38 | + } |
| 39 | + return new URL("http://vinebox.co/u/" + m.group(m.groupCount())); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public void rip() throws IOException { |
| 44 | + int page = 0; |
| 45 | + Document doc; |
| 46 | + while (true) { |
| 47 | + page++; |
| 48 | + String urlPaged = this.url.toExternalForm() + "?page=" + page; |
| 49 | + logger.info("[ ] Retrieving " + urlPaged); |
| 50 | + try { |
| 51 | + doc = Jsoup.connect(urlPaged).get(); |
| 52 | + } catch (HttpStatusException e) { |
| 53 | + logger.debug("Hit end of pages at page " + page, e); |
| 54 | + break; |
| 55 | + } |
| 56 | + for (Element element : doc.select("video")) { |
| 57 | + addURLToDownload(new URL(element.attr("src"))); |
| 58 | + } |
| 59 | + try { |
| 60 | + Thread.sleep(1000); |
| 61 | + } catch (InterruptedException e) { |
| 62 | + logger.error("[!] Interrupted while waiting to load next page", e); |
| 63 | + break; |
| 64 | + } |
| 65 | + } |
| 66 | + waitForThreads(); |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public String getHost() { |
| 71 | + return HOST; |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public String getGID(URL url) throws MalformedURLException { |
| 76 | + Pattern p = Pattern.compile("^https?://(www\\.)?vinebox\\.co/u/([a-zA-Z0-9]{1,}).*$"); |
| 77 | + System.err.println(url); |
| 78 | + Matcher m = p.matcher(url.toExternalForm()); |
| 79 | + if (!m.matches()) { |
| 80 | + throw new MalformedURLException("Expected format: http://vinebox.co/u/USERNAME"); |
| 81 | + } |
| 82 | + return m.group(m.groupCount()); |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments