mirror of
https://github.com/glomatico/gamdl.git
synced 2025-01-22 11:18:39 +00:00
optimize stream_url
fetching for music videos
This commit is contained in:
parent
3ee0d28727
commit
42a17ca90f
31
gamdl/cli.py
31
gamdl/cli.py
@ -609,13 +609,24 @@ 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
|
||||||
)
|
)
|
||||||
logger.debug("Getting webplayback")
|
if music_video_id_alt == track_metadata["id"]:
|
||||||
webplayback = apple_music_api.get_webplayback(track_metadata["id"])
|
stream_url = (
|
||||||
stream_url_master = webplayback["hls-playlist-url"]
|
downloader_music_video.get_stream_url_from_itunes_page(
|
||||||
|
itunes_page
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logger.debug("Getting webplayback")
|
||||||
|
webplayback = apple_music_api.get_webplayback(
|
||||||
|
track_metadata["id"]
|
||||||
|
)
|
||||||
|
stream_url = (
|
||||||
|
downloader_music_video.get_stream_url_from_webplayback(
|
||||||
|
webplayback
|
||||||
|
)
|
||||||
|
)
|
||||||
logger.debug("Getting M3U8 data")
|
logger.debug("Getting M3U8 data")
|
||||||
m3u8_master_data = downloader_music_video.get_m3u8_master_data(
|
m3u8_data = downloader_music_video.get_m3u8_master_data(stream_url)
|
||||||
stream_url_master
|
|
||||||
)
|
|
||||||
tags = downloader_music_video.get_tags(
|
tags = downloader_music_video.get_tags(
|
||||||
music_video_id_alt,
|
music_video_id_alt,
|
||||||
itunes_page,
|
itunes_page,
|
||||||
@ -643,12 +654,8 @@ def main(
|
|||||||
else:
|
else:
|
||||||
logger.debug("Getting stream info")
|
logger.debug("Getting stream info")
|
||||||
stream_info_video, stream_info_audio = (
|
stream_info_video, stream_info_audio = (
|
||||||
downloader_music_video.get_stream_info_video(
|
downloader_music_video.get_stream_info_video(m3u8_data),
|
||||||
m3u8_master_data
|
downloader_music_video.get_stream_info_audio(m3u8_data),
|
||||||
),
|
|
||||||
downloader_music_video.get_stream_info_audio(
|
|
||||||
m3u8_master_data
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
decryption_key_video = downloader.get_decryption_key(
|
decryption_key_video = downloader.get_decryption_key(
|
||||||
stream_info_video.pssh, track_metadata["id"]
|
stream_info_video.pssh, track_metadata["id"]
|
||||||
|
@ -25,9 +25,18 @@ class DownloaderMusicVideo:
|
|||||||
self.downloader = downloader
|
self.downloader = downloader
|
||||||
self.codec = codec
|
self.codec = codec
|
||||||
|
|
||||||
def get_stream_url_master(self, webplayback: dict) -> str:
|
def get_stream_url_from_webplayback(self, webplayback: dict) -> str:
|
||||||
return webplayback["hls-playlist-url"]
|
return webplayback["hls-playlist-url"]
|
||||||
|
|
||||||
|
def get_stream_url_from_itunes_page(self, itunes_page: dict) -> dict:
|
||||||
|
stream_url = itunes_page["offers"][0]["assets"][0]["hlsUrl"]
|
||||||
|
url_parts = urllib.parse.urlparse(stream_url)
|
||||||
|
query = urllib.parse.parse_qs(url_parts.query, keep_blank_values=True)
|
||||||
|
query.update({"aec": "HD", "dsid": "1"})
|
||||||
|
return url_parts._replace(
|
||||||
|
query=urllib.parse.urlencode(query, doseq=True)
|
||||||
|
).geturl()
|
||||||
|
|
||||||
def get_m3u8_master_data(self, stream_url_master: str) -> dict:
|
def get_m3u8_master_data(self, stream_url_master: str) -> dict:
|
||||||
return m3u8.load(stream_url_master).data
|
return m3u8.load(stream_url_master).data
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user