Skip to content

Commit bf45574

Browse files
committed
torrents: add --missing and --start
1 parent f323c50 commit bf45574

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

library/createdb/av.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def munge_av_tags(args, media) -> dict:
157157

158158
if not media.get("size"):
159159
if size:
160-
media["size"] = size
160+
media["size"] = int(size)
161161
elif bitrate_bps and duration:
162162
total_bits = duration * float(bitrate_bps)
163163
total_bytes = math.ceil(total_bits / 8)

library/playback/torrents_info.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def parse_args():
2121
help="Sort by priority, ratio, download, upload, download+upload, size, avg_size, remaining",
2222
)
2323

24-
parser.add_argument(
25-
"--force-start", "--start", action=argparse.BooleanOptionalAction, help="Force start matching torrents"
26-
)
24+
parser.add_argument("--start", action=argparse.BooleanOptionalAction, help="Start matching torrents")
25+
parser.add_argument("--force-start", action=argparse.BooleanOptionalAction, help="Force start matching torrents")
26+
parser.add_argument("--check", "--recheck", action="store_true", help="Check matching torrents")
2727
parser.add_argument("--stop", action="store_true", help="Stop matching torrents")
2828
parser.add_argument("--move", help="Directory to move folders/files")
2929
parser.add_argument(
@@ -43,6 +43,9 @@ def parse_args():
4343

4444
arggroups.qBittorrent_torrents_post(args)
4545

46+
if args.move and not (args.stop or args.delete_rows or args.delete_files):
47+
processes.exit_error("--move requires --stop or --delete-rows")
48+
4649
return args
4750

4851

@@ -83,7 +86,7 @@ def is_matching(args, t):
8386
if t.num_complete == 0 and t.seen_complete > 0
8487
else (
8588
t.added_on
86-
if t.state in ['downloading', 'forceDL', 'stalledDL', 'uploading', 'forcedUP', 'stalledUP']
89+
if t.state in ["downloading", "forceDL", "stalledDL", "uploading", "forcedUP", "stalledUP"]
8790
and t.num_complete == 0
8891
else 0
8992
)
@@ -114,6 +117,10 @@ def is_matching(args, t):
114117
def filter_torrents_by_activity(args, torrents):
115118
if args.stopped:
116119
torrents = [t for t in torrents if t.state_enum.is_stopped]
120+
if args.errored:
121+
torrents = [t for t in torrents if t.state == "error"]
122+
if args.missing:
123+
torrents = [t for t in torrents if t.state == "missingFiles"]
117124
if args.complete:
118125
torrents = [t for t in torrents if t.state_enum.is_complete]
119126
if args.incomplete:
@@ -351,14 +358,22 @@ def gen_row(t):
351358

352359
torrent_hashes = [t.hash for t in torrents]
353360

354-
if args.force_start is not None:
355-
print("Force-starting", len(torrents))
356-
qbt_client.torrents_set_force_start(args.force_start, torrent_hashes=torrent_hashes)
357-
358361
if args.stop:
359362
print("Stopping", len(torrents))
360363
qbt_client.torrents_stop(torrent_hashes=torrent_hashes)
361364

365+
if args.check:
366+
print("Checking", len(torrents))
367+
qbt_client.torrents_recheck(torrent_hashes=torrent_hashes)
368+
369+
if args.start is not None:
370+
print("Starting", len(torrents))
371+
qbt_client.torrents_start(torrent_hashes=torrent_hashes)
372+
373+
if args.force_start is not None:
374+
print("Force-starting", len(torrents))
375+
qbt_client.torrents_set_force_start(args.force_start, torrent_hashes=torrent_hashes)
376+
362377
if args.delete_incomplete:
363378
for t in torrents:
364379
if not os.path.exists(t.content_path):
@@ -375,7 +390,7 @@ def gen_row(t):
375390
if file.progress < args.delete_incomplete:
376391
path.unlink(missing_ok=True)
377392

378-
if (args.stop or args.mark_deleted or args.delete_rows or args.delete_files) and args.move:
393+
if (args.stop or args.delete_rows or args.delete_files) and args.move:
379394
for t in torrents:
380395
if os.path.exists(t.content_path):
381396
new_path = Path(args.move)

library/playback/torrents_status.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ def shorten(s, width):
9898

9999
if len(torrents_by_state) > 1:
100100
remaining = sum(t.amount_left for t in torrents)
101-
categories.append({
102-
"state": 'total',
103-
"count": len(torrents),
104-
"size": strings.file_size(sum(t.total_size for t in torrents)),
105-
"remaining": strings.file_size(remaining) if remaining else None,
106-
"files": (sum(len(t.files) for t in torrents) if args.file_counts else None),
107-
})
101+
categories.append(
102+
{
103+
"state": "total",
104+
"count": len(torrents),
105+
"size": strings.file_size(sum(t.total_size for t in torrents)),
106+
"remaining": strings.file_size(remaining) if remaining else None,
107+
"files": (sum(len(t.files) for t in torrents) if args.file_counts else None),
108+
}
109+
)
108110
printing.table(iterables.list_dict_filter_bool(categories))
109111
print()
110112

@@ -123,9 +125,7 @@ def shorten(s, width):
123125
"count": len(tracker_torrents),
124126
"size": sum(t.total_size for t in tracker_torrents),
125127
"remaining": remaining,
126-
"files": (
127-
sum(len(t.files) for t in tracker_torrents) if args.file_counts else None
128-
), # a bit slow
128+
"files": (sum(len(t.files) for t in tracker_torrents) if args.file_counts else None), # a bit slow
129129
}
130130
)
131131
if trackers:

library/utils/arggroups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,8 @@ def qBittorrent_torrents(parent_parser):
20012001
)
20022002
parser.add_argument("--inactive", "--dead", action="store_true", help="Include inactive torrents")
20032003
parser.add_argument("--stopped", "--paused", action="store_true", help="Include stopped torrents")
2004+
parser.add_argument("--missing", action="store_true", help="Include missing torrents")
2005+
parser.add_argument("--errored", action="store_true", help="Include errored torrents")
20042006
parser.add_argument("--complete", "--completed", action="store_true", help="Include completed torrents")
20052007
parser.add_argument("--incomplete", action="store_true", help="Include incomplete torrents")
20062008

0 commit comments

Comments
 (0)