Add bandcamp engine
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simon Bruder 2019-08-06 17:54:26 +00:00
parent 2370ea9d69
commit 0f7483140a
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F
2 changed files with 55 additions and 0 deletions

42
engines/bandcamp.py Normal file
View file

@ -0,0 +1,42 @@
from lxml import html
from searx.engines.xpath import extract_text
from searx.url_utils import quote
categories = ['music']
url = ' https://bandcamp.com/search'
search_url = url + '?q={query}&page={pageno}'
def clean_url(url):
return url.split('?')[0]
def request(query, params):
params['url'] = search_url.format(query=quote(query), pageno=params['pageno'])
return params
def response(resp):
results = []
dom = html.fromstring(resp.text.encode('utf-8'))
for result in dom.xpath('//li[starts-with(@class, "searchresult")]'):
result_info = result.xpath('div[@class="result-info"]')[0]
result_type = extract_text(result_info.xpath('div[@class="itemtype"]/text()')).capitalize()
if result_type == 'Fan':
continue
title = extract_text(result_info.xpath('div[@class="heading"]/a/text()'))
subhead = extract_text(result_info.xpath('div[@class="subhead"]/text()'))
href = clean_url(result_info.xpath('div[@class="heading"]/a/@href')[0])
image = result.xpath('a[@class="artcont"]/div[@class="art"]/img/@src')[0]
results.append({'url': href,
'title': title,
'image': image,
'subhead': subhead,
'type': result_type,
'template': 'bandcamp.html'})
return results

View file

@ -0,0 +1,13 @@
{% from 'oscar/macros.html' import result_link, result_footer, result_footer_rtl%}
<h4 class="result_header">
{% if result.image %}<img width="32" height="32" class="favicon" src="{{ image_proxify(result.image) }}">{% endif %}
{{ result_link(result.url, result.title|safe) }}
</h4>
<span class="text-muted">{{ result.type }}; {{ result.subhead }}</span>
{% if rtl %}
{{ result_footer_rtl(result) }}
{% else %}
{{ result_footer(result) }}
{% endif %}