@@ -40,9 +40,12 @@ def _load_config(self, config_file: str) -> None:
4040 self .real_path = config .get ('real_path' , '' )
4141 self .enable_recheck = config .get ('enable_recheck' , True )
4242 self .enable_orphan_check = config .get ('enable_orphan_check' , True )
43- self .orphan_states = config .get ('orphan_states' , [])
43+ self .orphan_states = [ state . lower () for state in config .get ('orphan_states' , [])]
4444 self .min_peers = config .get ('min_peers' , 1 )
4545
46+ self .enable_auto_update_trackers = config .get ('enable_auto-update_trackers' , False )
47+ self .auto_update_trackers_script = config .get ('auto-update_trackers_script' , '' )
48+
4649 self .base_url = f"{ self .host } :{ self .port } "
4750 self .session = requests .Session ()
4851
@@ -187,10 +190,35 @@ def remove_trackers(self, torrent_hash: str, trackers: Dict[str, str]) -> None:
187190 urljoin (self .base_url , 'api/v2/torrents/removeTrackers' ),
188191 data = {'hash' : torrent_hash , 'urls' : tracker }
189192 )
190- print (f"- Bad tracker{ 's' if len (trackers ) > 1 else '' } removed" )
193+ print (f"- Bad tracker{ 's' if len (trackers ) > 1 else '' } removed" )
191194 except Exception as e :
192195 print (f"Failed to remove trackers: { str (e )} " )
193196
197+ def run_tracker_update_script (self , torrent_hash : str , torrent_name : str ) -> None :
198+ """Execute tracker update script for the specified torrent using the torrent name"""
199+ try :
200+ if self .dry_run :
201+ print (f"- [DRY-RUN] Would run tracker update script for torrent: { torrent_name } " )
202+ return
203+
204+ import subprocess
205+
206+ # Utilizziamo il nome del torrent con l'argomento -n
207+ command = [self .auto_update_trackers_script , "-n" , torrent_name ]
208+
209+ result = subprocess .run (
210+ command ,
211+ capture_output = True ,
212+ text = True
213+ )
214+
215+ if result .returncode == 0 :
216+ print (f"- Tracker update script executed successfully" )
217+ else :
218+ print (f"- Tracker update script failed: { result .stderr .strip () or result .stdout .strip ()} " )
219+ except Exception as e :
220+ print (f"Failed to run tracker update script: { str (e )} " )
221+
194222 def _print_configuration (self ) -> None :
195223 """Print the current configuration"""
196224 print ("\n Current configuration:" )
@@ -207,6 +235,10 @@ def _print_configuration(self) -> None:
207235 print (f"- Enable orphan check: { self .enable_orphan_check } " )
208236 print (f"- Orphan states: { self .orphan_states if self .orphan_states else 'not set' } " )
209237
238+ print (f"- Auto-update trackers: { self .enable_auto_update_trackers } " )
239+ if self .enable_auto_update_trackers :
240+ print (f"- Update script: { self .auto_update_trackers_script } " )
241+
210242 if self .dry_run :
211243 print (f"{ Fore .GREEN } - DRY-RUN mode enabled{ Style .RESET_ALL } " )
212244 print ("\n Processing only selected torrents..." )
@@ -233,8 +265,8 @@ def process_torrents(self) -> None:
233265 # Control recheck
234266 if self .enable_recheck :
235267 print ("- Checking for errors ->" , end = " " )
236- if torrent .get ('state' ) == "error" :
237- print (f"{ Fore .RED } errors found{ Style .RESET_ALL } " )
268+ if torrent .get ('state' ) in [ "error" , "missingFiles" ] :
269+ print (f"{ Fore .RED } errors found, forcing recheck { Style .RESET_ALL } " )
238270 self .recheck_torrent (torrent ['hash' ])
239271 else :
240272 print (f"{ Fore .GREEN } no errors found{ Style .RESET_ALL } " )
@@ -249,7 +281,7 @@ def process_torrents(self) -> None:
249281 print (f" { tracker } -> { Fore .RED } { error } { Style .RESET_ALL } " )
250282 self .remove_trackers (torrent ['hash' ], bad_trackers )
251283 else :
252- print (" no bad trackers found" )
284+ print (f" { Fore . GREEN } no bad trackers found{ Style . RESET_ALL } " )
253285
254286 # Orphan check
255287 if self .enable_orphan_check and is_private :
@@ -274,6 +306,14 @@ def process_torrents(self) -> None:
274306 else :
275307 print ("no orphan detected" )
276308
309+ # Tracker update script
310+ if self .enable_auto_update_trackers and not is_private and torrent ['progress' ] != 1 :
311+ print ("- Running tracker update script ->" , end = " " )
312+ if self .auto_update_trackers_script :
313+ self .run_tracker_update_script (torrent ['hash' ], torrent ['name' ])
314+ else :
315+ print ("script path not configured" )
316+
277317 # Controllo hardlink
278318 content_path = torrent .get ('content_path' , '' )
279319 if content_path :
@@ -336,6 +376,7 @@ def process_torrents(self) -> None:
336376 - "unregistered"
337377 - "not registered"
338378 - "not found"
379+ - "not working"
339380
340381# Minimum number of peers before considering a torrent orphaned.
341382# Default: 1
@@ -420,4 +461,4 @@ def main() -> None:
420461 sys .exit (1 )
421462
422463if __name__ == "__main__" :
423- main ()
464+ main ()
0 commit comments