@@ -24,6 +24,7 @@ search_url = url + 'search/{search_term}/{pageno}/'
2424
2525# specific xpath variables
2626magnet_xpath = './/a[@title="Torrent magnet link"]'
27+torrent_xpath = './/a[@title="Download torrent file"]'
2728content_xpath = './/span[@class="font11px lightgrey block"]'
2829
2930
@@ -60,6 +61,9 @@ def response(resp):
6061 method="text"))
6162 seed = result.xpath('.//td[contains(@class, "green")]/text()')[0]
6263 leech = result.xpath('.//td[contains(@class, "red")]/text()')[0]
64+ filesize = result.xpath('.//td[contains(@class, "nobr")]/text()')[0]
65+ filesize_multiplier = result.xpath('.//td[contains(@class, "nobr")]//span/text()')[0]
66+ files = result.xpath('.//td[contains(@class, "center")][2]/text()')[0]
6367
6468 # convert seed to int if possible
6569 if seed.isdigit():
@@ -73,7 +77,31 @@ def response(resp):
7377 else:
7478 leech = 0
7579
80+ # convert filesize to byte if possible
81+ try:
82+ filesize = float(filesize)
83+
84+ # convert filesize to byte
85+ if filesize_multiplier == 'TB':
86+ filesize = int(filesize * 1024*1024*1024*1024)
87+ elif filesize_multiplier == 'GB':
88+ filesize = int(filesize * 1024*1024*1024)
89+ elif filesize_multiplier == 'MB':
90+ filesize = int(filesize * 1024*1024)
91+ elif filesize_multiplier == 'kb':
92+ filesize = int(filesize * 1024)
93+ except:
94+ filesize = None
95+
96+ # convert files to int if possible
97+ if files.isdigit():
98+ files = int(files)
99+ else:
100+ files = None
101+
76102 magnetlink = result.xpath(magnet_xpath)[0].attrib['href']
103+
104+ torrentfile = result.xpath(torrent_xpath)[0].attrib['href']
77105
78106 # append result
79107 results.append({'url': href,
@@ -81,7 +109,10 @@ def response(resp):
81109 'content': content,
82110 'seed': seed,
83111 'leech': leech,
112+ 'filesize': filesize,
113+ 'files': files,
84114 'magnetlink': magnetlink,
115+ 'torrentfile':torrentfile,
85116 'template': 'torrent.html'})
86117
87118 # return results sorted by seeder