2014-06-30 23:21:22 +02:00
|
|
|
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.List;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
|
|
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
|
|
|
import com.rarchives.ripme.utils.Http;
|
2014-07-02 07:48:02 +02:00
|
|
|
import com.rarchives.ripme.utils.Utils;
|
2014-06-30 23:21:22 +02:00
|
|
|
|
|
|
|
class TapasticEpisode {
|
2017-10-24 16:33:28 +02:00
|
|
|
int id;
|
|
|
|
String filename;
|
2014-06-30 23:21:22 +02:00
|
|
|
public TapasticEpisode(int index, int id, String title) {
|
2017-10-24 16:33:28 +02:00
|
|
|
int index1 = index;
|
2014-07-02 07:48:02 +02:00
|
|
|
this.id = id;
|
2017-10-24 16:33:28 +02:00
|
|
|
String title1 = title;
|
2014-07-02 07:48:02 +02:00
|
|
|
this.filename = Utils.filesystemSafe(title);
|
2014-06-30 23:21:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TapasticRipper extends AbstractHTMLRipper {
|
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
private List<TapasticEpisode> episodes= new ArrayList<>();
|
2014-06-30 23:21:22 +02:00
|
|
|
|
|
|
|
public TapasticRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDomain() {
|
2017-11-23 06:51:37 +01:00
|
|
|
return "tapas.io";
|
2014-06-30 23:21:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() {
|
2017-11-23 06:51:37 +01:00
|
|
|
return "tapas";
|
2014-06-30 23:21:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Document getFirstPage() throws IOException {
|
|
|
|
return Http.url(url).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getURLsFromPage(Document page) {
|
2017-10-24 16:33:28 +02:00
|
|
|
List<String> urls = new ArrayList<>();
|
2014-07-02 07:48:02 +02:00
|
|
|
String html = page.data();
|
|
|
|
if (!html.contains("episodeList : ")) {
|
2018-06-03 03:14:41 +02:00
|
|
|
LOGGER.error("No 'episodeList' found at " + this.url);
|
2014-07-02 07:48:02 +02:00
|
|
|
return urls;
|
|
|
|
}
|
|
|
|
String jsonString = Utils.between(html, "episodeList : ", ",\n").get(0);
|
|
|
|
JSONArray json = new JSONArray(jsonString);
|
|
|
|
for (int i = 0; i < json.length(); i++) {
|
|
|
|
JSONObject obj = json.getJSONObject(i);
|
|
|
|
TapasticEpisode episode = new TapasticEpisode(i, obj.getInt("id"), obj.getString("title"));
|
|
|
|
episodes.add(episode);
|
|
|
|
urls.add("http://tapastic.com/episode/" + episode.id);
|
2014-06-30 23:21:22 +02:00
|
|
|
}
|
|
|
|
return urls;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
try {
|
2014-07-02 07:48:02 +02:00
|
|
|
Document doc = Http.url(url).get();
|
|
|
|
Elements images = doc.select("article.ep-contents img");
|
|
|
|
// Find maximum # of images for optimal filename indexing
|
|
|
|
int epiLog = (int) (Math.floor(Math.log10(episodes.size())) + 1),
|
|
|
|
imgLog = (int) (Math.floor(Math.log10(images.size() )) + 1);
|
|
|
|
for (int i = 0; i < images.size(); i++) {
|
|
|
|
String link = images.get(i).attr("src");
|
|
|
|
TapasticEpisode episode = episodes.get(index - 1);
|
|
|
|
// Build elaborate filename prefix
|
|
|
|
StringBuilder prefix = new StringBuilder();
|
|
|
|
prefix.append(String.format("ep%0" + epiLog + "d", index));
|
|
|
|
prefix.append(String.format("-%0" + imgLog + "dof%0" + imgLog + "d-", i + 1, images.size()));
|
|
|
|
prefix.append(episode.filename.replace(" ", "-"));
|
|
|
|
prefix.append("-");
|
|
|
|
addURLToDownload(new URL(link), prefix.toString());
|
2015-02-10 08:29:29 +01:00
|
|
|
if (isThisATest()) {
|
|
|
|
break;
|
|
|
|
}
|
2014-07-02 07:48:02 +02:00
|
|
|
}
|
2014-06-30 23:21:22 +02:00
|
|
|
} catch (IOException e) {
|
2018-06-03 03:14:41 +02:00
|
|
|
LOGGER.error("[!] Exception while downloading " + url, e);
|
2014-06-30 23:21:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
2017-11-23 06:51:37 +01:00
|
|
|
Pattern p = Pattern.compile("^https?://tapas.io/series/([^/?]+).*$");
|
2014-06-30 23:21:22 +02:00
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
2014-07-02 07:48:02 +02:00
|
|
|
return "series_ " + m.group(1);
|
|
|
|
}
|
2017-11-23 06:51:37 +01:00
|
|
|
p = Pattern.compile("^https?://tapas.io/episode/([^/?]+).*$");
|
2014-07-02 07:48:02 +02:00
|
|
|
m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return "ep_" + m.group(1);
|
2014-06-30 23:21:22 +02:00
|
|
|
}
|
|
|
|
throw new MalformedURLException("Expected tapastic.com URL format: "
|
2014-07-02 07:48:02 +02:00
|
|
|
+ "tapastic.com/[series|episode]/name - got " + url + " instead");
|
2014-06-30 23:21:22 +02:00
|
|
|
}
|
|
|
|
}
|