11package com .rarchives .ripme .ripper ;
22
3- import java .io .File ;
43import java .io .IOException ;
54import java .net .URL ;
65import java .nio .charset .StandardCharsets ;
109import java .nio .file .StandardOpenOption ;
1110import java .util .Collections ;
1211import java .util .HashMap ;
12+ import java .util .HashSet ;
1313import java .util .Map ;
14+ import java .util .Set ;
1415
1516import org .apache .logging .log4j .LogManager ;
1617import org .apache .logging .log4j .Logger ;
@@ -23,8 +24,8 @@ public abstract class QueueingRipper extends AbstractRipper {
2324
2425 protected final Logger logger = LogManager .getLogger (getClass ());
2526
26- private final Map <URL , File > itemsPending = Collections .synchronizedMap (new HashMap <>());
27- private final Map <URL , Path > itemsCompleted = Collections .synchronizedMap (new HashMap <>());
27+ private final Set <URL > itemsPending = Collections .synchronizedSet (new HashSet <>());
28+ private final Set <URL > itemsCompleted = Collections .synchronizedSet (new HashSet <>());
2829 private final Map <URL , String > itemsErrored = Collections .synchronizedMap (new HashMap <>());
2930
3031 public QueueingRipper (URL url ) throws IOException {
@@ -59,8 +60,8 @@ public boolean addURLToDownload(URL url, Path saveAs, String referrer, Map<Strin
5960 return false ;
6061 }
6162 if (!allowDuplicates ()
62- && ( itemsPending .containsKey (url )
63- || itemsCompleted .containsKey (url )
63+ && ( itemsPending .contains (url )
64+ || itemsCompleted .contains (url )
6465 || itemsErrored .containsKey (url ) )) {
6566 // Item is already downloaded/downloading, skip it.
6667 logger .info ("[!] Skipping " + url + " -- already attempted: " + Utils .removeCWD (saveAs ));
@@ -76,13 +77,13 @@ public boolean addURLToDownload(URL url, Path saveAs, String referrer, Map<Strin
7677 final var text = url .toExternalForm () + System .lineSeparator ();
7778 try {
7879 Files .write (urlFile , text .getBytes (StandardCharsets .UTF_8 ), StandardOpenOption .APPEND );
79- itemsCompleted .put (url , urlFile );
80+ itemsCompleted .add (url );
8081 } catch (final IOException e ) {
8182 logger .error ("Error while writing to " + urlFile , e );
8283 }
8384 }
8485 else {
85- itemsPending . put (url , saveAs . toFile () );
86+ addURLToPending (url );
8687 downloadInBackground (url , saveAs , referrer , cookies , getFileExtFromMIME );
8788 }
8889
@@ -126,6 +127,13 @@ protected boolean addURLToDownload(URL url) {
126127 return addURLToDownload (url , "" , "" );
127128 }
128129
130+ protected void addURLToPending (URL url ) {
131+ if (observer == null ) {
132+ return ;
133+ }
134+ itemsPending .add (url );
135+ observer .update (this , new RipStatusMessage (STATUS .DOWNLOAD_PROGRESSED , url ));
136+ }
129137
130138 @ Override
131139 /*
@@ -139,7 +147,7 @@ public void downloadCompleted(URL url, Path saveAs) {
139147 final var path = Utils .removeCWD (saveAs );
140148 final var msg = new RipStatusMessage (STATUS .DOWNLOAD_COMPLETE , path );
141149 itemsPending .remove (url );
142- itemsCompleted .put (url , saveAs );
150+ itemsCompleted .add (url );
143151 observer .update (this , msg );
144152
145153 checkIfComplete ();
@@ -174,7 +182,7 @@ public void downloadExists(URL url, Path file) {
174182 }
175183
176184 itemsPending .remove (url );
177- itemsCompleted .put (url , file );
185+ itemsCompleted .add (url );
178186 observer .update (this , new RipStatusMessage (STATUS .DOWNLOAD_WARN , url + " already saved as " + file ));
179187
180188 checkIfComplete ();
0 commit comments