mirror of
https://github.com/searx/searx
synced 2024-12-12 16:56:47 +01:00
Merge pull request #2763 from return42/add-bandcamp
Add Bandcamp search engine
This commit is contained in:
commit
59df3bec28
73
searx/engines/bandcamp.py
Normal file
73
searx/engines/bandcamp.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
"""
|
||||||
|
Bandcamp (Music)
|
||||||
|
|
||||||
|
@website https://bandcamp.com/
|
||||||
|
@provide-api no
|
||||||
|
@results HTML
|
||||||
|
@parse url, title, content, publishedDate, embedded, thumbnail
|
||||||
|
"""
|
||||||
|
|
||||||
|
from urllib.parse import urlencode, urlparse, parse_qs
|
||||||
|
from dateutil.parser import parse as dateparse
|
||||||
|
from lxml import html
|
||||||
|
from searx.utils import extract_text
|
||||||
|
|
||||||
|
categories = ['music']
|
||||||
|
paging = True
|
||||||
|
|
||||||
|
base_url = "https://bandcamp.com/"
|
||||||
|
search_string = search_string = 'search?{query}&page={page}'
|
||||||
|
embedded_url = '''<iframe width="100%" height="166"
|
||||||
|
scrolling="no" frameborder="no"
|
||||||
|
data-src="https://bandcamp.com/EmbeddedPlayer/{type}={result_id}/size=large/bgcol=ffffff/linkcol=0687f5/tracklist=false/artwork=small/transparent=true/"
|
||||||
|
></iframe>'''
|
||||||
|
|
||||||
|
|
||||||
|
def request(query, params):
|
||||||
|
'''pre-request callback
|
||||||
|
params<dict>:
|
||||||
|
method : POST/GET
|
||||||
|
headers : {}
|
||||||
|
data : {} # if method == POST
|
||||||
|
url : ''
|
||||||
|
category: 'search category'
|
||||||
|
pageno : 1 # number of the requested page
|
||||||
|
'''
|
||||||
|
|
||||||
|
search_path = search_string.format(
|
||||||
|
query=urlencode({'q': query}),
|
||||||
|
page=params['pageno'])
|
||||||
|
|
||||||
|
params['url'] = base_url + search_path
|
||||||
|
|
||||||
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
def response(resp):
|
||||||
|
'''post-response callback
|
||||||
|
resp: requests response object
|
||||||
|
'''
|
||||||
|
results = []
|
||||||
|
tree = html.fromstring(resp.text)
|
||||||
|
search_results = tree.xpath('//li[contains(@class, "searchresult")]')
|
||||||
|
for result in search_results:
|
||||||
|
link = result.xpath('.//div[@class="itemurl"]/a')[0]
|
||||||
|
result_id = parse_qs(urlparse(link.get('href')).query)["search_item_id"][0]
|
||||||
|
title = result.xpath('.//div[@class="heading"]/a/text()')
|
||||||
|
date = dateparse(result.xpath('//div[@class="released"]/text()')[0].replace("released ", ""))
|
||||||
|
content = result.xpath('.//div[@class="subhead"]/text()')
|
||||||
|
new_result = {
|
||||||
|
"url": extract_text(link),
|
||||||
|
"title": extract_text(title),
|
||||||
|
"content": extract_text(content),
|
||||||
|
"publishedDate": date,
|
||||||
|
}
|
||||||
|
thumbnail = result.xpath('.//div[@class="art"]/img/@src')
|
||||||
|
if thumbnail:
|
||||||
|
new_result['thumbnail'] = thumbnail[0]
|
||||||
|
if "album" in result.classes:
|
||||||
|
new_result["embedded"] = embedded_url.format(type='album', result_id=result_id)
|
||||||
|
elif "track" in result.classes:
|
||||||
|
new_result["embedded"] = embedded_url.format(type='track', result_id=result_id)
|
||||||
|
results.append(new_result)
|
||||||
|
return results
|
@ -197,6 +197,11 @@ engines:
|
|||||||
# engine : base
|
# engine : base
|
||||||
# shortcut : bs
|
# shortcut : bs
|
||||||
|
|
||||||
|
- name: bandcamp
|
||||||
|
engine: bandcamp
|
||||||
|
shortcut: bc
|
||||||
|
categories: music
|
||||||
|
|
||||||
- name : wikipedia
|
- name : wikipedia
|
||||||
engine : wikipedia
|
engine : wikipedia
|
||||||
shortcut : wp
|
shortcut : wp
|
||||||
|
BIN
searx/static/themes/oscar/img/icons/bandcamp.png
Normal file
BIN
searx/static/themes/oscar/img/icons/bandcamp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 919 B |
@ -13,10 +13,10 @@
|
|||||||
</div>
|
</div>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
{%- if result.img_src -%}
|
{%- if result.img_src or result.thumbnail -%}
|
||||||
<div class="container-fluid">{{- "" -}}
|
<div class="container-fluid">{{- "" -}}
|
||||||
<div class="row">{{- "" -}}
|
<div class="row">{{- "" -}}
|
||||||
<img src="{{ image_proxify(result.img_src) }}" title="{{ result.title|striptags }}" style="width: auto; max-height: 60px; min-height: 60px;" class="col-xs-2 col-sm-4 col-md-4 result-content">
|
<img src="{{ image_proxify(result.img_src or result.thumbnail) }}" title="{{ result.title|striptags }}" style="width: auto; max-height: 60px; min-height: 60px;" class="col-xs-2 col-sm-4 col-md-4 result-content">
|
||||||
{%- if result.content %}<p class="result-content col-xs-8 col-sm-8 col-md-8">{{ result.content|safe }}</p>{% endif -%}
|
{%- if result.content %}<p class="result-content col-xs-8 col-sm-8 col-md-8">{{ result.content|safe }}</p>{% endif -%}
|
||||||
</div>{{- "" -}}
|
</div>{{- "" -}}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user