Fix torrent api bug
All checks were successful
Build and Deploy / build (push) Successful in 3m41s

This commit is contained in:
2025-04-19 22:16:25 +02:00
parent 29617a07a5
commit ee32057c0b
4 changed files with 98 additions and 50 deletions

View File

@@ -1,13 +1,13 @@
#!/usr/bin/env python3
from qbittorrent import Client
from torrent import TorrentApi
# Replace with your qBittorrent Web UI credentials
qb = Client('http://192.168.1.17:8112')
qb.login('admin', 'tMHNjrJr7nhjyhJrYsahi4anq2h6LJ')
torrent = TorrentApi("http://192.168.1.17:8112", "tMHNjrJr7nhjyhJrYsahi4anq2h6LJ")
# Retrieve all active torrents
torrents = qb.torrents(filter='downloading')
torrents = torrent.get_torrents()
# Print details of each active torrent
for torrent in torrents:
@@ -17,4 +17,4 @@ for torrent in torrents:
print(f"Download Speed: {torrent['dlspeed'] / 1024:.2f} KB/s")
print(f"Upload Speed: {torrent['upspeed'] / 1024:.2f} KB/s")
print(f"Size: {torrent['size'] / (1024 * 1024):.2f} MB")
print('-' * 40)
print("-" * 40)

View File

@@ -2,26 +2,33 @@
from qbittorrent import Client
class TorrentApi:
def __init__(self, ip, password, username='admin'):
def __init__(self, ip, password, username="admin"):
# Initialize the qBittorrent client
self.qb = Client(ip)
self.qb.login(username, password)
def get_torrents(self):
return self.get_filtered_torrents('all')
return self.get_filtered_torrents("all")
def get_filtered_torrents(self, state):
self.qb.login()
# Retrieve torrents filtered by the given state
torrents = self.qb.torrents(filter=state)
# Extract relevant information
torrent_list = []
for torrent in torrents:
torrent_info = {
'name': torrent['name'],
'state': torrent['state'],
'progress': torrent['progress'] * 100, # Convert to percentage
'eta': torrent['eta']
"name": torrent["name"],
"state": torrent["state"],
"progress": torrent["progress"] * 100, # Convert to percentage
"eta": torrent["eta"],
"upspeed": torrent["upspeed"],
"dlspeed": torrent["dlspeed"],
"size": torrent["size"],
}
torrent_list.append(torrent_info)
return torrent_list