2018-07-02 04:26:12 +02:00
|
|
|
package com.rarchives.ripme.ripper.rippers;
|
2014-04-20 07:41:11 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
2018-07-02 04:26:12 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-04-20 07:41:11 +02:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2018-07-02 04:26:12 +02:00
|
|
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
|
|
|
import com.rarchives.ripme.utils.Utils;
|
2014-04-20 07:41:11 +02:00
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
2014-06-22 02:08:42 +02:00
|
|
|
import com.rarchives.ripme.utils.Http;
|
2014-04-20 07:41:11 +02:00
|
|
|
|
2018-07-02 04:26:12 +02:00
|
|
|
public class XvideosRipper extends AbstractHTMLRipper {
|
2014-04-20 07:41:11 +02:00
|
|
|
|
|
|
|
private static final String HOST = "xvideos";
|
|
|
|
|
2018-07-02 04:26:12 +02:00
|
|
|
private int bytesTotal = 1;
|
|
|
|
private int bytesCompleted = 1;
|
|
|
|
|
2014-04-20 07:41:11 +02:00
|
|
|
public XvideosRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
2018-07-02 04:26:12 +02:00
|
|
|
@Override
|
|
|
|
public Document getFirstPage() throws IOException {
|
|
|
|
return Http.url(this.url).get();
|
|
|
|
}
|
|
|
|
|
2014-04-20 07:41:11 +02:00
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
return HOST;
|
|
|
|
}
|
|
|
|
|
2018-07-02 04:26:12 +02:00
|
|
|
@Override
|
|
|
|
public String getDomain() {
|
|
|
|
return HOST + ".com";
|
|
|
|
}
|
|
|
|
|
2014-04-20 07:41:11 +02:00
|
|
|
@Override
|
|
|
|
public boolean canRip(URL url) {
|
|
|
|
Pattern p = Pattern.compile("^https?://[wm.]*xvideos\\.com/video[0-9]+.*$");
|
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
return m.matches();
|
|
|
|
}
|
2017-05-10 00:22:55 +02:00
|
|
|
|
2014-04-20 07:41:11 +02:00
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
|
|
|
Pattern p = Pattern.compile("^https?://[wm.]*xvideos\\.com/video([0-9]+).*$");
|
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new MalformedURLException(
|
|
|
|
"Expected xvideo format:"
|
|
|
|
+ "xvideos.com/video####"
|
|
|
|
+ " Got: " + url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-02 04:26:12 +02:00
|
|
|
public List<String> getURLsFromPage(Document doc) {
|
|
|
|
List<String> results = new ArrayList<>();
|
2018-03-08 13:33:35 +01:00
|
|
|
Elements scripts = doc.select("script");
|
|
|
|
for (Element e : scripts) {
|
|
|
|
if (e.html().contains("html5player.setVideoUrlHigh")) {
|
2018-06-03 03:14:41 +02:00
|
|
|
LOGGER.info("Found the right script");
|
2018-03-08 13:33:35 +01:00
|
|
|
String[] lines = e.html().split("\n");
|
|
|
|
for (String line: lines) {
|
|
|
|
if (line.contains("html5player.setVideoUrlHigh")) {
|
|
|
|
String videoURL = line.replaceAll("\t", "").replaceAll("html5player.setVideoUrlHigh\\(", "").replaceAll("\'", "").replaceAll("\\);", "");
|
2018-07-02 04:26:12 +02:00
|
|
|
results.add(videoURL);
|
2018-03-08 13:33:35 +01:00
|
|
|
}
|
|
|
|
}
|
2014-04-20 07:41:11 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-02 04:26:12 +02:00
|
|
|
return results;
|
2014-04-20 07:41:11 +02:00
|
|
|
}
|
2018-07-02 04:26:12 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
addURLToDownload(url, getPrefix(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getStatusText() {
|
|
|
|
return Utils.getByteStatusText(getCompletionPercentage(), bytesCompleted, bytesTotal);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCompletionPercentage() {
|
|
|
|
return (int) (100 * (bytesCompleted / (float) bytesTotal));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setBytesTotal(int bytes) {
|
|
|
|
this.bytesTotal = bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setBytesCompleted(int bytes) {
|
|
|
|
this.bytesCompleted = bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean useByteProgessBar() {return true;}
|
2014-04-20 07:41:11 +02:00
|
|
|
}
|