Returing the best option for torrents based on max peers/seeds and

returning more metadata info on torrent.search
This commit is contained in:
Fabio Manganiello 2019-03-05 00:10:06 +01:00
parent 619c750f3b
commit dcb0555571

View file

@ -72,14 +72,24 @@ class TorrentPlugin(Plugin):
if isinstance(response, bytes): if isinstance(response, bytes):
response = response.decode('utf-8') response = response.decode('utf-8')
return [ results = []
{
'url': _['items'][0]['torrent_magnet'],
'title': _['title'],
}
for _ in json.loads(response).get('MovieList', []) for result in json.loads(response).get('MovieList', []):
] torrent = sorted(result['items'], key=lambda _:
_['torrent_seeds'] + _['torrent_peers'])[-1]
results.append({
'title': result['title'],
'url': torrent['torrent_magnet'],
'file': torrent['file'],
'size': torrent['size_bytes'],
'language': torrent.get('language'),
'quality': torrent.get('quality'),
'torrent_url': torrent['torrent_url'],
'torrent_seeds': torrent['torrent_seeds'],
'torrent_peers': torrent['torrent_peers'],
})
return results
@action @action
def download(self, torrent, download_dir=None): def download(self, torrent, download_dir=None):