[mod] add artwork to mixcloud & soundcloud engines

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2022-02-19 21:27:20 +01:00
parent 883e9c1ddd
commit 2921d3cd17
2 changed files with 29 additions and 42 deletions

View File

@ -1,11 +1,11 @@
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
""" # lint: pylint
Mixcloud (Music) """Mixcloud (Music)
""" """
from json import loads
from dateutil import parser
from urllib.parse import urlencode from urllib.parse import urlencode
from dateutil import parser
# about # about
about = { about = {
@ -26,38 +26,29 @@ url = 'https://api.mixcloud.com/'
search_url = url + 'search/?{query}&type=cloudcast&limit=10&offset={offset}' search_url = url + 'search/?{query}&type=cloudcast&limit=10&offset={offset}'
iframe_src = "https://www.mixcloud.com/widget/iframe/?feed={url}" iframe_src = "https://www.mixcloud.com/widget/iframe/?feed={url}"
# do search-request
def request(query, params): def request(query, params):
offset = (params['pageno'] - 1) * 10 offset = (params['pageno'] - 1) * 10
params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset) params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset)
return params return params
# get response from search-request
def response(resp): def response(resp):
results = [] results = []
search_res = resp.json()
search_res = loads(resp.text)
# parse results
for result in search_res.get('data', []): for result in search_res.get('data', []):
title = result['name']
url = result['url'] r_url = result['url']
content = result['user']['name']
publishedDate = parser.parse(result['created_time']) publishedDate = parser.parse(result['created_time'])
res = {
# append result 'url': r_url,
results.append( 'title': result['name'],
{ 'iframe_src': iframe_src.format(url=r_url),
'url': url, 'img_src': result['pictures']['medium'],
'title': title,
'iframe_src': iframe_src.format(url=url),
'publishedDate': publishedDate, 'publishedDate': publishedDate,
'content': content, 'content': result['user']['name'],
} }
) results.append(res)
# return results
return results return results

View File

@ -81,27 +81,23 @@ def request(query, params):
# get response from search-request # get response from search-request
def response(resp): def response(resp):
results = [] results = []
search_res = loads(resp.text) search_res = loads(resp.text)
# parse results # parse results
for result in search_res.get('collection', []): for result in search_res.get('collection', []):
if result['kind'] in ('track', 'playlist'): if result['kind'] in ('track', 'playlist'):
title = result['title']
content = result['description'] or ''
publishedDate = parser.parse(result['last_modified'])
uri = quote_plus(result['uri']) uri = quote_plus(result['uri'])
res = {
# append result
results.append(
{
'url': result['permalink_url'], 'url': result['permalink_url'],
'title': title, 'title': result['title'],
'publishedDate': publishedDate, 'content': result['description'] or '',
'publishedDate': parser.parse(result['last_modified']),
'iframe_src': "https://w.soundcloud.com/player/?url=" + uri, 'iframe_src': "https://w.soundcloud.com/player/?url=" + uri,
'content': content,
} }
) img_src = result['artwork_url'] or result['user']['avatar_url']
if img_src:
res['img_src'] = img_src
results.append(res)
# return results
return results return results