Skip to content

Commit 6f8af4d

Browse files
committed
torrent-start: fix MissingRequiredParameters400Error
1 parent 5105fb5 commit 6f8af4d

File tree

6 files changed

+58
-4
lines changed

6 files changed

+58
-4
lines changed

xklb/createdb/torrents_add.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def extract_metadata(path):
6969
{
7070
"path": f.name,
7171
"size": f.length,
72+
"time_deleted": 0,
7273
}
7374
for f in torrent.files
7475
],

xklb/mediafiles/torrents_start.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def wait_torrent_loaded(qbt_client, torrent):
3737
v1_info_hash = hashlib.sha1(Bencode.encode(torrent._struct.get("info"))).hexdigest()
3838
v2_info_hash = hashlib.sha256(Bencode.encode(torrent._struct.get("info"))).hexdigest()
3939

40-
attempts = 120
40+
# TODO: sometimes torrentool and qBittorrent come up with different info_hashes...
41+
42+
attempts = 10
4143
attempt = 0
4244
while attempt < attempts:
4345
with suppress(qbittorrentapi.NotFound404Error):
@@ -109,6 +111,7 @@ def torrents_start():
109111
qbt_client.app_set_preferences(
110112
{
111113
"preallocate_all": True,
114+
"add_stopped_enabled": False,
112115
"dl_limit": args.dl_limit,
113116
"up_limit": args.up_limit,
114117
"max_active_downloads": 1,
@@ -117,8 +120,8 @@ def torrents_start():
117120
"max_active_checking_torrents": 3,
118121
"slow_torrent_inactive_timer": 80,
119122
# divide by 10 but also some bps -> kbps BS
120-
"slow_torrent_dl_rate_threshold": (args.dl_limit) // 10000, # type: ignore
121-
"slow_torrent_ul_rate_threshold": (args.up_limit or args.dl_limit) // 10000, # type: ignore
123+
"slow_torrent_dl_rate_threshold": (args.dl_limit) // 10_000, # type: ignore
124+
"slow_torrent_ul_rate_threshold": (args.up_limit or args.dl_limit) // 10_000, # type: ignore
122125
}
123126
)
124127

@@ -150,7 +153,8 @@ def torrents_start():
150153
)
151154

152155
info_hash = wait_torrent_loaded(qbt_client, torrent)
153-
qbt_client.torrents_start(info_hash)
156+
if info_hash:
157+
qbt_client.torrents_start(info_hash)
154158

155159
if args.delete_torrent:
156160
trash(args, path)

xklb/multidb/allocate_torrents.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def allocate_torrents():
169169
ssh.load_system_host_keys()
170170
ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
171171
ssh.connect(d["host"])
172+
setattr(ssh, "host", d["host"])
172173

173174
remote_processes.cmd(
174175
ssh,

xklb/playback/torrents_info.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from xklb import usage
33
from xklb.mediafiles import torrents_start
44
from xklb.utils import arggroups, argparse_utils, consts, iterables, printing, processes, strings
5+
from xklb.utils.path_utils import domain_from_url
56

67

78
def parse_args():
@@ -67,6 +68,15 @@ def torrents_info():
6768
for torrent in all_torrents:
6869
torrents_by_state.setdefault(torrent.state, []).append(torrent)
6970

71+
torrents_by_tracker = {}
72+
for torrent in all_torrents:
73+
tracker = torrent.tracker
74+
if not tracker:
75+
tracker = iterables.safe_unpack(
76+
tr.url for tr in qbt_client.torrents_trackers(torrent.hash) if tr.url.startswith("http")
77+
)
78+
torrents_by_tracker.setdefault(domain_from_url(tracker), []).append(torrent)
79+
7080
interesting_states = [
7181
"stoppedUP",
7282
"queuedUP",
@@ -136,6 +146,33 @@ def torrents_info():
136146
printing.table(tbl)
137147
print()
138148

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

xklb/usage.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,13 @@ def play(action) -> str:
19061906
Create a SQLite database of torrent file data (torrents are playlists, referenced files are media)
19071907
19081908
library torrents-add torrents.db ~/.local/data/qbittorrent/queue/
1909+
1910+
View total size of undownloaded torrents
1911+
1912+
library playlists torrents.db -pa
1913+
path deleted_count size playlists_count media_count
1914+
---------------------- --------------- -------- ----------------- -------------
1915+
Aggregate of playlists 0 87.7 TiB 530 272681
19091916
"""
19101917

19111918

xklb/utils/remote_processes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def print_std(s, is_success):
5555
_stdin, stdout, stderr = ssh.exec_command(command, **kwargs)
5656
returncode = stdout.channel.recv_exit_status()
5757

58+
host = getattr(ssh, "host", None)
59+
if host:
60+
command = " ".join(["ssh", host, command])
61+
5862
r = subprocess.CompletedProcess(command, returncode, stdout.read().decode(), stderr.read().decode())
5963

6064
if cleanup_local_files and local_files:

0 commit comments

Comments
 (0)