Skip to content

Commit

Permalink
refactor to use webplayback api to get the stream url instead of itun…
Browse files Browse the repository at this point in the history
…es page
  • Loading branch information
glomatico committed Aug 30, 2024
1 parent acd5fef commit fcbe596
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
6 changes: 3 additions & 3 deletions gamdl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions gamdl/downloader_music_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,11 @@ def __init__(
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,
Expand Down

0 comments on commit fcbe596

Please sign in to comment.