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 .jsoup .Jsoup ;
10
+ import org .jsoup .nodes .Document ;
11
+ import org .jsoup .nodes .Element ;
12
+ import org .jsoup .select .Elements ;
13
+
14
+ import com .rarchives .ripme .ripper .AlbumRipper ;
15
+ import com .rarchives .ripme .ripper .DownloadThreadPool ;
16
+ import com .rarchives .ripme .ui .RipStatusMessage .STATUS ;
17
+ import com .rarchives .ripme .utils .Utils ;
18
+
19
+ public class ImagevenueRipper extends AlbumRipper {
20
+
21
+ private static final int IMAGE_SLEEP_TIME = 0 ;
22
+
23
+ private static final String DOMAIN = "imagevenue.com" , HOST = "imagevenue" ;
24
+
25
+ // Thread pool for finding direct image links from "image" pages (html)
26
+ private DownloadThreadPool imagevenueThreadPool = new DownloadThreadPool ("imagevenue" );
27
+
28
+ public ImagevenueRipper (URL url ) throws IOException {
29
+ super (url );
30
+ }
31
+
32
+ @ Override
33
+ public String getHost () {
34
+ return HOST ;
35
+ }
36
+
37
+ public URL sanitizeURL (URL url ) throws MalformedURLException {
38
+ return url ;
39
+ }
40
+
41
+ @ Override
42
+ public String getGID (URL url ) throws MalformedURLException {
43
+ Pattern p ;
44
+ Matcher m ;
45
+
46
+ p = Pattern .compile ("^https?://.*imagevenue.com/galshow.php\\ ?gal=([a-zA-Z0-9\\ -_]+).*$" );
47
+ m = p .matcher (url .toExternalForm ());
48
+ if (m .matches ()) {
49
+ return m .group (1 );
50
+ }
51
+
52
+ throw new MalformedURLException (
53
+ "Expected imagevenue gallery format: "
54
+ + "http://...imagevenue.com/galshow.php?gal=gallery_...."
55
+ + " Got: " + url );
56
+ }
57
+
58
+ @ Override
59
+ public void rip () throws IOException {
60
+ int index = 0 ;
61
+ String nextUrl = this .url .toExternalForm ();
62
+ logger .info (" Retrieving album page " + nextUrl );
63
+ sendUpdate (STATUS .LOADING_RESOURCE , nextUrl );
64
+ Document albumDoc = Jsoup .connect (nextUrl )
65
+ .userAgent (USER_AGENT )
66
+ .timeout (5000 )
67
+ .referrer (this .url .toExternalForm ())
68
+ .get ();
69
+ // Find thumbnails
70
+ Elements thumbs = albumDoc .select ("a[target=_blank]" );
71
+ if (thumbs .size () == 0 ) {
72
+ logger .info ("No images found at " + nextUrl );
73
+ }
74
+ else {
75
+ // Iterate over images on page
76
+ for (Element thumb : thumbs ) {
77
+ if (isStopped ()) {
78
+ break ;
79
+ }
80
+ index ++;
81
+ ImagevenueImageThread t = new ImagevenueImageThread (new URL (thumb .attr ("href" )), index );
82
+ imagevenueThreadPool .addThread (t );
83
+ try {
84
+ Thread .sleep (IMAGE_SLEEP_TIME );
85
+ } catch (InterruptedException e ) {
86
+ logger .warn ("Interrupted while waiting to load next image" , e );
87
+ break ;
88
+ }
89
+ }
90
+ }
91
+
92
+ imagevenueThreadPool .waitForThreads ();
93
+ waitForThreads ();
94
+ }
95
+
96
+ public boolean canRip (URL url ) {
97
+ return url .getHost ().endsWith (DOMAIN );
98
+ }
99
+
100
+ /**
101
+ * Helper class to find and download images found on "image" pages
102
+ *
103
+ * Handles case when site has IP-banned the user.
104
+ */
105
+ private class ImagevenueImageThread extends Thread {
106
+ private URL url ;
107
+ private int index ;
108
+
109
+ public ImagevenueImageThread (URL url , int index ) {
110
+ super ();
111
+ this .url = url ;
112
+ this .index = index ;
113
+ }
114
+
115
+ @ Override
116
+ public void run () {
117
+ fetchImage ();
118
+ }
119
+
120
+ private void fetchImage () {
121
+ try {
122
+ Document doc = Jsoup .connect (this .url .toExternalForm ())
123
+ .userAgent (USER_AGENT )
124
+ .timeout (5000 )
125
+ .referrer (this .url .toExternalForm ())
126
+ .get ();
127
+ // Find image
128
+ Elements images = doc .select ("a > img" );
129
+ if (images .size () == 0 ) {
130
+ logger .warn ("Image not found at " + this .url );
131
+ return ;
132
+ }
133
+ Element image = images .first ();
134
+ String imgsrc = image .attr ("src" );
135
+ imgsrc = "http://" + this .url .getHost () + "/" + imgsrc ;
136
+ // Provide prefix and let the AbstractRipper "guess" the filename
137
+ String prefix = "" ;
138
+ if (Utils .getConfigBoolean ("download.save_order" , true )) {
139
+ prefix = String .format ("%03d_" , index );
140
+ }
141
+ addURLToDownload (new URL (imgsrc ), prefix );
142
+ } catch (IOException e ) {
143
+ logger .error ("[!] Exception while loading/parsing " + this .url , e );
144
+ }
145
+ }
146
+ }
147
+ }
0 commit comments