mirror of
https://github.com/zhaarey/AppleMusicDecrypt.git
synced 2025-10-23 15:11:06 +00:00
feat: add lock for rip_song to prevent OOM
This commit is contained in:
12
src/rip.py
12
src/rip.py
@@ -16,10 +16,13 @@ from src.types import GlobalAuthParams, Codec
|
||||
from src.url import Song, Album, URLType, Artist, Playlist
|
||||
from src.utils import check_song_exists, if_raw_atmos, playlist_write_song_index, get_codec_from_codec_id
|
||||
|
||||
task_lock = asyncio.Semaphore(16)
|
||||
|
||||
|
||||
@logger.catch
|
||||
async def rip_song(song: Song, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device,
|
||||
force_save: bool = False, specified_m3u8: str = "", playlist: PlaylistInfo = None):
|
||||
async with task_lock:
|
||||
logger.debug(f"Task of song id {song.id} was created")
|
||||
token = auth_params.anonymousAccessToken
|
||||
song_data = await get_song_info(song.id, token, song.storefront, config.region.language)
|
||||
@@ -45,10 +48,13 @@ async def rip_song(song: Song, auth_params: GlobalAuthParams, codec: str, config
|
||||
return
|
||||
if specified_m3u8:
|
||||
song_uri, keys, codec_id = await extract_media(specified_m3u8, codec, song_metadata,
|
||||
config.download.codecPriority, config.download.codecAlternative)
|
||||
config.download.codecPriority,
|
||||
config.download.codecAlternative)
|
||||
else:
|
||||
song_uri, keys, codec_id = await extract_media(song_data.attributes.extendedAssetUrls.enhancedHls, codec, song_metadata,
|
||||
config.download.codecPriority, config.download.codecAlternative)
|
||||
song_uri, keys, codec_id = await extract_media(song_data.attributes.extendedAssetUrls.enhancedHls, codec,
|
||||
song_metadata,
|
||||
config.download.codecPriority,
|
||||
config.download.codecAlternative)
|
||||
logger.info(f"Downloading song: {song_metadata.artist} - {song_metadata.title}")
|
||||
codec = get_codec_from_codec_id(codec_id)
|
||||
raw_song = await download_song(song_uri)
|
||||
|
||||
Reference in New Issue
Block a user