This commit is contained in:
2025-04-06 11:38:10 +02:00
commit b7ba40b4da
7 changed files with 234 additions and 0 deletions

27
api/torrent.py Normal file
View File

@@ -0,0 +1,27 @@
#!/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):
# 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']
}
torrent_list.append(torrent_info)
return torrent_list