Skip to content

Commit

Permalink
Support for latest qbittorrent
Browse files Browse the repository at this point in the history
- fix direct upload
- fix stop start actions
- fix web selection progress incase file size is zero

Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Dec 16, 2024
1 parent a92d14b commit 8ab6c9c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
8 changes: 4 additions & 4 deletions bot/helper/listeners/qbit_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def _on_download_error(err, tor, button=None):
ext_hash = tor.hash
if task := await get_task_by_gid(ext_hash[:12]):
await task.listener.on_download_error(err, button)
await sync_to_async(qbittorrent_client.torrents_pause, torrent_hashes=ext_hash)
await sync_to_async(qbittorrent_client.torrents_stop, torrent_hashes=ext_hash)
await sleep(0.3)
await _remove_torrent(ext_hash, tor.tags)

Expand Down Expand Up @@ -70,7 +70,7 @@ async def _on_download_complete(tor):
if task := await get_task_by_gid(ext_hash[:12]):
if not task.listener.seed:
await sync_to_async(
qbittorrent_client.torrents_pause, torrent_hashes=ext_hash
qbittorrent_client.torrents_stop, torrent_hashes=ext_hash
)
if task.listener.select:
await clean_unwanted(task.listener.dir)
Expand Down Expand Up @@ -180,15 +180,15 @@ async def _qb_listener():
"No enough space for this torrent on device", tor_info
)
elif (
tor_info.completion_on != 0
tor_info.completion_on != -1
and not qb_torrents[tag]["uploaded"]
and state
not in ["checkingUP", "checkingDL", "checkingResumeData"]
):
qb_torrents[tag]["uploaded"] = True
await _on_download_complete(tor_info)
elif (
state in ["pausedUP", "pausedDL"]
state in ["stoppedUP", "stoppedDL"]
and qb_torrents[tag]["seeding"]
):
qb_torrents[tag]["seeding"] = False
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/mirror_leech_utils/download_utils/qbit_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
if tor_info.state not in [
"metaDL",
"checkingResumeData",
"pausedDL",
"stoppedDL",
]:
await delete_message(meta)
break
Expand All @@ -116,7 +116,7 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
ext_hash = tor_info.hash
if not add_to_queue:
await sync_to_async(
qbittorrent_client.torrents_pause, torrent_hashes=ext_hash
qbittorrent_client.torrents_stop, torrent_hashes=ext_hash
)
SBUTTONS = bt_selection_buttons(ext_hash)
msg = "Your download paused. Choose files then press Done Selecting button to start downloading."
Expand All @@ -135,7 +135,7 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
f"Start Queued Download from Qbittorrent: {tor_info.name} - Hash: {ext_hash}"
)
await sync_to_async(
qbittorrent_client.torrents_resume, torrent_hashes=ext_hash
qbittorrent_client.torrents_start, torrent_hashes=ext_hash
)

except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_leech_utils/status_utils/qbit_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def status(self):
return MirrorStatus.STATUS_QUEUEDL
elif state == "queuedUP":
return MirrorStatus.STATUS_QUEUEUP
elif state in ["pausedDL", "pausedUP"]:
elif state in ["stoppedDL", "stoppedUP"]:
return MirrorStatus.STATUS_PAUSED
elif state in ["checkingUP", "checkingDL"]:
return MirrorStatus.STATUS_CHECK
Expand Down Expand Up @@ -96,7 +96,7 @@ async def cancel_task(self):
self.listener.is_cancelled = True
await sync_to_async(self.update)
await sync_to_async(
qbittorrent_client.torrents_pause, torrent_hashes=self._info.hash
qbittorrent_client.torrents_stop, torrent_hashes=self._info.hash
)
if not self.seeding:
if self.queued:
Expand Down
4 changes: 2 additions & 2 deletions bot/modules/file_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def select(_, message):
await sync_to_async(task.update)
id_ = task.hash()
await sync_to_async(
qbittorrent_client.torrents_pause, torrent_hashes=id_
qbittorrent_client.torrents_stop, torrent_hashes=id_
)
elif not task.queued:
await sync_to_async(task.update)
Expand Down Expand Up @@ -143,7 +143,7 @@ async def get_confirm(_, query):
pass
if not task.queued:
await sync_to_async(
qbittorrent_client.torrents_resume, torrent_hashes=id_
qbittorrent_client.torrents_start, torrent_hashes=id_
)
else:
res = await sync_to_async(aria2.client.get_files, id_)
Expand Down
22 changes: 14 additions & 8 deletions web/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,34 @@ def make_tree(res, tool=False):
folder_id += 1
else:
previous_node = current_node
try:
progress = round((int(i["completedLength"]) / int(i["length"])) * 100, 5)
except:
progress = 0
TorNode(
folders[-1],
is_file=True,
parent=previous_node,
size=float(i["length"]),
size=int(i["length"]),
priority=priority,
file_id=i["index"],
progress=round(
(int(i["completedLength"]) / int(i["length"])) * 100, 5
),
progress=progress,
)
else:
try:
progress = round(
(int(i["completedLength"]) / int(i["length"])) * 100, 5
)
except:
progress = 0
TorNode(
folders[-1],
is_file=True,
parent=parent,
size=float(i["length"]),
size=int(i["length"]),
priority=priority,
file_id=i["index"],
progress=round(
(int(i["completedLength"]) / int(i["length"])) * 100, 5
),
progress=progress,
)

result = create_list(parent)
Expand Down

0 comments on commit 8ab6c9c

Please sign in to comment.