.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
digbt.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3 DigBT (Videos, Music, Files)
4"""
5
6from urllib.parse import urljoin
7from lxml import html
8from searx.utils import extract_text, get_torrent_size
9
10# about
11about = {
12 "website": 'https://digbt.org',
13 "wikidata_id": None,
14 "official_api_documentation": None,
15 "use_official_api": False,
16 "require_api_key": False,
17 "results": 'HTML',
18}
19
20categories = ['videos', 'music', 'files']
21paging = True
22
23URL = 'https://digbt.org'
24SEARCH_URL = URL + '/search/{query}-time-{pageno}'
25FILESIZE = 3
26FILESIZE_MULTIPLIER = 4
27
28
29def request(query, params):
30 params['url'] = SEARCH_URL.format(query=query, pageno=params['pageno'])
31
32 return params
33
34
35def response(resp):
36 dom = html.fromstring(resp.text)
37 search_res = dom.xpath('.//td[@class="x-item"]')
38
39 if not search_res:
40 return []
41
42 results = []
43 for result in search_res:
44 url = urljoin(URL, result.xpath('.//a[@title]/@href')[0])
45 title = extract_text(result.xpath('.//a[@title]'))
46 content = extract_text(result.xpath('.//div[@class="files"]'))
47 files_data = extract_text(result.xpath('.//div[@class="tail"]')).split()
48 filesize = get_torrent_size(files_data[FILESIZE], files_data[FILESIZE_MULTIPLIER])
49 magnetlink = result.xpath('.//div[@class="tail"]//a[@class="title"]/@href')[0]
50
51 results.append(
52 {
53 'url': url,
54 'title': title,
55 'content': content,
56 'filesize': filesize,
57 'magnetlink': magnetlink,
58 'seed': 'N/A',
59 'leech': 'N/A',
60 'template': 'torrent.html',
61 }
62 )
63
64 return results
request(query, params)
Definition digbt.py:29