44import java .io .FileOutputStream ;
55import java .io .IOException ;
66import java .io .UnsupportedEncodingException ;
7- import java .net .*;
7+ import java .net .MalformedURLException ;
8+ import java .net .URI ;
9+ import java .net .URISyntaxException ;
10+ import java .net .URL ;
811import java .nio .charset .StandardCharsets ;
912import java .nio .file .Files ;
1013import java .nio .file .Path ;
1619import java .util .List ;
1720import java .util .Map ;
1821
22+ import org .apache .logging .log4j .LogManager ;
23+ import org .apache .logging .log4j .Logger ;
1924import org .jsoup .nodes .Document ;
2025
21- import com .rarchives .ripme .ui .RipStatusMessage .STATUS ;
22- import com .rarchives .ripme .utils .Utils ;
2326import com .rarchives .ripme .ui .MainWindow ;
2427import com .rarchives .ripme .ui .RipStatusMessage ;
28+ import com .rarchives .ripme .ui .RipStatusMessage .STATUS ;
2529import com .rarchives .ripme .utils .Http ;
30+ import com .rarchives .ripme .utils .Utils ;
2631
2732/**
2833 * Simplified ripper, designed for ripping from sites by parsing HTML.
2934 */
3035public abstract class AbstractHTMLRipper extends AbstractRipper {
3136
37+ private static final Logger logger = LogManager .getLogger (AbstractHTMLRipper .class );
38+
3239 private final Map <URL , File > itemsPending = Collections .synchronizedMap (new HashMap <>());
3340 private final Map <URL , Path > itemsCompleted = Collections .synchronizedMap (new HashMap <>());
3441 private final Map <URL , String > itemsErrored = Collections .synchronizedMap (new HashMap <>());
@@ -116,7 +123,7 @@ protected boolean pageContainsAlbums(URL url) {
116123 public void rip () throws IOException , URISyntaxException {
117124 int index = 0 ;
118125 int textindex = 0 ;
119- LOGGER .info ("Retrieving " + this .url );
126+ logger .info ("Retrieving " + this .url );
120127 sendUpdate (STATUS .LOADING_RESOURCE , this .url .toExternalForm ());
121128 var doc = getCachedFirstPage ();
122129
@@ -128,20 +135,20 @@ public void rip() throws IOException, URISyntaxException {
128135
129136 // We set doc to null here so the while loop below this doesn't fire
130137 doc = null ;
131- LOGGER .debug ("Adding items from " + this .url + " to queue" );
138+ logger .debug ("Adding items from " + this .url + " to queue" );
132139 }
133140
134141 List <String > doclocation = new ArrayList <>();
135142
136- LOGGER .info ("Got doc location " + doc .location ());
143+ logger .info ("Got doc location " + doc .location ());
137144
138145 while (doc != null ) {
139146
140- LOGGER .info ("Processing a doc..." );
147+ logger .info ("Processing a doc..." );
141148
142149 // catch if we saw a doc location already, save the ones seen in a list
143150 if (doclocation .contains (doc .location ())) {
144- LOGGER .info ("Already processed location " + doc .location () + " breaking" );
151+ logger .info ("Already processed location " + doc .location () + " breaking" );
145152 break ;
146153 }
147154 doclocation .add (doc .location ());
@@ -151,7 +158,7 @@ public void rip() throws IOException, URISyntaxException {
151158 break ;
152159 }
153160
154- LOGGER .info ("retrieving urls from doc" );
161+ logger .info ("retrieving urls from doc" );
155162
156163 List <String > imageURLs = getURLsFromPage (doc );
157164 // If hasASAPRipping() returns true then the ripper will handle downloading the files
@@ -170,25 +177,25 @@ public void rip() throws IOException, URISyntaxException {
170177
171178 for (String imageURL : imageURLs ) {
172179 index += 1 ;
173- LOGGER .debug ("Found image url #" + index + ": '" + imageURL + "'" );
180+ logger .debug ("Found image url #" + index + ": '" + imageURL + "'" );
174181 downloadURL (new URI (imageURL ).toURL (), index );
175182 if (isStopped () || isThisATest ()) {
176183 break ;
177184 }
178185 }
179186 }
180187 if (hasDescriptionSupport () && Utils .getConfigBoolean ("descriptions.save" , false )) {
181- LOGGER .debug ("Fetching description(s) from " + doc .location ());
188+ logger .debug ("Fetching description(s) from " + doc .location ());
182189 List <String > textURLs = getDescriptionsFromPage (doc );
183190 if (!textURLs .isEmpty ()) {
184- LOGGER .debug ("Found description link(s) from " + doc .location ());
191+ logger .debug ("Found description link(s) from " + doc .location ());
185192 for (String textURL : textURLs ) {
186193 if (isStopped () || isThisATest ()) {
187194 break ;
188195 }
189196
190197 textindex += 1 ;
191- LOGGER .debug ("Getting description from " + textURL );
198+ logger .debug ("Getting description from " + textURL );
192199 String [] tempDesc = getDescription (textURL ,doc );
193200
194201 if (tempDesc != null ) {
@@ -204,11 +211,11 @@ public void rip() throws IOException, URISyntaxException {
204211 + ".txt" ).exists ();
205212
206213 if (Utils .getConfigBoolean ("file.overwrite" , false ) || !fileExists ) {
207- LOGGER .debug ("Got description from " + textURL );
214+ logger .debug ("Got description from " + textURL );
208215 saveText (url , "" , tempDesc [0 ], textindex , (tempDesc .length > 1 ? tempDesc [1 ] : filename ));
209216 sleep (descSleepTime ());
210217 } else {
211- LOGGER .debug ("Description from " + textURL + " already exists." );
218+ logger .debug ("Description from " + textURL + " already exists." );
212219 }
213220 }
214221
@@ -224,14 +231,14 @@ public void rip() throws IOException, URISyntaxException {
224231 sendUpdate (STATUS .LOADING_RESOURCE , "next page" );
225232 doc = getNextPage (doc );
226233 } catch (IOException e ) {
227- LOGGER .info ("Can't get next page: " + e .getMessage ());
234+ logger .info ("Can't get next page: " + e .getMessage ());
228235 break ;
229236 }
230237 }
231238
232239 // If they're using a thread pool, wait for it.
233240 if (getThreadPool () != null ) {
234- LOGGER .debug ("Waiting for threadpool " + getThreadPool ().getClass ().getName ());
241+ logger .debug ("Waiting for threadpool " + getThreadPool ().getClass ().getName ());
235242 getThreadPool ().waitForThreads ();
236243 }
237244 waitForThreads ();
@@ -296,12 +303,12 @@ private boolean saveText(URL url, String subdirectory, String text, int index, S
296303 out .write (text .getBytes ());
297304 out .close ();
298305 } catch (IOException e ) {
299- LOGGER .error ("[!] Error creating save file path for description '" + url + "':" , e );
306+ logger .error ("[!] Error creating save file path for description '" + url + "':" , e );
300307 return false ;
301308 }
302- LOGGER .debug ("Downloading " + url + "'s description to " + saveFileAs );
309+ logger .debug ("Downloading " + url + "'s description to " + saveFileAs );
303310 if (!saveFileAs .getParentFile ().exists ()) {
304- LOGGER .info ("[+] Creating directory: " + saveFileAs .getParent ());
311+ logger .info ("[+] Creating directory: " + saveFileAs .getParent ());
305312 saveFileAs .getParentFile ().mkdirs ();
306313 }
307314 return true ;
@@ -355,7 +362,7 @@ public boolean addURLToDownload(URL url, Path saveAs, String referrer, Map<Strin
355362 || itemsCompleted .containsKey (url )
356363 || itemsErrored .containsKey (url ) )) {
357364 // Item is already downloaded/downloading, skip it.
358- LOGGER .info ("[!] Skipping " + url + " -- already attempted: " + Utils .removeCWD (saveAs ));
365+ logger .info ("[!] Skipping " + url + " -- already attempted: " + Utils .removeCWD (saveAs ));
359366 return false ;
360367 }
361368 if (shouldIgnoreURL (url )) {
@@ -370,7 +377,7 @@ public boolean addURLToDownload(URL url, Path saveAs, String referrer, Map<Strin
370377 Files .write (urlFile , text .getBytes (StandardCharsets .UTF_8 ), StandardOpenOption .CREATE , StandardOpenOption .APPEND );
371378 itemsCompleted .put (url , urlFile );
372379 } catch (IOException e ) {
373- LOGGER .error ("Error while writing to " + urlFile , e );
380+ logger .error ("Error while writing to " + urlFile , e );
374381 }
375382 }
376383 else {
@@ -423,7 +430,7 @@ public void downloadCompleted(URL url, Path saveAs) {
423430
424431 checkIfComplete ();
425432 } catch (Exception e ) {
426- LOGGER .error ("Exception while updating observer: " , e );
433+ logger .error ("Exception while updating observer: " , e );
427434 }
428435 }
429436
@@ -486,20 +493,20 @@ public void setWorkingDir(URL url) throws IOException, URISyntaxException {
486493 path += File .separator ;
487494 }
488495 String title = getAlbumTitle (this .url );
489- LOGGER .debug ("Using album title '" + title + "'" );
496+ logger .debug ("Using album title '" + title + "'" );
490497
491498 title = Utils .filesystemSafe (title );
492499 path += title ;
493500 path = Utils .getOriginalDirectory (path ) + File .separator ; // check for case sensitive (unix only)
494501
495502 this .workingDir = new File (path );
496503 if (!this .workingDir .exists ()) {
497- LOGGER .info ("[+] Creating directory: " + Utils .removeCWD (this .workingDir .toPath ()));
504+ logger .info ("[+] Creating directory: " + Utils .removeCWD (this .workingDir .toPath ()));
498505 if (!this .workingDir .mkdirs ()) {
499506 throw new IOException ("Failed creating dir: \" " + this .workingDir + "\" " );
500507 }
501508 }
502- LOGGER .debug ("Set working directory to: " + this .workingDir );
509+ logger .debug ("Set working directory to: " + this .workingDir );
503510 }
504511
505512 /**
0 commit comments