1+ package com .rarchives .ripme .ripper .rippers ;
2+
3+ import java .io .IOException ;
4+ import java .net .MalformedURLException ;
5+ import java .net .URL ;
6+ import java .util .regex .Matcher ;
7+ import java .util .regex .Pattern ;
8+
9+ import org .apache .log4j .Logger ;
10+ import org .jsoup .Jsoup ;
11+ import org .jsoup .nodes .Document ;
12+ import org .jsoup .nodes .Element ;
13+
14+ import com .rarchives .ripme .ripper .AlbumRipper ;
15+
16+ public class ButttoucherRipper extends AlbumRipper {
17+
18+ private static final String DOMAIN = "butttoucher.com" ,
19+ HOST = "butttoucher" ;
20+ private static final Logger logger = Logger .getLogger (ButttoucherRipper .class );
21+
22+ private Document albumDoc = null ;
23+
24+ public ButttoucherRipper (URL url ) throws IOException {
25+ super (url );
26+ }
27+
28+ @ Override
29+ public String getHost () {
30+ return HOST ;
31+ }
32+
33+ @ Override
34+ public String getGID (URL url ) throws MalformedURLException {
35+ Pattern p ; Matcher m ;
36+
37+ p = Pattern .compile ("^.*butttoucher.com/users/([a-zA-Z0-9_\\ -]{1,}).*$" );
38+ m = p .matcher (url .toExternalForm ());
39+ if (m .matches ()) {
40+ return m .group (1 );
41+ }
42+ throw new MalformedURLException (
43+ "Expected butttoucher.com gallery format: "
44+ + "butttoucher.com/users/<username>"
45+ + " Got: " + url );
46+ }
47+
48+ @ Override
49+ public void rip () throws IOException {
50+ logger .info (" Retrieving " + this .url .toExternalForm ());
51+ if (albumDoc == null ) {
52+ albumDoc = Jsoup .connect (this .url .toExternalForm ()).get ();
53+ }
54+ int index = 0 ;
55+ for (Element thumb : albumDoc .select ("div.image-gallery > a > img" )) {
56+ if (!thumb .hasAttr ("src" )) {
57+ continue ;
58+ }
59+ String smallImage = thumb .attr ("src" );
60+ String image = smallImage .replace ("m." , "." );
61+ index += 1 ;
62+ addURLToDownload (new URL (image ), String .format ("%03d_" , index ));
63+ }
64+ waitForThreads ();
65+ }
66+
67+ public boolean canRip (URL url ) {
68+ if (!url .getHost ().endsWith (DOMAIN )) {
69+ return false ;
70+ }
71+ return true ;
72+ }
73+
74+ @ Override
75+ public URL sanitizeURL (URL url ) throws MalformedURLException {
76+ return url ;
77+ }
78+
79+ }
0 commit comments