From 675631b83c5fe55541ce34cfe7fe5c9c861c1ead Mon Sep 17 00:00:00 2001 From: sCoruja Date: Sat, 20 Apr 2019 19:58:55 +0300 Subject: [PATCH] added classes for get_files method --- app/utorrentapi.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/utorrentapi.py b/app/utorrentapi.py index 6c0aaf7..b1fdde3 100644 --- a/app/utorrentapi.py +++ b/app/utorrentapi.py @@ -58,7 +58,19 @@ def __init__(self, data): self.torrents = [TorrentInfo(x) for x in data['torrents']] self.torrent_cache_id = data['torrentc'] +class FileInfo: + def __init__(self, data): + self.name = data[0] + self.size = data[1] + self.downloaded = data[2] + self.priority = data[3] +class FileListInfo: + def __init__(self, data): + self.build = data['build'] + self.hash = data['files'][0] + self.files = [FileInfo(x) for x in data['files'][1]] + class UTorrentAPI(object): def __init__(self, base_url, username, password): @@ -109,7 +121,7 @@ def get_list(self): try: status, response = self._action('list=1') if status == 200: - torrents = response.json() + torrents = TorrentListInfo(response.json()) else: print(response.status_code) @@ -127,7 +139,7 @@ def get_files(self, torrentid): files = [] if status == 200: - files = response.json() + files = FileListInfo(response.json()) else: print(response.status_code)