mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 00:46:18 +00:00
Apply changes
This commit is contained in:
parent
8e2adf8fc8
commit
b662162ca7
@ -40,6 +40,9 @@ log_level = WARNING
|
||||
; Default: El La Le Las Les Los The
|
||||
index_ignored_prefixes = El La Le Las Les Los The
|
||||
|
||||
; Enable the ChartLyrics API. Default: off
|
||||
online_lyrics = off
|
||||
|
||||
[daemon]
|
||||
; Socket file the daemon will listen on for incoming management commands
|
||||
; Default: /tmp/supysonic/supysonic.sock
|
||||
|
@ -443,37 +443,39 @@ def lyrics():
|
||||
|
||||
return lyrics_response_for_track(track, lyrics)
|
||||
|
||||
# Create a stable, unique, filesystem-compatible identifier for the artist+title
|
||||
unique = hashlib.md5(
|
||||
json.dumps([x.lower() for x in (artist, title)]).encode("utf-8")
|
||||
).hexdigest()
|
||||
cache_key = f"lyrics-{unique}"
|
||||
|
||||
lyrics = {}
|
||||
try:
|
||||
lyrics = json.loads(
|
||||
zlib.decompress(current_app.cache.get_value(cache_key)).decode("utf-8")
|
||||
)
|
||||
except (CacheMiss, zlib.error, TypeError, ValueError):
|
||||
|
||||
if current_app.config["WEBAPP"]["online_lyrics"]:
|
||||
# Create a stable, unique, filesystem-compatible identifier for the artist+title
|
||||
unique = hashlib.md5(
|
||||
json.dumps([x.lower() for x in (artist, title)]).encode("utf-8")
|
||||
).hexdigest()
|
||||
cache_key = f"lyrics-{unique}"
|
||||
|
||||
try:
|
||||
r = requests.get(
|
||||
"http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect",
|
||||
params={"artist": artist, "song": title},
|
||||
timeout=5,
|
||||
lyrics = json.loads(
|
||||
zlib.decompress(current_app.cache.get_value(cache_key)).decode("utf-8")
|
||||
)
|
||||
root = ElementTree.fromstring(r.content)
|
||||
except (CacheMiss, zlib.error, TypeError, ValueError):
|
||||
try:
|
||||
r = requests.get(
|
||||
"http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect",
|
||||
params={"artist": artist, "song": title},
|
||||
timeout=5,
|
||||
)
|
||||
root = ElementTree.fromstring(r.content)
|
||||
|
||||
ns = {"cl": "http://api.chartlyrics.com/"}
|
||||
lyrics = {
|
||||
"artist": root.find("cl:LyricArtist", namespaces=ns).text,
|
||||
"title": root.find("cl:LyricSong", namespaces=ns).text,
|
||||
"value": root.find("cl:Lyric", namespaces=ns).text,
|
||||
}
|
||||
ns = {"cl": "http://api.chartlyrics.com/"}
|
||||
lyrics = {
|
||||
"artist": root.find("cl:LyricArtist", namespaces=ns).text,
|
||||
"title": root.find("cl:LyricSong", namespaces=ns).text,
|
||||
"value": root.find("cl:Lyric", namespaces=ns).text,
|
||||
}
|
||||
|
||||
current_app.cache.set(
|
||||
cache_key, zlib.compress(json.dumps(lyrics).encode("utf-8"), 9)
|
||||
)
|
||||
except requests.exceptions.RequestException as e: # pragma: nocover
|
||||
logger.warning("Error while requesting the ChartLyrics API: " + str(e))
|
||||
current_app.cache.set(
|
||||
cache_key, zlib.compress(json.dumps(lyrics).encode("utf-8"), 9)
|
||||
)
|
||||
except requests.exceptions.RequestException as e: # pragma: nocover
|
||||
logger.warning("Error while requesting the ChartLyrics API: " + str(e))
|
||||
|
||||
return request.formatter("lyrics", lyrics)
|
||||
|
@ -37,6 +37,7 @@ class DefaultConfig:
|
||||
"mount_webui": True,
|
||||
"mount_api": True,
|
||||
"index_ignored_prefixes": "El La Le Las Les Los The",
|
||||
"online_lyrics": False,
|
||||
}
|
||||
DAEMON = {
|
||||
"socket": r"\\.\pipe\supysonic"
|
||||
|
Loading…
Reference in New Issue
Block a user