Commit d7756ed8 authored by prx's avatar prx

ajout torrent9

parent ff17d100
......@@ -288,7 +288,7 @@ def watchlist(user):
def create_select_search_engine(selected):
#list_search_engines = ["btdigg", "kickasstorrents", "piratebay", "torrentproject", tpl_msg['tpl_all']]
list_search_engines = ["kickasstorrents", "piratebay", "isohunt", tpl_msg['tpl_all']]
list_search_engines = ["kickasstorrents", "piratebay", "isohunt", "torrent9", tpl_msg['tpl_all']]
list_html = str()
for search_engine in list_search_engines:
......
......@@ -26,11 +26,11 @@ def do_req_get(url, ret, keys=None, headers=None):
retval = ''
try:
retval = requests.get(url, params=keys, headers=headers)
req = requests.get(url, params=keys, headers=headers)
if ret == "text":
retval = retval.text
retval = req.text
elif ret == "json":
retval = retval.json()
retval = req.json()
except Exception as e:
logging.info(e)
if ret == "text":
......@@ -38,6 +38,7 @@ def do_req_get(url, ret, keys=None, headers=None):
elif ret == "json":
retval = {}
finally:
req.close()
return retval
......@@ -268,10 +269,12 @@ class TorrentSearch:
s = [res for res in self._kickasstorrents(sch)]
elif self.searchengine == 'isohunt':
s = [res for res in self._isohunt(sch)]
elif self.searchengine == 'torrent9':
s = [res for res in self._torrent9(sch)]
elif self.searchengine == '*':
s = self._search_all(sch)
else:
s = [res for res in self._btdigg(sch, 0)]
s = [res for res in self._piratebay(sch, 0)]
except:
s = []
......@@ -279,7 +282,7 @@ class TorrentSearch:
def _search_all(self, sch):
s = []
searchengine_list = [self._piratebay, self._kickasstorrents, self._isohunt]
searchengine_list = [self._piratebay, self._kickasstorrents, self._isohunt, self._torrent9]
if sys.version_info >= (3, 0):
with ThreadPoolExecutor(max_workers=5) as e:
for searchengine in searchengine_list:
......@@ -290,6 +293,7 @@ class TorrentSearch:
s += [res for res in self._piratebay(sch)]
s += [res for res in self._kickasstorrents(sch)]
s += [res for res in self._isohunt(sch)]
s += [res for res in self._torrent9(sch)]
return s
......@@ -538,6 +542,62 @@ class TorrentSearch:
for z in zip(row, seeds_results, size_results):
yield(isohunt_parse_results(z))
def _torrent9(self, sch, page=0):
"""
Return:
List of dictionnaries with keys :
name : torrent name
magnet : magnet link
size : size
seed : number of seeds
"""
thesch = sch.replace(' ', '-')
baseurl = 'http://www.torrent9.ws'
url = '{}/search_torrent/{}.html'.format(baseurl,thesch)
s = do_req_get(url, "text")
soup = bs4.BeautifulSoup(s, "html.parser")
name = str()
magnet = str()
size = str()
seeds = str()
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)
def isohunt_parse_results(z):
"""
......@@ -573,8 +633,8 @@ def isohunt_parse_results(z):
if __name__ == '__main__':
with TorrentSearch('kickasstorrents') as ts:
s = ts.search('flash', 0)
with TorrentSearch('torrent9') as ts:
s = ts.search('orange is the new black vostfr', 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