|
4 | 4 |
|
5 | 5 | from library import usage |
6 | 6 | from library.mediafiles import torrents_start |
7 | | -from library.utils import arggroups, argparse_utils, consts, iterables, printing, processes, strings |
| 7 | +from library.utils import arggroups, argparse_utils, consts, iterables, path_utils, printing, processes, strings |
8 | 8 | from library.utils.path_utils import domain_from_url |
9 | 9 |
|
10 | 10 |
|
@@ -45,10 +45,13 @@ def parse_args(): |
45 | 45 | parser.add_argument("--all", action="store_true", help="Show active and inactive torrents") |
46 | 46 | parser.add_argument("--active", action="store_true", help="Show active torrents") |
47 | 47 | parser.add_argument("--inactive", "--dead", action="store_true", help="Show inactive torrents") |
| 48 | + parser.add_argument("--stopped", "--paused", action="store_true", help="Show stopped torrents") |
48 | 49 |
|
49 | 50 | parser.add_argument( |
50 | 51 | "--force-start", "--start", action=argparse.BooleanOptionalAction, help="Force start matching torrents" |
51 | 52 | ) |
| 53 | + parser.add_argument("--stop", action="store_true", help="Stop matching torrents") |
| 54 | + parser.add_argument("--export", action="store_true", help="Export matching torrent files") |
52 | 55 | arggroups.capability_soft_delete(parser) |
53 | 56 | arggroups.capability_delete(parser) |
54 | 57 | arggroups.debug(parser) |
@@ -133,6 +136,9 @@ def shorten(s, width): |
133 | 136 | printing.table(tbl) |
134 | 137 | print() |
135 | 138 |
|
| 139 | + if args.stopped: |
| 140 | + torrents = [t for t in torrents if t.state_enum.is_stopped] |
| 141 | + |
136 | 142 | torrents = filter_torrents_by_activity(args, torrents) |
137 | 143 |
|
138 | 144 | if args.torrent_search or args.file_search: |
@@ -187,7 +193,7 @@ def shorten(s, width): |
187 | 193 | or (t.state_enum.is_complete and t.uploaded_session > 0) |
188 | 194 | ] |
189 | 195 | if active_torrents: |
190 | | - print("Active Torrents") |
| 196 | + print(f"Active Torrents ({len(active_torrents)})") |
191 | 197 |
|
192 | 198 | def gen_row(t): |
193 | 199 | d = { |
@@ -248,7 +254,7 @@ def gen_row(t): |
248 | 254 | or (t.state_enum.is_complete and t.uploaded_session == 0) |
249 | 255 | ] |
250 | 256 | if inactive_torrents: |
251 | | - print("Inactive Torrents") |
| 257 | + print(f"Inactive Torrents ({len(inactive_torrents)})") |
252 | 258 |
|
253 | 259 | def gen_row(t): |
254 | 260 | d = { |
@@ -318,6 +324,20 @@ def gen_row(t): |
318 | 324 | print("Force-starting", len(torrents)) |
319 | 325 | qbt_client.torrents_set_force_start(args.force_start, torrent_hashes=torrent_hashes) |
320 | 326 |
|
| 327 | + if args.stop: |
| 328 | + print("Stopping", len(torrents)) |
| 329 | + qbt_client.torrents_stop(torrent_hashes=torrent_hashes) |
| 330 | + |
| 331 | + if args.export: |
| 332 | + p = Path("exported_torrents") |
| 333 | + p.mkdir(exist_ok=True) |
| 334 | + for idx, t in enumerate(torrents): |
| 335 | + printing.print_overwrite("Exporting", idx + 1, "of", len(torrents), "to", p) |
| 336 | + |
| 337 | + file_name = f"{qbt_get_tracker(qbt_client, t)}_{t.name}_{t.hash}.torrent" |
| 338 | + file_name = path_utils.clean_path(file_name.encode()) |
| 339 | + (p / file_name).write_bytes(qbt_client.torrents_export(torrent_hash=t.hash)) |
| 340 | + |
321 | 341 | if args.temp_drive and Path(args.temp_drive).is_absolute(): |
322 | 342 | temp_prefix = Path(args.temp_drive) |
323 | 343 | else: |
|
0 commit comments