@@ -92,8 +92,8 @@ def run(self) -> int:
9292 f"in { QBT_CAT_NAME } "
9393 )
9494 if context .debug :
95- for btih in self .manager .btihs :
96- logger .debug (f"* { self . manager . get ( btih ) !s} " )
95+ for torrent in self .manager .get_all () :
96+ logger .debug (f"* { torrent !s} " )
9797
9898 self .remove_outdated_torrents ()
9999 self .reconcile_books_and_torrents ()
@@ -162,10 +162,11 @@ def remove_outdated_torrents(self):
162162
163163 # reconciling existing torrents and books
164164 unselected_books = list (self .manager .btihs .keys ())
165+ all_btihs = self .manager .btihs .items ()
165166 for book in self .books :
166167 btihs = [
167168 btih
168- for btih , fname in self . manager . btihs . items ()
169+ for btih , fname in all_btihs
169170 # having condition on name first is important and it allows
170171 # us to only compare on btih if name matches.
171172 # we cant direclty compare on btih as it would require getting the
@@ -177,26 +178,41 @@ def remove_outdated_torrents(self):
177178 book .btih = btihs [0 ]
178179 unselected_books .remove (book .btih )
179180
181+ # get added_on for all btih
182+ all_added_ts : dict [str , int ] = dict (
183+ zip (
184+ unselected_books ,
185+ self .manager .get_all_added_ts (unselected_books ),
186+ strict = False ,
187+ )
188+ )
180189 # keep those that are within --keep duration
181- keep_until = self .now - datetime .timedelta (seconds = context .keep_for )
190+ keep_until = (
191+ self .now - datetime .timedelta (seconds = context .keep_for )
192+ ).timestamp ()
182193 for btih in unselected_books :
183- if self .manager .get (btih ).added_on <= keep_until :
194+ # keep (remove from unselected) is added to BT after that date in the past
195+ if all_added_ts [btih ] > keep_until :
184196 unselected_books .remove (btih )
197+ else :
198+ logger .error (
199+ f"{ self .manager .get (btih ).added_on } is before { keep_until } "
200+ )
185201
186202 if not unselected_books :
187203 logger .info ("> None" )
188204 return
189205
190206 logger .info (
191- f"{ self .banner } Removing { len (unselected_books )} outdated torrents "
192- "( not in catalog, over --keep)… "
207+ f"{ self .banner } Removing { len (unselected_books )} torrents: "
208+ "outside filters or not in catalog and anterior to --keep"
193209 )
194- for btih in unselected_books :
195- logger .info (f"- { self . manager . get ( btih ) !s} " )
210+ for torrent in self . manager . get_all ( btihs = unselected_books ) :
211+ logger .info (f"- { torrent !s} " )
196212 if context .dry_run :
197213 continue
198- if not self .manager .remove (btih ):
199- logger .error (f"Failed to remove { btih } " )
214+ if not self .manager .remove (torrent . btih ):
215+ logger .error (f"Failed to remove { torrent . btih } " )
200216
201217 def ensure_storage (self ):
202218 torrents_size = self .manager .total_size
@@ -213,6 +229,8 @@ def ensure_storage(self):
213229
214230 if total_size > context .max_storage :
215231 logger .error ("Total size exceeds max-storage" )
232+ if context .dry_run :
233+ logger .error (">> does not account removal in dry-mode" )
216234 return True
217235
218236 def reconcile_books_and_torrents (self ):
0 commit comments