From fcbe596a80e1db0e0a0cdbd8bd871fdd2d25f84a Mon Sep 17 00:00:00 2001 From: Rafael Moraes <50295204+glomatico@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:50:19 -0300 Subject: [PATCH] refactor to use webplayback api to get the stream url instead of itunes page --- gamdl/cli.py | 6 +++--- gamdl/downloader_music_video.py | 12 +++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/gamdl/cli.py b/gamdl/cli.py index f4155fa..3ed374c 100644 --- a/gamdl/cli.py +++ b/gamdl/cli.py @@ -609,9 +609,9 @@ def main( itunes_page = itunes_api.get_itunes_page( "music-video", music_video_id_alt ) - stream_url_master = downloader_music_video.get_stream_url_master( - itunes_page - ) + logger.debug("Getting webplayback") + webplayback = apple_music_api.get_webplayback(track_metadata["id"]) + stream_url_master = webplayback["hls-playlist-url"] logger.debug("Getting M3U8 data") m3u8_master_data = downloader_music_video.get_m3u8_master_data( stream_url_master diff --git a/gamdl/downloader_music_video.py b/gamdl/downloader_music_video.py index 4bd2da5..0375cf4 100644 --- a/gamdl/downloader_music_video.py +++ b/gamdl/downloader_music_video.py @@ -25,17 +25,11 @@ class DownloaderMusicVideo: self.downloader = downloader self.codec = codec - def get_stream_url_master(self, itunes_page: dict) -> str: - return itunes_page["offers"][0]["assets"][0]["hlsUrl"] + def get_stream_url_master(self, webplayback: dict) -> str: + return webplayback["hls-playlist-url"] def get_m3u8_master_data(self, stream_url_master: str) -> dict: - url_parts = urllib.parse.urlparse(stream_url_master) - query = urllib.parse.parse_qs(url_parts.query, keep_blank_values=True) - query.update({"aec": "HD", "dsid": "1"}) - stream_url_master_new = url_parts._replace( - query=urllib.parse.urlencode(query, doseq=True) - ).geturl() - return m3u8.load(stream_url_master_new).data + return m3u8.load(stream_url_master).data def get_playlist_video( self,