mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-06 11:57:20 +08:00
[mover] Add check if file is still on cache mount (#493)
* Update mover.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update scripts/mover.py Co-authored-by: bobokun <12660469+bobokun@users.noreply.github.com> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: bobokun <12660469+bobokun@users.noreply.github.com>
This commit is contained in:
parent
604d08274a
commit
1365689397
1 changed files with 19 additions and 5 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue