From d593cdd9f6955368025ef6352603be2a571d54ce Mon Sep 17 00:00:00 2001 From: aaaaan Date: Thu, 1 Jan 2015 20:56:40 +0100 Subject: [PATCH] Added vid.me ripper Rips a video from vidme. Does not support ripping all videos of a user --- .../ripme/ripper/rippers/VidmeRipper.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/VidmeRipper.java diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/VidmeRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/VidmeRipper.java new file mode 100644 index 00000000..d1c669e4 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/VidmeRipper.java @@ -0,0 +1,66 @@ +package com.rarchives.ripme.ripper.rippers; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.LinkedList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.lang.StringEscapeUtils; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.rarchives.ripme.ripper.AbstractHTMLRipper; +import com.rarchives.ripme.utils.Http; + +public class VidmeRipper extends AbstractHTMLRipper { + + public VidmeRipper(URL url) throws IOException { + super(url); + } + + @Override + public String getDomain() { + return "vid.me"; + } + + @Override + public String getHost() { + return "vid"; + } + + @Override + public Document getFirstPage() throws IOException { + return Http.url(url).get(); + } + + @Override + public List getURLsFromPage(Document page) { + List result = new LinkedList<>(); + for(Element elem : page.select("a.js-download-video-link")){ + String link = StringEscapeUtils.unescapeHtml(elem.attr("data-href").toString()); + result.add(link); + } + return result; + } + + @Override + public void downloadURL(URL url, int index) { + addURLToDownload(url, getPrefix(index)); + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p = Pattern.compile("^https?://vid\\.me/([a-zA-Z0-9]+).*$"); + Matcher m = p.matcher(url.toExternalForm()); + if (m.matches()) { + // Return the text contained between () in the regex + return m.group(1); + } + throw new MalformedURLException("Expected imgur.com URL format: " + + "imgur.com/a/albumid - got " + url + " instead"); + } + +}