Files
Jarvis/api/torrent.py
MrZaiko ee32057c0b
All checks were successful
Build and Deploy / build (push) Successful in 3m41s
Fix torrent api bug
2025-04-19 22:16:25 +02:00

35 lines
1.0 KiB
Python

#!/usr/bin/env python3
from qbittorrent import Client
class TorrentApi:
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")
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"],
"upspeed": torrent["upspeed"],
"dlspeed": torrent["dlspeed"],
"size": torrent["size"],
}
torrent_list.append(torrent_info)
return torrent_list