Commit 3fd2cbc2 authored by prx's avatar prx

torrent9 en parallèle

parent bcda0895
......@@ -558,41 +558,47 @@ class TorrentSearch:
leechs = str()
for i in soup.find_all('tbody'):
for d in i.find_all('td'):
if d.find('a'):
href = d.find('a')['href']
# le titre est dans des <span>...
name = [ s.string for s in d.a.find_all('span') ]
name = ' '.join(name)
else:
if len(size) == 0:
size = d.string
elif len(seeds) == 0:
seeds = d.string
elif len(leechs) == 0:
leechs = d.string
# get magnet link
ms = do_req_get("{}/{}".format(baseurl,href), "text")
magnetsoup = bs4.BeautifulSoup(ms, "html.parser")
for m in magnetsoup.find_all('a', class_='download'):
if m['href'].startswith('magnet'):
magnet = m['href']
break
if name != "" and magnet != "" and size != "" and seeds != "" and leechs != "":
if sys.version_info < (3, 0):
magnet = magnet.encode('utf-8')
name = name.encode('utf-8')
size = size.encode('utf-8')
d = {'name': name, 'magnet': magnet, 'size': size, 'seeds': seeds, "leechs": leechs}
name = str()
magnet = str()
size = str()
seeds = str()
leechs = str()
yield(d)
with ThreadPoolExecutor(max_workers=5) as executor:
for res in executor.map(torrent9_parse_results, i.find_all('td')):
yield res
def torrent9_parse_results(d):
baseurl = 'http://www.torrent9.ws'
name = str()
magnet = str()
size = str()
seeds = str()
leechs = str()
if d.find('a'):
href = d.find('a')['href']
# le titre est dans des <span>...
name = [ s.string for s in d.a.find_all('span') ]
name = ' '.join(name)
# get magnet link
ms = do_req_get("{}/{}".format(baseurl,href), "text")
magnetsoup = bs4.BeautifulSoup(ms, "html.parser")
for m in magnetsoup.find_all('a', class_='download'):
if m['href'].startswith('magnet'):
magnet = m['href']
break
else:
if len(size) == 0:
size = d.string
elif len(seeds) == 0:
seeds = d.string
elif len(leechs) == 0:
leechs = d.string
if sys.version_info < (3, 0):
magnet = magnet.encode('utf-8')
name = name.encode('utf-8')
size = size.encode('utf-8')
res = {'name': name, 'magnet': magnet, 'size': size, 'seeds': seeds, "leechs": leechs}
return res
def isohunt_parse_results(z):
"""
......@@ -629,7 +635,7 @@ def isohunt_parse_results(z):
if __name__ == '__main__':
with TorrentSearch('torrent9') as ts:
s = ts.search('orange is the new black vostfr', 0)
s = ts.search('orange is the new black', 0)
print(s)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment