@@ -0,0 +1,75 @@
1+"""
2+ Acgsou (Japanese Animation/Music/Comics Bittorrent tracker)
3+
4+ @website https://www.acgsou.com/
5+ @provide-api no
6+ @using-api no
7+ @results HTML
8+ @stable no (HTML can change)
9+ @parse url, title, content, seed, leech, torrentfile
10+"""
11+
12+from lxml import html
13+from searx.engines.xpath import extract_text
14+from searx.url_utils import urlencode
15+from searx.utils import get_torrent_size, int_or_zero
16+
17+# engine dependent config
18+categories = ['files', 'images', 'videos', 'music']
19+paging = True
20+
21+# search-url
22+base_url = 'https://www.acgsou.com/'
23+search_url = base_url + 'search.php?{query}&page={offset}'
24+# xpath queries
25+xpath_results = '//table[contains(@class, "list_style table_fixed")]//tr[not(th)]'
26+xpath_category = './/td[2]/a[1]'
27+xpath_title = './/td[3]/a[last()]'
28+xpath_torrent_links = './/td[3]/a'
29+xpath_filesize = './/td[4]/text()'
30+
31+
32+def request(query, params):
33+ query = urlencode({'keyword': query})
34+ params['url'] = search_url.format(query=query, offset=params['pageno'])
35+ return params
36+
37+
38+def response(resp):
39+ results = []
40+ dom = html.fromstring(resp.text)
41+ for result in dom.xpath(xpath_results):
42+ # defaults
43+ filesize = 0
44+ magnet_link = "magnet:?xt=urn:btih:{}&tr=http://tracker.acgsou.com:2710/announce"
45+ torrent_link = ""
46+
47+ try:
48+ category = extract_text(result.xpath(xpath_category)[0])
49+ except:
50+ pass
51+
52+ page_a = result.xpath(xpath_title)[0]
53+ title = extract_text(page_a)
54+ href = base_url + page_a.attrib.get('href')
55+
56+ magnet_link = magnet_link.format(page_a.attrib.get('href')[5:-5])
57+
58+ try:
59+ filesize_info = result.xpath(xpath_filesize)[0]
60+ filesize = filesize_info[:-2]
61+ filesize_multiplier = filesize_info[-2:]
62+ filesize = get_torrent_size(filesize, filesize_multiplier)
63+ except:
64+ pass
65+ # I didn't add download/seed/leech count since as I figured out they are generated randomly everytime
66+ content = 'Category: "{category}".'
67+ content = content.format(category=category)
68+
69+ results.append({'url': href,
70+ 'title': title,
71+ 'content': content,
72+ 'filesize': filesize,
73+ 'magnetlink': magnet_link,
74+ 'template': 'torrent.html'})
75+ return results