Added vine video ripper #18
This commit is contained in:
parent
67e947a0e5
commit
65f014319e
@ -0,0 +1,71 @@
|
||||
package com.rarchives.ripme.ripper.rippers.video;
|
||||
|
||||
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.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import com.rarchives.ripme.ripper.VideoRipper;
|
||||
|
||||
public class VineRipper extends VideoRipper {
|
||||
|
||||
private static final String HOST = "vine";
|
||||
private static final Logger logger = Logger.getLogger(VineRipper.class);
|
||||
|
||||
public VineRipper(URL url) throws IOException {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return HOST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRip(URL url) {
|
||||
// https://vine.co/v/hiqQrP0eUZx
|
||||
Pattern p = Pattern.compile("^https?://[wm.]*vine\\.co/v/[a-zA-Z0-9]+.*$");
|
||||
Matcher m = p.matcher(url.toExternalForm());
|
||||
return m.matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL sanitizeURL(URL url) throws MalformedURLException {
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGID(URL url) throws MalformedURLException {
|
||||
Pattern p = Pattern.compile("^https?://[wm.]*vine\\.co/v/([a-zA-Z0-9]+).*$");
|
||||
Matcher m = p.matcher(url.toExternalForm());
|
||||
if (m.matches()) {
|
||||
return m.group(1);
|
||||
}
|
||||
|
||||
throw new MalformedURLException(
|
||||
"Expected vine format:"
|
||||
+ "vine.co/v/####"
|
||||
+ " Got: " + url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rip() throws IOException {
|
||||
logger.info(" Retrieving " + this.url.toExternalForm());
|
||||
Document doc = Jsoup.connect(this.url.toExternalForm())
|
||||
.userAgent(USER_AGENT)
|
||||
.get();
|
||||
Elements props = doc.select("meta[property=twitter:player:stream]");
|
||||
if (props.size() == 0) {
|
||||
throw new IOException("Could not find meta property 'twitter:player:stream' at " + url);
|
||||
}
|
||||
String vidUrl = props.get(0).attr("content");
|
||||
addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url));
|
||||
waitForThreads();
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.rarchives.ripme.ripper.rippers.video.PornhubRipper;
|
||||
import com.rarchives.ripme.ripper.rippers.video.VineRipper;
|
||||
import com.rarchives.ripme.ripper.rippers.video.XvideosRipper;
|
||||
|
||||
public class VideoRippersTest extends RippersTest {
|
||||
@ -49,4 +50,23 @@ public class VideoRippersTest extends RippersTest {
|
||||
}
|
||||
}
|
||||
|
||||
public void testVineRipper() throws IOException {
|
||||
if (!DOWNLOAD_CONTENT) {
|
||||
return;
|
||||
}
|
||||
List<URL> contentURLs = new ArrayList<URL>();
|
||||
contentURLs.add(new URL("https://vine.co/v/hiqQrP0eUZx"));
|
||||
for (URL url : contentURLs) {
|
||||
try {
|
||||
VineRipper ripper = new VineRipper(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user