Ponysearch/searx/engines/acgsou.py

75 lines
2.4 KiB
Python
Raw Normal View History

# SPDX-License-Identifier: AGPL-3.0-or-later
2018-04-26 21:42:31 +02:00
"""
Acgsou (Japanese Animation/Music/Comics Bittorrent tracker)
"""
from urllib.parse import urlencode
2018-04-26 21:42:31 +02:00
from lxml import html
from searx.utils import extract_text, get_torrent_size, eval_xpath_list, eval_xpath_getindex
2018-04-26 21:42:31 +02:00
# about
about = {
"website": 'https://www.acgsou.com/',
"wikidata_id": None,
"official_api_documentation": None,
"use_official_api": False,
"require_api_key": False,
"results": 'HTML',
}
2018-04-26 21:42:31 +02:00
# engine dependent config
categories = ['files', 'images', 'videos', 'music']
paging = True
# search-url
base_url = 'https://www.acgsou.com/'
2018-04-26 21:42:31 +02:00
search_url = base_url + 'search.php?{query}&page={offset}'
# xpath queries
xpath_results = '//table[contains(@class, "list_style table_fixed")]//tr[not(th)]'
xpath_category = './/td[2]/a[1]'
xpath_title = './/td[3]/a[last()]'
xpath_torrent_links = './/td[3]/a'
xpath_filesize = './/td[4]/text()'
2018-04-27 07:29:17 +02:00
2018-04-26 21:42:31 +02:00
def request(query, params):
query = urlencode({'keyword': query})
params['url'] = search_url.format(query=query, offset=params['pageno'])
return params
2018-04-27 07:29:17 +02:00
2018-04-26 21:42:31 +02:00
def response(resp):
2018-04-27 07:36:11 +02:00
results = []
2018-04-26 21:42:31 +02:00
dom = html.fromstring(resp.text)
for result in eval_xpath_list(dom, xpath_results):
2018-04-26 21:42:31 +02:00
# defaults
filesize = 0
magnet_link = "magnet:?xt=urn:btih:{}&tr=https://tracker.acgsou.com:2710/announce"
2018-04-26 21:42:31 +02:00
category = extract_text(eval_xpath_getindex(result, xpath_category, 0, default=[]))
page_a = eval_xpath_getindex(result, xpath_title, 0)
2018-04-26 21:42:31 +02:00
title = extract_text(page_a)
href = base_url + page_a.attrib.get('href')
2018-04-27 07:23:58 +02:00
2018-04-26 21:42:31 +02:00
magnet_link = magnet_link.format(page_a.attrib.get('href')[5:-5])
filesize_info = eval_xpath_getindex(result, xpath_filesize, 0, default=None)
if filesize_info:
try:
filesize = filesize_info[:-2]
filesize_multiplier = filesize_info[-2:]
filesize = get_torrent_size(filesize, filesize_multiplier)
except:
pass
2018-04-27 14:36:15 +02:00
# I didn't add download/seed/leech count since as I figured out they are generated randomly everytime
content = 'Category: "{category}".'
2018-04-26 21:42:31 +02:00
content = content.format(category=category)
2018-04-27 07:29:17 +02:00
2018-04-26 21:42:31 +02:00
results.append({'url': href,
'title': title,
'content': content,
'filesize': filesize,
'magnetlink': magnet_link,
'template': 'torrent.html'})
return results