Skip to content

Commit 09ab030

Browse files
committed
torrents-info: make less verbose by default
1 parent 9973af7 commit 09ab030

File tree

1 file changed

+57
-58
lines changed

1 file changed

+57
-58
lines changed

library/playback/torrents_info.py

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ def torrents_info():
7373
qbt_client.torrents_delete(delete_files=False, torrent_hashes=torrent_hashes)
7474
return
7575

76-
torrents_by_state = {}
77-
for torrent in all_torrents:
78-
torrents_by_state.setdefault(torrent.state, []).append(torrent)
79-
80-
torrents_by_tracker = {}
81-
for torrent in all_torrents:
82-
torrents_by_tracker.setdefault(qbt_get_tracker(qbt_client, torrent), []).append(torrent)
83-
8476
interesting_states = [
8577
"stoppedUP",
8678
"queuedUP",
@@ -95,17 +87,23 @@ def torrents_info():
9587
"error",
9688
]
9789

98-
tbl = []
99-
for state in {*interesting_states} - {"uploading", "downloading"}:
100-
torrents = torrents_by_state.get(state)
101-
if not torrents:
102-
continue
90+
torrents_by_state = {}
91+
for torrent in all_torrents:
92+
torrents_by_state.setdefault(torrent.state, []).append(torrent)
93+
94+
if args.verbose >= consts.LOG_INFO:
95+
torrents_by_tracker = {}
96+
for torrent in all_torrents:
97+
torrents_by_tracker.setdefault(qbt_get_tracker(qbt_client, torrent), []).append(torrent)
98+
99+
tbl = []
100+
for state in {*interesting_states} - {"uploading", "downloading"}:
101+
torrents = torrents_by_state.get(state)
102+
if not torrents:
103+
continue
103104

104-
torrents = sorted(torrents, key=lambda t: (-t.seen_complete, t.time_active))
105+
torrents = sorted(torrents, key=lambda t: (-t.seen_complete, t.time_active))
105106

106-
if args.verbose >= 1:
107-
printing.extended_view(torrents)
108-
else:
109107
tbl.extend(
110108
[
111109
{
@@ -114,23 +112,27 @@ def torrents_info():
114112
"seen_complete": strings.relative_datetime(t.seen_complete) if t.seen_complete > 0 else None,
115113
"last_activity": strings.relative_datetime(t.last_activity),
116114
"time_active": strings.duration(t.time_active),
115+
"num_seeds": f"{t.num_complete} ({t.num_seeds})",
116+
# 'num_leechs': f"{t.num_incomplete} ({t.num_leechs})",
117+
# 'comment': t.comment,
117118
}
118119
for t in torrents
119120
]
120121
)
121-
if tbl:
122-
printing.table(tbl)
123-
print()
122+
if tbl:
123+
printing.table(tbl)
124+
print()
124125

125-
tbl = []
126-
for state in interesting_states:
127-
torrents = torrents_by_state.get(state)
128-
if not torrents:
129-
continue
126+
tbl = []
127+
for state in ["downloading", "missingFiles", "error"]:
128+
torrents = torrents_by_state.get(state)
129+
if not torrents:
130+
continue
130131

131-
torrents = sorted(torrents, key=lambda t: (t.amount_left == t.total_size, t.eta, t.amount_left), reverse=True)
132+
torrents = sorted(
133+
torrents, key=lambda t: (t.amount_left == t.total_size, t.eta, t.amount_left), reverse=True
134+
)
132135

133-
if args.verbose == 0:
134136
tbl.extend(
135137
[
136138
{
@@ -139,43 +141,40 @@ def torrents_info():
139141
"progress": strings.safe_percent(t.progress),
140142
"eta": strings.duration(t.eta) if t.eta < 8640000 else None,
141143
"remaining": strings.file_size(t.amount_left),
142-
"num_seeds": f"{t.num_complete} ({t.num_seeds})",
143-
# 'num_leechs': f"{t.num_incomplete} ({t.num_leechs})",
144-
# 'comment': t.comment,
145144
}
146145
for t in torrents
147146
]
148147
)
149-
if tbl:
150-
printing.table(tbl)
151-
print()
148+
if tbl:
149+
printing.table(tbl)
150+
print()
152151

153-
trackers = []
154-
for tracker, torrents in torrents_by_tracker.items():
155-
torrents = [t for t in torrents if args.verbose >= 1 or t.state not in ("stoppedDL",)]
156-
remaining = sum(t.amount_left for t in torrents)
157-
if remaining or args.verbose >= 1:
158-
trackers.append(
152+
trackers = []
153+
for tracker, torrents in torrents_by_tracker.items():
154+
torrents = [t for t in torrents if args.verbose >= 2 or t.state not in ("stoppedDL",)]
155+
remaining = sum(t.amount_left for t in torrents)
156+
if remaining or args.verbose >= 2:
157+
trackers.append(
158+
{
159+
"tracker": tracker,
160+
"count": len(torrents),
161+
"size": sum(t.total_size for t in torrents),
162+
"remaining": remaining,
163+
"file_count": sum(len(t.files) for t in torrents) if args.verbose >= 2 else None, # a bit slow
164+
}
165+
)
166+
if trackers:
167+
trackers = sorted(trackers, key=lambda d: (d["remaining"], d["size"]))
168+
trackers = [
159169
{
160-
"tracker": tracker,
161-
"count": len(torrents),
162-
"size": sum(t.total_size for t in torrents),
163-
"remaining": remaining,
164-
"file_count": sum(len(t.files) for t in torrents) if args.verbose >= 1 else None, # a bit slow
170+
**d,
171+
"size": strings.file_size(d["size"]),
172+
"remaining": strings.file_size(d["remaining"]) if d["remaining"] else None,
165173
}
166-
)
167-
if trackers:
168-
trackers = sorted(trackers, key=lambda d: (d["remaining"], d["size"]))
169-
trackers = [
170-
{
171-
**d,
172-
"size": strings.file_size(d["size"]),
173-
"remaining": strings.file_size(d["remaining"]) if d["remaining"] else None,
174-
}
175-
for d in trackers
176-
]
177-
printing.table(iterables.list_dict_filter_bool(trackers))
178-
print()
174+
for d in trackers
175+
]
176+
printing.table(iterables.list_dict_filter_bool(trackers))
177+
print()
179178

180179
categories = []
181180
for state, torrents in torrents_by_state.items():
@@ -186,7 +185,7 @@ def torrents_info():
186185
"count": len(torrents),
187186
"size": strings.file_size(sum(t.total_size for t in torrents)),
188187
"remaining": strings.file_size(remaining) if remaining else None,
189-
"file_count": sum(len(t.files) for t in torrents) if args.verbose >= 1 else None, # a bit slow
188+
"file_count": sum(len(t.files) for t in torrents) if args.verbose >= 2 else None, # a bit slow
190189
}
191190
)
192191

0 commit comments

Comments
 (0)