refactor to use webplayback api to get the stream url instead of itunes page

This commit is contained in:
Rafael Moraes 2024-08-29 22:50:19 -03:00
parent acd5fefb76
commit fcbe596a80
2 changed files with 6 additions and 12 deletions

View File

@ -609,9 +609,9 @@ def main(
itunes_page = itunes_api.get_itunes_page( itunes_page = itunes_api.get_itunes_page(
"music-video", music_video_id_alt "music-video", music_video_id_alt
) )
stream_url_master = downloader_music_video.get_stream_url_master( logger.debug("Getting webplayback")
itunes_page webplayback = apple_music_api.get_webplayback(track_metadata["id"])
) stream_url_master = webplayback["hls-playlist-url"]
logger.debug("Getting M3U8 data") logger.debug("Getting M3U8 data")
m3u8_master_data = downloader_music_video.get_m3u8_master_data( m3u8_master_data = downloader_music_video.get_m3u8_master_data(
stream_url_master stream_url_master

View File

@ -25,17 +25,11 @@ class DownloaderMusicVideo:
self.downloader = downloader self.downloader = downloader
self.codec = codec self.codec = codec
def get_stream_url_master(self, itunes_page: dict) -> str: def get_stream_url_master(self, webplayback: dict) -> str:
return itunes_page["offers"][0]["assets"][0]["hlsUrl"] return webplayback["hls-playlist-url"]
def get_m3u8_master_data(self, stream_url_master: str) -> dict: def get_m3u8_master_data(self, stream_url_master: str) -> dict:
url_parts = urllib.parse.urlparse(stream_url_master) return m3u8.load(stream_url_master).data
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
def get_playlist_video( def get_playlist_video(
self, self,