Skip to content

Commit 2222043

Browse files
committed
torrents-info: add --all shortcut
1 parent 78517fa commit 2222043

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

library/playback/torrents_info.py

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def parse_args():
4040
parser.add_argument("--size", action="store_true", help="Sort by data transferred")
4141
parser.add_argument("--remaining", action="store_true", help="Sort by remaining")
4242

43+
parser.add_argument("--all", action="store_true", help="Show active and inactive torrents")
4344
parser.add_argument("--active", action=argparse.BooleanOptionalAction, help="Show active torrents")
4445
parser.add_argument("--inactive", "--dead", action=argparse.BooleanOptionalAction, help="Show inactive torrents")
4546

@@ -56,12 +57,11 @@ def parse_args():
5657
args = parser.parse_args()
5758
arggroups.args_post(args, parser)
5859

59-
if args.torrent_search or args.file_search:
60-
if set(["active", "inactive"]).issubset(args.defaults.keys()):
61-
args.active = True
62-
args.inactive = True
63-
else:
64-
if set(["active", "inactive"]).issubset(args.defaults.keys()):
60+
if set(["active", "inactive"]).issubset(args.defaults.keys()):
61+
if args.all or args.torrent_search or args.file_search:
62+
args.active = False
63+
args.inactive = False
64+
else:
6565
args.active = True
6666

6767
return args
@@ -78,27 +78,26 @@ def qbt_get_tracker(qbt_client, torrent):
7878

7979
def filter_torrents_by_activity(args, torrents):
8080
if args.downloading and args.uploading:
81-
torrents = [t for t in torrents if t.downloaded_session > 0 and t.uploaded_session > 0]
82-
else:
83-
if args.active:
84-
torrents = [
85-
t
86-
for t in torrents
87-
if (t.state_enum.is_downloading and t.downloaded_session > 0)
88-
or (t.state_enum.is_uploading and t.uploaded_session > 0)
89-
]
90-
if args.inactive:
91-
torrents = [
92-
t
93-
for t in torrents
94-
if (t.state_enum.is_downloading and t.downloaded_session == 0)
95-
or (t.state_enum.is_uploading and t.uploaded_session == 0)
96-
]
97-
98-
if args.downloading:
99-
torrents = [t for t in torrents if t.state_enum.is_downloading]
100-
elif args.uploading:
101-
torrents = [t for t in torrents if t.state_enum.is_uploading]
81+
return [t for t in torrents if t.downloaded_session > 0 and t.uploaded_session > 0]
82+
83+
if args.downloading:
84+
torrents = [t for t in torrents if not t.state_enum.is_complete]
85+
elif args.uploading:
86+
torrents = [t for t in torrents if t.state_enum.is_complete]
87+
if args.active:
88+
torrents = [
89+
t
90+
for t in torrents
91+
if (not t.state_enum.is_complete and t.downloaded_session > 0)
92+
or (t.state_enum.is_complete and t.uploaded_session > 0)
93+
]
94+
if args.inactive:
95+
torrents = [
96+
t
97+
for t in torrents
98+
if (not t.state_enum.is_complete and t.downloaded_session == 0)
99+
or (t.state_enum.is_complete and t.uploaded_session == 0)
100+
]
102101

103102
return torrents
104103

