mirror of
https://github.com/correl/Transmission-XBMC.git
synced 2025-01-04 20:16:26 +00:00
Fix and beautify output from TorrentReactor
re.findall is looking for "seeders" while in fact the output shows "seeder", this is now working. Also, item.title.text has a prefix showing the category (eg. "[Movies - DVD-R]") which makes it uneasy to read in the results dialog, so this has been stripped off. Finally, the results are being rev sorted by seeds to promote the most popular entries.
This commit is contained in:
parent
bb4b001fb6
commit
dca825294e
1 changed files with 6 additions and 2 deletions
|
@ -1,8 +1,10 @@
|
|||
import re
|
||||
import socket
|
||||
from urllib2 import urlopen
|
||||
from operator import itemgetter
|
||||
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
|
||||
|
||||
|
||||
socket.setdefaulttimeout(15)
|
||||
|
||||
class Search:
|
||||
|
@ -59,13 +61,15 @@ class TorrentReactor(Search):
|
|||
f = urlopen(url)
|
||||
soup = BeautifulStoneSoup(f.read())
|
||||
for item in soup.findAll('item'):
|
||||
(seeds, leechers) = re.findall('Status: (\d+) seeders, (\d+) leecher', item.description.text)[0]
|
||||
(seeds, leechers) = re.findall('Status: (\d+) seeder, (\d+) leecher', item.description.text)[0]
|
||||
title = re.findall(r'\[(?:[^\]])*\] (.*)', item.title.text)[0]
|
||||
torrents.append({
|
||||
'url': item.enclosure['url'],
|
||||
'name': item.title.text,
|
||||
'name': title,
|
||||
'seeds': int(seeds),
|
||||
'leechers': int(leechers),
|
||||
})
|
||||
torrents = sorted(torrents, key=itemgetter('seeds'), reverse=True)
|
||||
return torrents
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue