-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/main/java/com/rarchives/ripme/ripper/rippers/VineboxRipper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/rarchives/ripme/tst/ripper/rippers/VineboxRipperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} | ||
|
||
} |