mirror of
https://github.com/searxng/searxng.git
synced 2024-11-13 08:10:12 +01:00
Merge pull request #913 from return42/add-artwork
[mod] add artwork to mixcloud & soundcloud engines
This commit is contained in:
commit
8d937179ab
@ -1,11 +1,11 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
Mixcloud (Music)
|
||||
# lint: pylint
|
||||
"""Mixcloud (Music)
|
||||
|
||||
"""
|
||||
|
||||
from json import loads
|
||||
from dateutil import parser
|
||||
from urllib.parse import urlencode
|
||||
from dateutil import parser
|
||||
|
||||
# about
|
||||
about = {
|
||||
@ -26,38 +26,29 @@ url = 'https://api.mixcloud.com/'
|
||||
search_url = url + 'search/?{query}&type=cloudcast&limit=10&offset={offset}'
|
||||
iframe_src = "https://www.mixcloud.com/widget/iframe/?feed={url}"
|
||||
|
||||
# do search-request
|
||||
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 10
|
||||
|
||||
params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset)
|
||||
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
search_res = resp.json()
|
||||
|
||||
search_res = loads(resp.text)
|
||||
|
||||
# parse results
|
||||
for result in search_res.get('data', []):
|
||||
title = result['name']
|
||||
url = result['url']
|
||||
content = result['user']['name']
|
||||
|
||||
r_url = result['url']
|
||||
publishedDate = parser.parse(result['created_time'])
|
||||
res = {
|
||||
'url': r_url,
|
||||
'title': result['name'],
|
||||
'iframe_src': iframe_src.format(url=r_url),
|
||||
'img_src': result['pictures']['medium'],
|
||||
'publishedDate': publishedDate,
|
||||
'content': result['user']['name'],
|
||||
}
|
||||
results.append(res)
|
||||
|
||||
# append result
|
||||
results.append(
|
||||
{
|
||||
'url': url,
|
||||
'title': title,
|
||||
'iframe_src': iframe_src.format(url=url),
|
||||
'publishedDate': publishedDate,
|
||||
'content': content,
|
||||
}
|
||||
)
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
@ -81,27 +81,23 @@ def request(query, params):
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
search_res = loads(resp.text)
|
||||
|
||||
# parse results
|
||||
for result in search_res.get('collection', []):
|
||||
|
||||
if result['kind'] in ('track', 'playlist'):
|
||||
title = result['title']
|
||||
content = result['description'] or ''
|
||||
publishedDate = parser.parse(result['last_modified'])
|
||||
uri = quote_plus(result['uri'])
|
||||
res = {
|
||||
'url': result['permalink_url'],
|
||||
'title': result['title'],
|
||||
'content': result['description'] or '',
|
||||
'publishedDate': parser.parse(result['last_modified']),
|
||||
'iframe_src': "https://w.soundcloud.com/player/?url=" + uri,
|
||||
}
|
||||
img_src = result['artwork_url'] or result['user']['avatar_url']
|
||||
if img_src:
|
||||
res['img_src'] = img_src
|
||||
results.append(res)
|
||||
|
||||
# append result
|
||||
results.append(
|
||||
{
|
||||
'url': result['permalink_url'],
|
||||
'title': title,
|
||||
'publishedDate': publishedDate,
|
||||
'iframe_src': "https://w.soundcloud.com/player/?url=" + uri,
|
||||
'content': content,
|
||||
}
|
||||
)
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
Loading…
Reference in New Issue
Block a user