mirror of
https://github.com/zhaarey/AppleMusicDecrypt.git
synced 2025-10-23 15:11:06 +00:00
fix: raise exception when unable to get lyrics
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from ssl import SSLError
|
||||
from typing import Optional
|
||||
|
||||
import httpx
|
||||
import regex
|
||||
@@ -167,7 +168,7 @@ async def get_song_info(song_id: str, token: str, storefront: str, lang: str):
|
||||
@retry(retry=retry_if_exception_type((httpx.HTTPError, SSLError, FileNotFoundError)),
|
||||
wait=wait_random_exponential(multiplier=1, max=60),
|
||||
stop=stop_after_attempt(retry_times), before_sleep=before_sleep_log(logger, logging.WARN))
|
||||
async def get_song_lyrics(song_id: str, storefront: str, token: str, dsid: str, account_token: str, lang: str) -> str:
|
||||
async def get_song_lyrics(song_id: str, storefront: str, token: str, dsid: str, account_token: str, lang: str) -> Optional[str]:
|
||||
async with request_lock:
|
||||
req = await client.get(f"https://amp-api.music.apple.com/v1/catalog/{storefront}/songs/{song_id}/lyrics",
|
||||
params={"l": lang},
|
||||
@@ -175,7 +176,10 @@ async def get_song_lyrics(song_id: str, storefront: str, token: str, dsid: str,
|
||||
"X-Dsid": dsid},
|
||||
cookies={f"mz_at_ssl-{dsid}": account_token})
|
||||
result = SongLyrics.model_validate(req.json())
|
||||
if result.data:
|
||||
return result.data[0].attributes.ttml
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@alru_cache
|
||||
|
||||
@@ -48,7 +48,10 @@ async def rip_song(song: Song, auth_params: GlobalAuthParams, codec: str, config
|
||||
f"Use storefront {auth_params.storefront.upper()} to get lyrics")
|
||||
lyrics = await get_song_lyrics(song.id, auth_params.storefront, auth_params.accountAccessToken,
|
||||
auth_params.dsid, auth_params.accountToken, config.region.language)
|
||||
if lyrics:
|
||||
song_metadata.lyrics = lyrics
|
||||
else:
|
||||
logger.warning(f"Unable to get lyrics of song: {song_metadata.artist} - {song_metadata.title}")
|
||||
if config.m3u8Api.enable and codec == Codec.ALAC and not specified_m3u8:
|
||||
m3u8_url = await get_m3u8_from_api(config.m3u8Api.endpoint, song.id, config.m3u8Api.enable)
|
||||
if m3u8_url:
|
||||
|
||||
Reference in New Issue
Block a user