@@ -150,15 +149,15 @@ def shorten(s, width):
150149
torrents = sorted(
151150
torrents,
152151
key=lambda t: (
153-
t.downloaded if t.state_enum.is_downloading else t.uploaded,
154-
t.downloaded_session if t.state_enum.is_downloading else t.uploaded_session,
152+
t.downloaded if not t.state_enum.is_complete else t.uploaded,
153+
t.downloaded_session if not t.state_enum.is_complete else t.uploaded_session,
155154
),
156155
)
157156
elif args.inactive:
158157
torrents = sorted(
159158
torrents,
160159
key=lambda t: (
161-
t.state_enum.is_downloading,
160+
not t.state_enum.is_complete,
162161
t.eta if t.eta < 8640000 else 0,
163162
t.time_active * t.last_activity,
164163
),
@@ -167,7 +166,7 @@ def shorten(s, width):
167166
torrents = sorted(
168167
torrents,
169168
key=lambda t: (
170-
t.state_enum.is_downloading,
169+
not t.state_enum.is_complete,
171170
t.eta,
172171
t.completion_on,
173172
t.added_on,
@@ -180,8 +179,8 @@ def shorten(s, width):
180179
active_torrents = [
181180
t
182181
for t in torrents
183-
if (t.state_enum.is_downloading and t.downloaded_session > 0)
184-
or (t.state_enum.is_uploading and t.uploaded_session > 0)
182+
if (not t.state_enum.is_complete and t.downloaded_session > 0)
183+
or (t.state_enum.is_complete and t.uploaded_session > 0)
185184
]
186185
if active_torrents:
187186
print("Active Torrents")
@@ -192,14 +191,14 @@ def gen_row(t):
192191
"num_seeds": f"{t.num_seeds} ({t.num_complete})",
193192
"progress": strings.safe_percent(t.progress),
194193
}
195-
if t.state_enum.is_downloading:
194+
if not t.state_enum.is_complete:
196195
d |= {
197196
"downloaded_session": strings.file_size(t.downloaded_session),
198197
"remaining": strings.file_size(t.amount_left) if t.amount_left > 0 else None,
199198
"speed": strings.file_size(t.dlspeed) + "/s" if t.dlspeed else None,
200199
"eta": strings.duration_short(t.eta) if t.eta < 8640000 else None,
201200
}
202-
if t.state_enum.is_uploading:
201+
if t.state_enum.is_complete:
203202
d |= {
204203
"uploaded_session": strings.file_size(t.uploaded_session),
205204
"uploaded": strings.file_size(t.uploaded),
@@ -237,8 +236,8 @@ def gen_row(t):
237236
inactive_torrents = [
238237
t
239238
for t in torrents
240-
if (t.state_enum.is_downloading and t.downloaded_session == 0)
241-
or (t.state_enum.is_uploading and t.uploaded_session == 0)
239+
if (not t.state_enum.is_complete and t.downloaded_session == 0)
240+
or (t.state_enum.is_complete and t.uploaded_session == 0)
242241
]
243242
if inactive_torrents:
244243
print("Inactive Torrents")
@@ -252,12 +251,12 @@ def gen_row(t):
252251
"last_activity": strings.relative_datetime(t.last_activity),
253252
"time_active": strings.duration_short(t.time_active),
254253
}
255-
if t.state_enum.is_downloading:
254+
if not t.state_enum.is_complete:
256255
d |= {
257256
"downloaded": strings.file_size(t.downloaded),
258257
"remaining": strings.file_size(t.amount_left) if t.amount_left > 0 else None,
259258
}
260-
if t.state_enum.is_uploading:
259+
if t.state_enum.is_complete:
261260
d |= {
262261
"uploaded": strings.file_size(t.uploaded),
263262
}

library/playback/torrents_status.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def parse_args():
3535
"--file-counts", "--files", "--counts", action="store_true", help="Print file counts (a bit slow)"
3636
)
3737

38+
parser.add_argument("--all", action="store_true", help="Show active and inactive torrents")
3839
parser.add_argument("--active", action="store_true", help="Show active torrents")
3940
parser.add_argument("--inactive", "--dead", action="store_true", help="Show inactive torrents")
4041

@@ -47,6 +48,11 @@ def parse_args():
4748
args = parser.parse_args()
4849
arggroups.args_post(args, parser)
4950

51+
if set(["active", "inactive"]).issubset(args.defaults.keys()):
52+
if args.all or args.torrent_search or args.file_search:
53+
args.active = False
54+
args.inactive = False
55+
5056
return args
5157

5258

0 commit comments

Comments
 (0)