mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 20:17:45 +01:00
Merge pull request #93 from return42/genius-misc
Some minor Genius improvements
This commit is contained in:
commit
32b5a0ef7b
@ -1,12 +1,17 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""
|
# lint: pylint
|
||||||
Genius
|
# pylint: disable=invalid-name, missing-function-docstring
|
||||||
|
"""Genius
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from json import loads
|
from json import loads
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from searx import logger
|
||||||
|
logger = logger.getChild('genius engine')
|
||||||
|
|
||||||
# about
|
# about
|
||||||
about = {
|
about = {
|
||||||
"website": 'https://genius.com/',
|
"website": 'https://genius.com/',
|
||||||
@ -27,49 +32,54 @@ search_url = url + 'search/{index}?{query}&page={pageno}&per_page={page_size}'
|
|||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
params['url'] = search_url.format(query=urlencode({'q': query}),
|
params['url'] = search_url.format(
|
||||||
index='multi',
|
query=urlencode({'q': query}),
|
||||||
page_size=page_size,
|
index='multi',
|
||||||
pageno=params['pageno'])
|
page_size=page_size,
|
||||||
|
pageno=params['pageno'],
|
||||||
|
)
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
def parse_lyric(hit):
|
def parse_lyric(hit):
|
||||||
try:
|
try:
|
||||||
content = hit['highlights'][0]['value']
|
content = hit['highlights'][0]['value']
|
||||||
except:
|
except Exception as e: # pylint: disable=broad-except
|
||||||
|
logger.error(e, exc_info=True)
|
||||||
content = ''
|
content = ''
|
||||||
timestamp = hit['result']['lyrics_updated_at']
|
timestamp = hit['result']['lyrics_updated_at']
|
||||||
result = {'url': hit['result']['url'],
|
result = {
|
||||||
'title': hit['result']['full_title'],
|
'url': hit['result']['url'],
|
||||||
'content': content,
|
'title': hit['result']['full_title'],
|
||||||
'thumbnail': hit['result']['song_art_image_thumbnail_url'],
|
'content': content,
|
||||||
'template': 'videos.html'}
|
'thumbnail': hit['result']['song_art_image_thumbnail_url'],
|
||||||
|
}
|
||||||
if timestamp:
|
if timestamp:
|
||||||
result.update({'publishedDate': datetime.fromtimestamp(timestamp)})
|
result.update({'publishedDate': datetime.fromtimestamp(timestamp)})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def parse_artist(hit):
|
def parse_artist(hit):
|
||||||
result = {'url': hit['result']['url'],
|
result = {
|
||||||
'title': hit['result']['name'],
|
'url': hit['result']['url'],
|
||||||
'content': '',
|
'title': hit['result']['name'],
|
||||||
'thumbnail': hit['result']['image_url'],
|
'content': '',
|
||||||
'template': 'videos.html'}
|
'thumbnail': hit['result']['image_url'],
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def parse_album(hit):
|
def parse_album(hit):
|
||||||
result = {'url': hit['result']['url'],
|
result = {
|
||||||
'title': hit['result']['full_title'],
|
'url': hit['result']['url'],
|
||||||
'thumbnail': hit['result']['cover_art_url'],
|
'title': hit['result']['full_title'],
|
||||||
'content': '',
|
'thumbnail': hit['result']['cover_art_url'],
|
||||||
# 'thumbnail': hit['result']['cover_art_thumbnail_url'],
|
'content': '',
|
||||||
'template': 'videos.html'}
|
}
|
||||||
try:
|
try:
|
||||||
year = hit['result']['release_date_components']['year']
|
year = hit['result']['release_date_components']['year']
|
||||||
except:
|
except Exception as e: # pylint: disable=broad-except
|
||||||
pass
|
logger.error(e, exc_info=True)
|
||||||
else:
|
else:
|
||||||
if year:
|
if year:
|
||||||
result.update({'content': 'Released: {}'.format(year)})
|
result.update({'content': 'Released: {}'.format(year)})
|
||||||
|
Loading…
Reference in New Issue
Block a user