mirror of
https://github.com/zhaarey/AppleMusicDecrypt.git
synced 2025-10-23 15:11:06 +00:00
add select Sampling rate
This commit is contained in:
@@ -85,6 +85,10 @@ saveLyrics = true
|
|||||||
saveCover = true
|
saveCover = true
|
||||||
coverFormat = "jpg"
|
coverFormat = "jpg"
|
||||||
coverSize = "5000x5000"
|
coverSize = "5000x5000"
|
||||||
|
# 192000 96000 48000 44100
|
||||||
|
alacMax = 192000
|
||||||
|
# 2768 2448
|
||||||
|
atmosMax = 2768
|
||||||
# The command to be executed after the song is ripped successfully, passing in the filename parameter.
|
# The command to be executed after the song is ripped successfully, passing in the filename parameter.
|
||||||
# Example: "\"C:\\Program Files\\DAUM\\PotPlayer\\PotPlayerMini64.exe\" \"{filename}\""
|
# Example: "\"C:\\Program Files\\DAUM\\PotPlayer\\PotPlayerMini64.exe\" \"{filename}\""
|
||||||
# Pay attention to escaping issues
|
# Pay attention to escaping issues
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ class Download(BaseModel):
|
|||||||
saveCover: bool
|
saveCover: bool
|
||||||
coverFormat: str
|
coverFormat: str
|
||||||
coverSize: str
|
coverSize: str
|
||||||
|
alacMax: int
|
||||||
|
atmosMax: int
|
||||||
afterDownloaded: str
|
afterDownloaded: str
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ async def get_available_codecs(m3u8_url: str) -> Tuple[list[str], list[str]]:
|
|||||||
|
|
||||||
|
|
||||||
async def extract_media(m3u8_url: str, codec: str, song_metadata: SongMetadata,
|
async def extract_media(m3u8_url: str, codec: str, song_metadata: SongMetadata,
|
||||||
codec_priority: list[str], alternative_codec: bool = False) -> Tuple[str, list[str], str, Optional[int], Optional[int]]:
|
codec_priority: list[str], alternative_codec: bool = False, alacMax: Optional[int] = None, atmosMax: Optional[int] = None) -> Tuple[str, list[str], str, Optional[int], Optional[int]]:
|
||||||
parsed_m3u8 = m3u8.loads(await download_m3u8(m3u8_url), uri=m3u8_url)
|
parsed_m3u8 = m3u8.loads(await download_m3u8(m3u8_url), uri=m3u8_url)
|
||||||
specifyPlaylist = find_best_codec(parsed_m3u8, codec)
|
specifyPlaylist = find_best_codec(parsed_m3u8, codec, alacMax, atmosMax)
|
||||||
if not specifyPlaylist and alternative_codec:
|
if not specifyPlaylist and alternative_codec:
|
||||||
logger.warning(f"Codec {codec} of song: {song_metadata.artist} - {song_metadata.title} did not found")
|
logger.warning(f"Codec {codec} of song: {song_metadata.artist} - {song_metadata.title} did not found")
|
||||||
for a_codec in codec_priority:
|
for a_codec in codec_priority:
|
||||||
specifyPlaylist = find_best_codec(parsed_m3u8, a_codec)
|
specifyPlaylist = find_best_codec(parsed_m3u8, a_codec, alacMax, atmosMax)
|
||||||
if specifyPlaylist:
|
if specifyPlaylist:
|
||||||
codec = a_codec
|
codec = a_codec
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -77,11 +77,11 @@ async def rip_song(song: Song, auth_params: GlobalAuthParams, codec: str, config
|
|||||||
logger.info(f"Use m3u8 from device for song: {song_metadata.artist} - {song_metadata.title}")
|
logger.info(f"Use m3u8 from device for song: {song_metadata.artist} - {song_metadata.title}")
|
||||||
if specified_m3u8:
|
if specified_m3u8:
|
||||||
song_uri, keys, codec_id, bit_depth, sample_rate = await extract_media(
|
song_uri, keys, codec_id, bit_depth, sample_rate = await extract_media(
|
||||||
specified_m3u8, codec, song_metadata, config.download.codecPriority, config.download.codecAlternative)
|
specified_m3u8, codec, song_metadata, config.download.codecPriority, config.download.codecAlternative, config.download.alacMax, config.download.alacMax)
|
||||||
else:
|
else:
|
||||||
song_uri, keys, codec_id, bit_depth, sample_rate = await extract_media(
|
song_uri, keys, codec_id, bit_depth, sample_rate = await extract_media(
|
||||||
song_data.attributes.extendedAssetUrls.enhancedHls, codec, song_metadata,
|
song_data.attributes.extendedAssetUrls.enhancedHls, codec, song_metadata,
|
||||||
config.download.codecPriority, config.download.codecAlternative)
|
config.download.codecPriority, config.download.codecAlternative, config.download.alacMax, config.download.atmosMax)
|
||||||
if all([bool(bit_depth), bool(sample_rate)]):
|
if all([bool(bit_depth), bool(sample_rate)]):
|
||||||
song_metadata.set_bit_depth_and_sample_rate(bit_depth, sample_rate)
|
song_metadata.set_bit_depth_and_sample_rate(bit_depth, sample_rate)
|
||||||
if not force_save and check_song_exists(song_metadata, config.download, codec, playlist):
|
if not force_save and check_song_exists(song_metadata, config.download, codec, playlist):
|
||||||
|
|||||||
18
src/utils.py
18
src/utils.py
@@ -36,12 +36,24 @@ def byte_length(i):
|
|||||||
return (i.bit_length() + 7) // 8
|
return (i.bit_length() + 7) // 8
|
||||||
|
|
||||||
|
|
||||||
def find_best_codec(parsed_m3u8: m3u8.M3U8, codec: str) -> Optional[m3u8.Playlist]:
|
def find_best_codec(parsed_m3u8: m3u8.M3U8, codec: str, alacMax, atmosMax) -> Optional[m3u8.Playlist]:
|
||||||
available_medias = [playlist for playlist in parsed_m3u8.playlists
|
available_medias = []
|
||||||
if regex.match(CodecRegex.get_pattern_by_codec(codec), playlist.stream_info.audio)]
|
for playlist in parsed_m3u8.playlists:
|
||||||
|
if regex.match(CodecRegex.get_pattern_by_codec(codec), playlist.stream_info.audio):
|
||||||
|
split_str = playlist.stream_info.audio.split('-')
|
||||||
|
if "alac" in playlist.stream_info.audio:
|
||||||
|
if int(split_str[3]) <= alacMax:
|
||||||
|
available_medias.append(playlist)
|
||||||
|
elif "atmos" in playlist.stream_info.audio:
|
||||||
|
if int(split_str[2]) <= atmosMax:
|
||||||
|
available_medias.append(playlist)
|
||||||
|
else:
|
||||||
|
available_medias.append(playlist)
|
||||||
|
|
||||||
if not available_medias:
|
if not available_medias:
|
||||||
return None
|
return None
|
||||||
available_medias.sort(key=lambda x: x.stream_info.average_bandwidth, reverse=True)
|
available_medias.sort(key=lambda x: x.stream_info.average_bandwidth, reverse=True)
|
||||||
|
|
||||||
return available_medias[0]
|
return available_medias[0]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user