commit
c957422d8d
@ -0,0 +1,80 @@
|
||||
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.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
|
||||
import com.rarchives.ripme.ripper.VideoRipper;
|
||||
import com.rarchives.ripme.utils.Http;
|
||||
|
||||
public class TwitchVideoRipper extends VideoRipper {
|
||||
|
||||
private static final String HOST = "twitch";
|
||||
|
||||
public TwitchVideoRipper(URL url) throws IOException {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return HOST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRip(URL url) {
|
||||
Pattern p = Pattern.compile("^https://clips\\.twitch\\.tv/.*$");
|
||||
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://clips\\.twitch\\.tv/(.*)$");
|
||||
Matcher m = p.matcher(url.toExternalForm());
|
||||
if (m.matches()) {
|
||||
return m.group(m.groupCount());
|
||||
}
|
||||
|
||||
throw new MalformedURLException(
|
||||
"Expected Twitch.tv format:"
|
||||
+ "https://clips.twitch.tv/####"
|
||||
+ " Got: " + url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rip() throws IOException {
|
||||
logger.info("Retrieving " + this.url);
|
||||
Document doc = Http.url(url).get();
|
||||
|
||||
//Get user friendly filename from page title
|
||||
String title = doc.title();
|
||||
|
||||
Elements script = doc.select("script");
|
||||
if (script.size() == 0) {
|
||||
throw new IOException("Could not find script code at " + url);
|
||||
}
|
||||
//Regex assumes highest quality source is listed first
|
||||
Pattern p = Pattern.compile("\"source\":\"(.*?)\"");
|
||||
|
||||
for (Element element : script) {
|
||||
Matcher m = p.matcher(element.data());
|
||||
if (m.find()){
|
||||
String vidUrl = m.group(1);
|
||||
addURLToDownload(new URL(vidUrl), HOST + "_" + title);
|
||||
}
|
||||
}
|
||||
waitForThreads();
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
|
||||
import com.rarchives.ripme.ripper.VideoRipper;
|
||||
import com.rarchives.ripme.ripper.rippers.video.PornhubRipper;
|
||||
import com.rarchives.ripme.ripper.rippers.video.TwitchVideoRipper;
|
||||
import com.rarchives.ripme.ripper.rippers.video.VineRipper;
|
||||
import com.rarchives.ripme.ripper.rippers.video.XhamsterRipper;
|
||||
import com.rarchives.ripme.ripper.rippers.video.XvideosRipper;
|
||||
@ -37,6 +38,15 @@ public class VideoRippersTest extends RippersTest {
|
||||
}
|
||||
}
|
||||
|
||||
public void testTwitchVideoRipper() throws IOException {
|
||||
List<URL> contentURLs = new ArrayList<>();
|
||||
contentURLs.add(new URL("https://clips.twitch.tv/FaithfulIncredulousPotTBCheesePull"));
|
||||
for (URL url : contentURLs) {
|
||||
TwitchVideoRipper ripper = new TwitchVideoRipper(url);
|
||||
videoTestHelper(ripper);
|
||||
}
|
||||
}
|
||||
|
||||
public void testXhamsterRipper() throws IOException {
|
||||
List<URL> contentURLs = new ArrayList<>();
|
||||
contentURLs.add(new URL("https://xhamster.com/videos/brazzers-busty-big-booty-milf-lisa-ann-fucks-her-masseur-1492828"));
|
||||
|
Loading…
Reference in New Issue
Block a user