ImgScroll/src/main/java/com/rarchives/ripme/ripper/rippers/EroShareRipper.java

240 lines
7.8 KiB
Java
Raw Normal View History

2016-04-17 20:50:40 +02:00
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.rarchives.ripme.ripper.rippers;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
2016-04-17 20:50:40 +02:00
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Connection.Response;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.jsoup.Connection.Method;
2016-04-17 20:50:40 +02:00
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
2016-04-17 20:50:40 +02:00
import com.rarchives.ripme.utils.Http;
/**
*
* @author losipher
*/
public class EroShareRipper extends AbstractHTMLRipper {
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
public EroShareRipper (URL url) throws IOException {
super(url);
}
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
@Override
public String getDomain() {
return "eroshare.com";
}
@Override
public String getHost() {
return "eroshare";
}
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
@Override
2017-06-19 19:32:57 +02:00
public void downloadURL(URL url, int index) {
2016-04-17 20:50:40 +02:00
addURLToDownload(url);
}
@Override
public boolean canRip(URL url) {
2017-08-09 23:01:10 +02:00
Pattern p = Pattern.compile("^https?://eroshae.com/([a-zA-Z0-9\\-_]+)/?$");
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return true;
}
2017-08-09 23:01:10 +02:00
Pattern pa = Pattern.compile("^https?://eroshae.com/u/([a-zA-Z0-9\\-_]+)/?$");
Matcher ma = pa.matcher(url.toExternalForm());
if (ma.matches()) {
return true;
}
2017-07-30 03:51:41 +02:00
Pattern p_eroshare = Pattern.compile("^https?://eroshare.com/([a-zA-Z0-9\\-_]+)/?$");
Matcher m_eroshare = p_eroshare.matcher(url.toExternalForm());
if (m_eroshare.matches()) {
return true;
}
Pattern p_eroshare_profile = Pattern.compile("^https?://eroshare.com/u/([a-zA-Z0-9\\-_]+)/?$");
Matcher m_eroshare_profile = p_eroshare_profile.matcher(url.toExternalForm());
if (m_eroshare_profile.matches()) {
return true;
}
return false;
}
public boolean is_profile(URL url) {
2017-08-09 23:01:10 +02:00
Pattern pa = Pattern.compile("^https?://eroshae.com/u/([a-zA-Z0-9\\-_]+)/?$");
Matcher ma = pa.matcher(url.toExternalForm());
if (ma.matches()) {
return true;
}
return false;
}
@Override
public Document getNextPage(Document doc) throws IOException {
// Find next page
String nextUrl = "";
Element elem = doc.select("li.next > a").first();
if (elem == null) {
throw new IOException("No more pages");
}
nextUrl = elem.attr("href");
if (nextUrl == "") {
throw new IOException("No more pages");
}
2017-08-09 23:01:10 +02:00
return Http.url("eroshae.com" + nextUrl).get();
}
2017-03-20 00:50:29 +01:00
@Override
public String getAlbumTitle(URL url) throws MalformedURLException {
if (is_profile(url) == false) {
try {
// Attempt to use album title as GID
Element titleElement = getFirstPage().select("meta[property=og:title]").first();
String title = titleElement.attr("content");
title = title.substring(title.lastIndexOf('/') + 1);
return getHost() + "_" + getGID(url) + "_" + title.trim();
} catch (IOException e) {
// Fall back to default album naming convention
logger.info("Unable to find title at " + url);
}
return super.getAlbumTitle(url);
2017-03-20 00:50:29 +01:00
}
return url.toExternalForm().split("/u/")[1];
2017-03-20 00:50:29 +01:00
}
2016-04-17 20:50:40 +02:00
@Override
2017-06-19 19:32:57 +02:00
public List<String> getURLsFromPage(Document doc) {
2016-04-17 20:50:40 +02:00
List<String> URLs = new ArrayList<String>();
//Pictures
Elements imgs = doc.getElementsByTag("img");
2017-06-19 19:32:57 +02:00
for (Element img : imgs) {
if (img.hasClass("album-image")) {
2016-04-17 20:50:40 +02:00
String imageURL = img.attr("src");
imageURL = "https:" + imageURL;
URLs.add(imageURL);
}
}
//Videos
Elements vids = doc.getElementsByTag("video");
2017-06-19 19:32:57 +02:00
for (Element vid : vids) {
if (vid.hasClass("album-video")) {
2016-04-17 20:50:40 +02:00
Elements source = vid.getElementsByTag("source");
String videoURL = source.first().attr("src");
URLs.add("https:" + videoURL);
2016-04-17 20:50:40 +02:00
}
}
// Profile videos
Elements links = doc.select("div.item-container > a.item");
2017-06-19 19:32:57 +02:00
for (Element link : links) {
Document video_page;
try {
2017-08-09 23:01:10 +02:00
video_page = Http.url("eroshae.com" + link.attr("href")).get();
2017-06-19 19:32:57 +02:00
} catch (IOException e) {
logger.warn("Failed to log link in Jsoup");
video_page = null;
e.printStackTrace();
}
Elements profile_vids = video_page.getElementsByTag("video");
2017-06-19 19:32:57 +02:00
for (Element vid : profile_vids) {
if (vid.hasClass("album-video")) {
Elements source = vid.getElementsByTag("source");
String videoURL = source.first().attr("src");
URLs.add("https:" + videoURL);
}
}
}
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
return URLs;
}
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
@Override
public Document getFirstPage() throws IOException {
2017-07-30 03:51:41 +02:00
String urlToDownload = this.url.toExternalForm();
2017-08-09 23:01:10 +02:00
Response resp = Http.url(urlToDownload.replace("eroshare.com", "eroshae.com"))
2016-04-17 20:50:40 +02:00
.ignoreContentType()
.response();
Document doc = resp.parse();
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
return doc;
}
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
@Override
public String getGID(URL url) throws MalformedURLException {
2017-08-09 23:01:10 +02:00
Pattern p = Pattern.compile("^https?://eroshae.com/([a-zA-Z0-9\\-_]+)/?$");
2016-04-17 20:50:40 +02:00
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);
}
2017-07-30 03:51:41 +02:00
Pattern p_eroshare = Pattern.compile("^https?://eroshare.com/([a-zA-Z0-9\\-_]+)/?$");
Matcher m_eroshare = p_eroshare.matcher(url.toExternalForm());
if (m_eroshare.matches()) {
return m_eroshare.group(1);
}
Pattern p_eroshare_profile = Pattern.compile("^https?://eroshare.com/u/([a-zA-Z0-9\\-_]+)/?$");
Matcher m_eroshare_profile = p_eroshare_profile.matcher(url.toExternalForm());
if (m_eroshare_profile.matches()) {
return m_eroshare_profile.group(1) + "_profile";
}
2017-08-09 23:01:10 +02:00
Pattern pa = Pattern.compile("^https?://eroshae.com/u/([a-zA-Z0-9\\-_]+)/?$");
Matcher ma = pa.matcher(url.toExternalForm());
if (ma.matches()) {
return m.group(1) + "_profile";
}
2017-08-09 23:01:10 +02:00
throw new MalformedURLException("eroshare album not found in " + url + ", expected https://eroshare.com/album or eroshae.com/album");
2016-04-17 20:50:40 +02:00
}
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
public static List<URL> getURLs(URL url) throws IOException{
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
Response resp = Http.url(url)
.ignoreContentType()
.response();
Document doc = resp.parse();
List<URL> URLs = new ArrayList<URL>();
//Pictures
Elements imgs = doc.getElementsByTag("img");
2017-06-19 19:32:57 +02:00
for (Element img : imgs) {
if (img.hasClass("album-image")) {
2016-04-17 20:50:40 +02:00
String imageURL = img.attr("src");
imageURL = "https:" + imageURL;
URLs.add(new URL(imageURL));
}
}
//Videos
Elements vids = doc.getElementsByTag("video");
2017-06-19 19:32:57 +02:00
for (Element vid : vids) {
if (vid.hasClass("album-video")) {
2016-04-17 20:50:40 +02:00
Elements source = vid.getElementsByTag("source");
String videoURL = source.first().attr("src");
URLs.add(new URL("https:" + videoURL));
2016-04-17 20:50:40 +02:00
}
}
2017-03-20 00:50:29 +01:00
2016-04-17 20:50:40 +02:00
return URLs;
}
}