Beautify output from TorrentReactor

The data for <title> starts with a pretty long category in square brackets (eg. [Movies - DVD-R]) which makes the title uneasy to read in the results window. Also, added rev sorting by seeds.
This commit is contained in:
TheLegs 2013-12-04 00:53:01 +01:00
parent bb4b001fb6
commit ee44a01b76

View file

@ -1,8 +1,10 @@
import re import re
import socket import socket
from urllib2 import urlopen from urllib2 import urlopen
from operator import itemgetter
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
socket.setdefaulttimeout(15) socket.setdefaulttimeout(15)
class Search: class Search:
@ -60,12 +62,14 @@ class TorrentReactor(Search):
soup = BeautifulStoneSoup(f.read()) soup = BeautifulStoneSoup(f.read())
for item in soup.findAll('item'): 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+) seeders, (\d+) leecher', item.description.text)[0]
title = re.findall(r'\[(?:[^\]])*\] (.*)', item.title.text)[0]
torrents.append({ torrents.append({
'url': item.enclosure['url'], 'url': item.enclosure['url'],
'name': item.title.text, 'name': title,
'seeds': int(seeds), 'seeds': int(seeds),
'leechers': int(leechers), 'leechers': int(leechers),
}) })
torrents = sorted(torrents, key=itemgetter('seeds'), reverse=True)
return torrents return torrents
if __name__ == '__main__': if __name__ == '__main__':