2015-03-09 21:08:06 +01: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.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
|
|
|
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
|
|
|
import com.rarchives.ripme.utils.Http;
|
|
|
|
|
|
|
|
public class NatalieMuRipper extends AbstractHTMLRipper {
|
2017-05-10 00:22:55 +02:00
|
|
|
|
2015-03-09 21:08:06 +01:00
|
|
|
public int news_id = 0;
|
2017-05-10 00:22:55 +02:00
|
|
|
|
2015-03-09 21:08:06 +01:00
|
|
|
public NatalieMuRipper(URL url) throws IOException {
|
2017-05-10 00:22:55 +02:00
|
|
|
super(url);
|
2015-03-09 21:08:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
String host = this.url.getHost();
|
|
|
|
host = host.substring(0, host.lastIndexOf('.'));
|
|
|
|
if (host.contains(".")) {
|
|
|
|
// Host has subdomain (www)
|
|
|
|
host = host.substring(host.lastIndexOf('.') + 1);
|
|
|
|
}
|
|
|
|
String board = this.url.toExternalForm().split("/")[3];
|
|
|
|
return host + "_" + board;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-10 00:22:55 +02:00
|
|
|
public boolean canRip(URL url) {
|
2015-03-09 21:08:06 +01:00
|
|
|
//urls like:
|
|
|
|
// http://cdn2.natalie.mu/music/gallery/show/news_id/xxxxxx/image_id/xxxxxx
|
|
|
|
// http://cdn2.natalie.mu/music/news/140411
|
|
|
|
return url.toExternalForm().contains("natalie.mu") // Most chans
|
2017-05-10 00:22:55 +02:00
|
|
|
&& (url.toExternalForm().contains("/news_id/")
|
2015-03-09 21:08:06 +01:00
|
|
|
|| url.toExternalForm().contains("/news/")); // 4chan, archive.moe
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For example the achrives are all known. (Check 4chan-x)
|
|
|
|
* Should be based on the software the specific chan uses.
|
|
|
|
* FoolFuuka uses the same (url) layout as 4chan
|
|
|
|
* */
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
|
|
|
Pattern p; Matcher m;
|
|
|
|
|
|
|
|
String u = url.toExternalForm();
|
|
|
|
if (u.contains("/news_id/")) {
|
|
|
|
p = Pattern.compile("/news_id/([0-9]+)/");
|
|
|
|
m = p.matcher(u);
|
|
|
|
if (m.find()) {
|
|
|
|
return m.group(1);
|
2017-05-10 00:22:55 +02:00
|
|
|
}
|
2015-03-09 21:08:06 +01:00
|
|
|
} else if (u.contains("/news/")) {
|
|
|
|
p = Pattern.compile("/news/([0-9]+)/?");
|
|
|
|
m = p.matcher(u);
|
|
|
|
if (m.find()) {
|
|
|
|
return m.group(1);
|
2017-05-10 00:22:55 +02:00
|
|
|
}
|
2015-03-09 21:08:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new MalformedURLException(
|
|
|
|
"Expected natalie.mu URL formats: "
|
|
|
|
+ "http://natalie.mu/music/news/xxxxxx or http://natalie.mu/music/gallery/show/news_id/xxxxxx/image_id/yyyyyy"
|
|
|
|
+ " Got: " + u);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDomain() {
|
|
|
|
return this.url.getHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Document getFirstPage() throws IOException {
|
|
|
|
return Http.url(this.url).get();
|
|
|
|
}
|
2017-05-10 00:22:55 +02:00
|
|
|
|
2015-03-09 21:08:06 +01:00
|
|
|
@Override
|
|
|
|
public List<String> getURLsFromPage(Document page) {
|
|
|
|
List<String> imageURLs = new ArrayList<String>();
|
|
|
|
Pattern p; Matcher m;
|
|
|
|
//select all album thumbnails
|
|
|
|
for (Element span : page.select(".NA_articleGallery span")) {
|
2017-05-10 00:22:55 +02:00
|
|
|
if (!span.hasAttr("style")) {
|
2015-03-09 21:08:06 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String style = span.attr("style").trim();
|
2017-05-10 00:22:55 +02:00
|
|
|
|
2015-03-09 21:08:06 +01:00
|
|
|
p = Pattern.compile("background-image: url\\((.*list_thumb_inbox.*)\\);", Pattern.CASE_INSENSITIVE);
|
|
|
|
m = p.matcher(style);
|
|
|
|
if (m.find()) {
|
|
|
|
String imgUrl = m.group(1);
|
|
|
|
if (imgUrl.startsWith("//")) {
|
|
|
|
imgUrl = "http:" + imgUrl;
|
|
|
|
}
|
|
|
|
if (imgUrl.startsWith("/")) {
|
|
|
|
imgUrl = "http://" + this.url.getHost() + imgUrl;
|
|
|
|
}
|
|
|
|
//convert thumbnail url into fullsize url
|
|
|
|
imgUrl = imgUrl.replace("list_thumb_inbox","xlarge");
|
|
|
|
// Don't download the same URL twice
|
|
|
|
if (imageURLs.contains(imgUrl)) {
|
|
|
|
logger.debug("Already attempted: " + imgUrl);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
imageURLs.add(imgUrl);
|
|
|
|
if (isThisATest()) {
|
|
|
|
break;
|
|
|
|
}
|
2017-05-10 00:22:55 +02:00
|
|
|
}
|
2015-03-09 21:08:06 +01:00
|
|
|
|
|
|
|
if (isStopped()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return imageURLs;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
addURLToDownload(url, getPrefix(index), "", this.url.toString(), null);
|
2017-05-10 00:22:55 +02:00
|
|
|
}
|
2015-03-09 21:08:06 +01:00
|
|
|
}
|