@@ -0,0 +1,124 @@
1+# Yggtorrent (Videos, Music, Files)
3+# @website https://www2.yggtorrent.si
4+# @provide-api no (nothing found)
7+# @results HTML (using search portal)
8+# @stable no (HTML can change)
9+# @parse url, title, seed, leech, publishedDate, filesize
12+from operator import itemgetter
13+from datetime import datetime
14+from searx.engines.xpath import extract_text
15+from searx.url_utils import quote
16+from searx.utils import get_torrent_size
17+from searx.poolrequests import get as http_get
19+# engine dependent config
20+categories = ['videos', 'music', 'files']
24+url = 'https://www2.yggtorrent.si/'
25+search_url = url + 'engine/search?name={search_term}&do=search&page={pageno}&category={search_type}'
27+# yggtorrent specific type-definitions
28+search_types = {'files': 'all',
35+def init(engine_settings=None):
38+ resp = http_get(url, allow_redirects=False)
40+ for r in resp.history:
41+ cookies.update(r.cookies)
42+ cookies.update(resp.cookies)
46+def request(query, params):
47+ search_type = search_types.get(params['category'], 'all')
48+ pageno = (params['pageno'] - 1) * 50
50+ params['url'] = search_url.format(search_term=quote(query),
51+ search_type=search_type,
54+ params['cookies'] = cookies
59+# get response from search-request
62+ dom = html.fromstring(resp.text)
64+ search_res = dom.xpath('//section[@id="#torrents"]/div/table/tbody/tr')
66+ # return empty array if nothing is found
71+ for result in search_res:
72+ link = result.xpath('.//a[@id="torrent_name"]')[0]
73+ href = link.attrib.get('href')
74+ title = extract_text(link)
75+ seed = result.xpath('.//td[8]/text()')[0]
76+ leech = result.xpath('.//td[9]/text()')[0]
78+ # convert seed to int if possible
84+ # convert leech to int if possible
90+ params = {'url': href,
94+ 'template': 'torrent.html'}
96+ # let's try to calculate the torrent size
98+ filesize_info = result.xpath('.//td[6]/text()')[0]
99+ filesize = filesize_info[:-2]
100+ filesize_multiplier = filesize_info[-2:].lower()
101+ multiplier_french_to_english = {
107+ filesize = get_torrent_size(filesize, multiplier_french_to_english[filesize_multiplier])
108+ params['filesize'] = filesize
112+ # extract and convert creation date
114+ date_ts = result.xpath('.//td[5]/div/text()')[0]
115+ date = datetime.fromtimestamp(float(date_ts))
116+ params['publishedDate'] = date
121+ results.append(params)
123+ # return results sorted by seeder
124+ return sorted(results, key=itemgetter('seed'), reverse=True)