diff --git a/scripts/mover.py b/scripts/mover.py index a1aadf0..23e767c 100755 --- a/scripts/mover.py +++ b/scripts/mover.py @@ -12,8 +12,16 @@ parser = argparse.ArgumentParser(prog="Qbit Mover", description="Stop torrents a parser.add_argument("--host", help="qbittorrent host including port", required=True) parser.add_argument("-u", "--user", help="qbittorrent user", default="admin") parser.add_argument("-p", "--password", help="qbittorrent password", default="adminadmin") -parser.add_argument("--days_from", help="Set Number of Days to stop torrents between two offsets", type=int, default=0) -parser.add_argument("--days_to", help="Set Number of Days to stop torrents between two offsets", type=int, default=2) +parser.add_argument( + "--cache-mount", + "--cache_mount", + help="Cache mount point in Unraid. This is used to additionally filter for only torrents that exists on the cache mount. Use this option ONLY if you follow TRaSH Guides folder structure.", + default=None, +) +parser.add_argument( + "--days-from", "--days_from", help="Set Number of Days to stop torrents between two offsets", type=int, default=0 +) +parser.add_argument("--days-to", "--days_to", help="Set Number of Days to stop torrents between two offsets", type=int, default=2) # --DEFINE VARIABLES--# # --START SCRIPT--# @@ -26,16 +34,22 @@ except ModuleNotFoundError: sys.exit(1) -def filter_torrents(torrent_list, timeoffset_from, timeoffset_to): +def filter_torrents(torrent_list, timeoffset_from, timeoffset_to, cache_mount): result = [] for torrent in torrent_list: if torrent.added_on >= timeoffset_to and torrent.added_on <= timeoffset_from: - result.append(torrent) + if not cache_mount or exists_in_cache(cache_mount, torrent.content_path): + result.append(torrent) elif torrent.added_on < timeoffset_to: break return result +def exists_in_cache(cache_mount, content_path): + cache_path = os.path.join(cache_mount, content_path.lstrip("/")) + return os.path.exists(cache_path) + + def stop_start_torrents(torrent_list, pause=True): for torrent in torrent_list: if pause: @@ -66,7 +80,7 @@ if __name__ == "__main__": timeoffset_to = current - timedelta(days=args.days_to) torrent_list = client.torrents.info(sort="added_on", reverse=True) - torrents = filter_torrents(torrent_list, timeoffset_from.timestamp(), timeoffset_to.timestamp()) + torrents = filter_torrents(torrent_list, timeoffset_from.timestamp(), timeoffset_to.timestamp(), args.cache_mount) # Pause Torrents print(f"Pausing [{len(torrents)}] torrents from {args.days_from} - {args.days_to} days ago")