.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.nyaa Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['files']
 
bool paging = True
 
str base_url = 'https://nyaa.si/'
 
str xpath_results = '//table[contains(@class, "torrent-list")]//tr[not(th)]'
 
str xpath_category = './/td[1]/a[1]'
 
str xpath_title = './/td[2]/a[last()]'
 
str xpath_torrent_links = './/td[3]/a'
 
str xpath_filesize = './/td[4]/text()'
 
str xpath_seeds = './/td[6]/text()'
 
str xpath_leeches = './/td[7]/text()'
 
str xpath_downloads = './/td[8]/text()'
 

Detailed Description

Nyaa.si (Anime Bittorrent tracker)

Function Documentation

◆ request()

searx.engines.nyaa.request ( query,
params )

Definition at line 44 of file nyaa.py.

44def request(query, params):
45 args = urlencode(
46 {
47 'q': query,
48 'p': params['pageno'],
49 }
50 )
51 params['url'] = base_url + '?' + args #
52 logger.debug("query_url --> %s", params['url'])
53 return params
54
55
56# get response from search-request

◆ response()

searx.engines.nyaa.response ( resp)

Definition at line 57 of file nyaa.py.

57def response(resp):
58 results = []
59
60 dom = html.fromstring(resp.text)
61
62 for result in dom.xpath(xpath_results):
63 # defaults
64 filesize = 0
65 magnet_link = ""
66 torrent_link = ""
67
68 # category in which our torrent belongs
69
70 category = eval_xpath_getindex(result, xpath_category, 0, '')
71 if category:
72 category = category.attrib.get('title')
73
74 # torrent title
75 page_a = result.xpath(xpath_title)[0]
76 title = extract_text(page_a)
77
78 # link to the page
79 href = base_url + page_a.attrib.get('href')
80
81 for link in result.xpath(xpath_torrent_links):
82 url = link.attrib.get('href')
83 if 'magnet' in url:
84 # link to the magnet
85 magnet_link = url
86 else:
87 # link to the torrent file
88 torrent_link = url
89
90 # seed count
91 seed = int_or_zero(result.xpath(xpath_seeds))
92
93 # leech count
94 leech = int_or_zero(result.xpath(xpath_leeches))
95
96 # torrent downloads count
97 downloads = int_or_zero(result.xpath(xpath_downloads))
98
99 # let's try to calculate the torrent size
100
101 filesize = eval_xpath_getindex(result, xpath_filesize, 0, '')
102
103 # content string contains all information not included into template
104 content = 'Category: "{category}". Downloaded {downloads} times.'
105 content = content.format(category=category, downloads=downloads)
106
107 results.append(
108 {
109 'url': href,
110 'title': title,
111 'content': content,
112 'seed': seed,
113 'leech': leech,
114 'filesize': filesize,
115 'torrentfile': torrent_link,
116 'magnetlink': magnet_link,
117 'template': 'torrent.html',
118 }
119 )
120
121 return results

Variable Documentation

◆ about

dict searx.engines.nyaa.about
Initial value:
1= {
2 "website": 'https://nyaa.si/',
3 "wikidata_id": None,
4 "official_api_documentation": None,
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 16 of file nyaa.py.

◆ base_url

str searx.engines.nyaa.base_url = 'https://nyaa.si/'

Definition at line 30 of file nyaa.py.

◆ categories

list searx.engines.nyaa.categories = ['files']

Definition at line 26 of file nyaa.py.

◆ paging

bool searx.engines.nyaa.paging = True

Definition at line 27 of file nyaa.py.

◆ xpath_category

str searx.engines.nyaa.xpath_category = './/td[1]/a[1]'

Definition at line 34 of file nyaa.py.

◆ xpath_downloads

str searx.engines.nyaa.xpath_downloads = './/td[8]/text()'

Definition at line 40 of file nyaa.py.

◆ xpath_filesize

str searx.engines.nyaa.xpath_filesize = './/td[4]/text()'

Definition at line 37 of file nyaa.py.

◆ xpath_leeches

str searx.engines.nyaa.xpath_leeches = './/td[7]/text()'

Definition at line 39 of file nyaa.py.

◆ xpath_results

str searx.engines.nyaa.xpath_results = '//table[contains(@class, "torrent-list")]//tr[not(th)]'

Definition at line 33 of file nyaa.py.

◆ xpath_seeds

str searx.engines.nyaa.xpath_seeds = './/td[6]/text()'

Definition at line 38 of file nyaa.py.

◆ xpath_title

str searx.engines.nyaa.xpath_title = './/td[2]/a[last()]'

Definition at line 35 of file nyaa.py.

◆ xpath_torrent_links

str searx.engines.nyaa.xpath_torrent_links = './/td[3]/a'

Definition at line 36 of file nyaa.py.