From 30aeee90b81d7acfbf32c3e84206b963d9e9dea6 Mon Sep 17 00:00:00 2001 From: Rafael Moraes <50295204+glomatico@users.noreply.github.com> Date: Wed, 20 May 2026 16:57:50 -0300 Subject: [PATCH] Add use_cenc and use_single_content_key to StreamInfo --- gamdl/interface/song.py | 28 ++++++++++++++++++++-------- gamdl/interface/types.py | 3 ++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/gamdl/interface/song.py b/gamdl/interface/song.py index 05fc2b5..1ce1d61 100644 --- a/gamdl/interface/song.py +++ b/gamdl/interface/song.py @@ -311,7 +311,7 @@ class AppleMusicSongInterface: log.debug("no_matching_playlist", codec=codec.value) return None - stream_info = StreamInfo(legacy=False) + stream_info = StreamInfo(use_single_content_key=False) stream_info.stream_url = ( f"{m3u8_master_url.rpartition('/')[0]}/{playlist['uri']}" ) @@ -448,17 +448,29 @@ class AppleMusicSongInterface: ) -> StreamInfoAv: log = logger.bind(action="get_web_song_stream_info") - flavor = "32:ctrp64" if codec == SongCodec.AAC_HE_WEB else "28:ctrp256" + flavor = codec.flavor - stream_info = StreamInfo(web_song_codec=True) - stream_info.stream_url = next( - i for i in webplayback["songList"][0]["assets"] if i["flavor"] == flavor - )["URL"] + stream_info = StreamInfo( + use_cenc=codec.is_cenc, + ) + asset = next( + (i for i in webplayback["songList"][0]["assets"] if i["flavor"] == flavor), + None, + ) + if not asset: + log.debug("no_matching_asset", codec=codec.value, flavor=flavor) + return None + + stream_info.stream_url = asset["URL"] m3u8_obj = m3u8.loads( (await self.base.get_response(stream_info.stream_url)).text ) - stream_info.widevine_pssh = m3u8_obj.keys[0].uri + + if stream_info.use_cenc: + stream_info.widevine_pssh = m3u8_obj.keys[0].uri + else: + stream_info.fairplay_key = m3u8_obj.keys[0].uri stream_info_av = StreamInfoAv( media_id=webplayback["songList"][0]["songId"], @@ -542,7 +554,7 @@ class AppleMusicSongInterface: ) or ( self.base.use_wrapper and not media.stream_info.audio_track.fairplay_key - and not media.stream_info.audio_track.web_song_codec + and not media.stream_info.audio_track.use_cenc ): raise GamdlInterfaceDecryptionNotAvailableError(media_id=media.media_id) diff --git a/gamdl/interface/types.py b/gamdl/interface/types.py index 6654f31..d428b82 100644 --- a/gamdl/interface/types.py +++ b/gamdl/interface/types.py @@ -122,7 +122,8 @@ class StreamInfo: codec: str = None width: int = None height: int = None - web_song_codec: bool = False + use_cenc: bool = False + use_single_content_key: bool = True @dataclass