|
| 1 | +package com.rarchives.ripme.ripper.rippers; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.UnsupportedEncodingException; |
| 5 | +import java.net.MalformedURLException; |
| 6 | +import java.net.URL; |
| 7 | +import java.net.URLDecoder; |
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.List; |
| 10 | +import java.util.regex.Matcher; |
| 11 | +import java.util.regex.Pattern; |
| 12 | + |
| 13 | +import org.jsoup.nodes.Document; |
| 14 | + |
| 15 | +import com.rarchives.ripme.ripper.AbstractHTMLRipper; |
| 16 | +import com.rarchives.ripme.utils.Http; |
| 17 | +import com.rarchives.ripme.utils.Utils; |
| 18 | + |
| 19 | +public class FuskatorRipper extends AbstractHTMLRipper { |
| 20 | + |
| 21 | + public FuskatorRipper(URL url) throws IOException { |
| 22 | + super(url); |
| 23 | + } |
| 24 | + |
| 25 | + @Override |
| 26 | + public String getHost() { |
| 27 | + return "fuskator"; |
| 28 | + } |
| 29 | + @Override |
| 30 | + public String getDomain() { |
| 31 | + return "fuskator.com"; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public URL sanitizeURL(URL url) throws MalformedURLException { |
| 36 | + String u = url.toExternalForm(); |
| 37 | + if (u.contains("/thumbs/")) { |
| 38 | + u = u.replace("/thumbs/", "/full/"); |
| 39 | + } |
| 40 | + return new URL(u); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public String getGID(URL url) throws MalformedURLException { |
| 45 | + Pattern p = Pattern.compile("^.*fuskator.com/full/([a-zA-Z0-9\\-]+).*$"); |
| 46 | + Matcher m = p.matcher(url.toExternalForm()); |
| 47 | + if (m.matches()) { |
| 48 | + return m.group(1); |
| 49 | + } |
| 50 | + throw new MalformedURLException( |
| 51 | + "Expected fuskator.com gallery formats: " |
| 52 | + + "fuskator.com/full/id/..." |
| 53 | + + " Got: " + url); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public Document getFirstPage() throws IOException { |
| 58 | + return Http.url(url).get(); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public List<String> getURLsFromPage(Document doc) { |
| 63 | + List<String> imageURLs = new ArrayList<String>(); |
| 64 | + String html = doc.html(); |
| 65 | + // Get "baseUrl" |
| 66 | + String baseUrl = Utils.between(html, "var baseUrl = unescape('", "'").get(0); |
| 67 | + try { |
| 68 | + baseUrl = URLDecoder.decode(baseUrl, "UTF-8"); |
| 69 | + } catch (UnsupportedEncodingException e) { |
| 70 | + logger.warn("Error while decoding " + baseUrl, e); |
| 71 | + } |
| 72 | + if (baseUrl.startsWith("//")) { |
| 73 | + baseUrl = "http:" + baseUrl; |
| 74 | + } |
| 75 | + // Iterate over images |
| 76 | + for (String filename : Utils.between(html, ".src=baseUrl+'", "'")) { |
| 77 | + imageURLs.add(baseUrl + filename); |
| 78 | + } |
| 79 | + return imageURLs; |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public void downloadURL(URL url, int index) { |
| 84 | + addURLToDownload(url, getPrefix(index)); |
| 85 | + } |
| 86 | +} |
0 commit comments