Skip to content

Commit c8768c7

Browse files
committed
torrents: add --status
1 parent 5c20075 commit c8768c7

File tree

5 files changed

+11
-28
lines changed

5 files changed

+11
-28
lines changed

library/playback/links_open.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import argparse, shlex
1+
import argparse
22

33
from library import usage
44
from library.mediadb import db_history, db_media
@@ -38,9 +38,6 @@ def parse_args() -> argparse.Namespace:
3838
args.title_prefix = ["https://www.google.com/search?q=%"]
3939
args.title_prefix = [s if "%" in s else s + "%" for s in args.title_prefix]
4040

41-
if args.browser:
42-
args.browser = shlex.split(args.browser)
43-
4441
return args
4542

4643

library/playback/torrents_info.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,8 @@ def shorten(s, width):
161161
torrents = qbt_client.torrents_info()
162162

163163
error_torrents = [t for t in torrents if t.state_enum.is_errored]
164-
error_torrents = sorted(
165-
error_torrents, key=lambda t: (t.amount_left == t.total_size, t.eta, t.amount_left), reverse=True
166-
)
167164
if error_torrents:
168-
print("Error Torrents")
169-
tbl = [
170-
{
171-
"state": t.state,
172-
"name": shorten(t.name, width=40),
173-
"progress": strings.safe_percent(t.progress),
174-
"eta": strings.duration_short(t.eta) if t.eta < 8640000 else None,
175-
"remaining": strings.file_size(t.amount_left) if t.amount_left > 0 else None,
176-
"files": len(t.files) if args.file_counts else None,
177-
}
178-
for t in error_torrents
179-
]
180-
printing.table(tbl)
181-
print()
165+
args.status = True
182166

183167
torrents = filter_torrents_by_activity(args, torrents)
184168
torrents = [t for t in torrents if is_matching(args, t)]
@@ -274,6 +258,8 @@ def gen_row(t):
274258
d |= {"priority": str(t.priority) + (" [F]" if t.force_start else "")}
275259
if args.trackers:
276260
d |= {"tracker": qbt_get_tracker(qbt_client, t)}
261+
if args.status:
262+
d |= {"state": t.state}
277263

278264
if args.verbose >= consts.LOG_INFO:
279265
d |= {
@@ -338,10 +324,11 @@ def gen_row(t):
338324
d |= {"priority": str(t.priority) + (" [F]" if t.force_start else "")}
339325
if args.trackers:
340326
d |= {"tracker": qbt_get_tracker(qbt_client, t)}
327+
if args.status:
328+
d |= {"state": t.state}
341329

342330
if args.verbose >= consts.LOG_INFO:
343331
d |= {
344-
"state": t.state,
345332
"added_on": strings.relative_datetime(t.added_on),
346333
"size": strings.file_size(t.total_size),
347334
"remaining": strings.file_size(t.amount_left),

library/playback/torrents_status.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ def shorten(s, width):
9696
}
9797
)
9898

99-
categories = sorted(
100-
categories,
101-
key=lambda d: (
102-
iterables.safe_index(interesting_states, d["state"])
103-
)
104-
)
99+
categories = sorted(categories, key=lambda d: (iterables.safe_index(interesting_states, d["state"])))
105100

106101
if len(torrents_by_state) > 1:
107102
remaining = sum(t.amount_left for t in torrents)

library/utils/arggroups.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,7 @@ def qBittorrent_torrents(parent_parser):
20582058
"--file-counts", "--files", "--counts", action="store_true", help="Include file counts column (a bit slow)"
20592059
)
20602060
parser.add_argument("--trackers", action="store_true", help="Include tracker column")
2061+
parser.add_argument("--status", "--state", action="store_true", help="Include state column")
20612062

20622063
parser.add_argument("--file-search", "-s", nargs="+", help="The file path substring to search for")
20632064
parser.add_argument("torrent_search", nargs="*", help="The info_hash, name, or save_path substring to search for")

library/utils/date_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55

66
from library.utils import iterables, nums
77

8+
89
def is_tz_aware(dt: datetime.datetime) -> bool:
910
return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None
1011

12+
1113
def maybe_tz_now(maybe_tz_dt: datetime.datetime):
1214
if is_tz_aware(maybe_tz_dt):
1315
now = datetime.datetime.now(tz=tz.utc).astimezone()
1416
else:
1517
now = datetime.datetime.now()
1618
return now
1719

20+
1821
def super_parser(date_str, fallback=False):
1922
parsing_strategies = [
2023
{}, # default

0 commit comments

Comments
 (0)