2021-01-13 11:31:25 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2015-05-02 15:45:17 +02:00
|
|
|
"""
|
|
|
|
BTDigg (Videos, Music, Files)
|
|
|
|
"""
|
2015-01-21 18:02:29 +01:00
|
|
|
|
2020-08-06 17:42:46 +02:00
|
|
|
from urllib.parse import quote, urljoin
|
2024-03-11 07:45:08 +01:00
|
|
|
|
|
|
|
from lxml import html
|
2024-06-12 22:35:13 +02:00
|
|
|
from searx.utils import extract_text
|
2015-01-21 18:02:29 +01:00
|
|
|
|
2021-01-13 11:31:25 +01:00
|
|
|
# about
|
|
|
|
about = {
|
|
|
|
"website": 'https://btdig.com',
|
|
|
|
"wikidata_id": 'Q4836698',
|
2021-12-27 09:26:22 +01:00
|
|
|
"official_api_documentation": {'url': 'https://btdig.com/contacts', 'comment': 'on demand'},
|
2021-01-13 11:31:25 +01:00
|
|
|
"use_official_api": False,
|
|
|
|
"require_api_key": False,
|
|
|
|
"results": 'HTML',
|
|
|
|
}
|
|
|
|
|
2015-01-21 18:02:29 +01:00
|
|
|
# engine dependent config
|
2021-05-29 16:14:19 +02:00
|
|
|
categories = ['files']
|
2015-01-21 18:02:29 +01:00
|
|
|
paging = True
|
|
|
|
|
|
|
|
# search-url
|
2019-07-25 08:40:48 +02:00
|
|
|
url = 'https://btdig.com'
|
2015-01-25 10:21:44 +01:00
|
|
|
search_url = url + '/search?q={search_term}&p={pageno}'
|
2015-01-21 18:02:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
# do search-request
|
|
|
|
def request(query, params):
|
2021-12-27 09:26:22 +01:00
|
|
|
params['url'] = search_url.format(search_term=quote(query), pageno=params['pageno'] - 1)
|
2015-01-21 18:02:29 +01:00
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
# get response from search-request
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
|
2016-11-30 18:43:03 +01:00
|
|
|
dom = html.fromstring(resp.text)
|
2015-01-21 18:02:29 +01:00
|
|
|
|
2019-07-25 08:40:48 +02:00
|
|
|
search_res = dom.xpath('//div[@class="one_result"]')
|
2015-01-21 18:02:29 +01:00
|
|
|
|
|
|
|
# return empty array if nothing is found
|
|
|
|
if not search_res:
|
|
|
|
return []
|
|
|
|
|
|
|
|
# parse results
|
|
|
|
for result in search_res:
|
2019-07-25 08:40:48 +02:00
|
|
|
link = result.xpath('.//div[@class="torrent_name"]//a')[0]
|
2015-01-30 19:52:44 +01:00
|
|
|
href = urljoin(url, link.attrib.get('href'))
|
2016-12-09 11:44:24 +01:00
|
|
|
title = extract_text(link)
|
2015-01-21 18:02:29 +01:00
|
|
|
|
2019-07-25 08:40:48 +02:00
|
|
|
excerpt = result.xpath('.//div[@class="torrent_excerpt"]')[0]
|
|
|
|
content = html.tostring(excerpt, encoding='unicode', method='text', with_tail=False)
|
|
|
|
content = content.strip().replace('\n', ' | ')
|
|
|
|
content = ' '.join(content.split())
|
2015-01-21 18:02:29 +01:00
|
|
|
|
2024-06-12 22:35:13 +02:00
|
|
|
filesize = result.xpath('.//span[@class="torrent_size"]/text()')[0]
|
2019-07-25 08:40:48 +02:00
|
|
|
files = (result.xpath('.//span[@class="torrent_files"]/text()') or ['1'])[0]
|
2015-01-21 18:02:29 +01:00
|
|
|
|
|
|
|
# convert files to int if possible
|
2019-07-25 08:40:48 +02:00
|
|
|
try:
|
2015-01-21 18:02:29 +01:00
|
|
|
files = int(files)
|
2024-03-11 07:45:08 +01:00
|
|
|
except: # pylint: disable=bare-except
|
2015-01-21 18:02:29 +01:00
|
|
|
files = None
|
|
|
|
|
2019-07-25 08:40:48 +02:00
|
|
|
magnetlink = result.xpath('.//div[@class="torrent_magnet"]//a')[0].attrib['href']
|
2015-01-21 18:02:29 +01:00
|
|
|
|
|
|
|
# append result
|
2021-12-27 09:26:22 +01:00
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
'url': href,
|
|
|
|
'title': title,
|
|
|
|
'content': content,
|
|
|
|
'filesize': filesize,
|
|
|
|
'files': files,
|
|
|
|
'magnetlink': magnetlink,
|
|
|
|
'template': 'torrent.html',
|
|
|
|
}
|
|
|
|
)
|
2015-01-21 18:02:29 +01:00
|
|
|
|
|
|
|
# return results sorted by seeder
|
2019-07-25 08:40:48 +02:00
|
|
|
return results
|