From 839703c03497c57fdd1bd32ba009d04ccee3be04 Mon Sep 17 00:00:00 2001 From: Cory Marshall Date: Tue, 24 Nov 2020 09:45:01 -0400 Subject: [PATCH] Retreive streaming data for 256 kbps AAC Adding the parameters c=WEB_REMIX and cver=0.1 to the get_video_info request in get_song() returns a streamingData adaptiveFormat of itag 141, audioQuality of AUDIO_QUALITY_HIGH, a 256 kbps AAC m4a for authenticated requests from YouTube Music Premium subscribers. Unfortunately, these parameters result in player_response['videoDetails']['shortDescription'] not being returned, the information in which contains useful song metadata. player_response['microformat']['microformatDataRenderer']['description'] is returned, but it seems to be a truncated version of shortDescription, so the metadata parsing in get_song() does not work on that response. Therefore, a second get_video_info request is made with the updated parameters and the metadata in song_meta is copied in to the new player_response['videoDetails'], which is returned from get_song() instead of song_meta. --- ytmusicapi/mixins/browsing.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ytmusicapi/mixins/browsing.py b/ytmusicapi/mixins/browsing.py index 11f53cb..baa8cc1 100644 --- a/ytmusicapi/mixins/browsing.py +++ b/ytmusicapi/mixins/browsing.py @@ -550,4 +550,15 @@ class BrowsingMixin: except (KeyError, IndexError): pass song_meta['streamingData'] = player_response['streamingData'] - return song_meta + params.update({"c": "WEB_REMIX", "cver": "0.1"}) + response = requests.get(endpoint, params, headers=self.headers, proxies=self.proxies) + text = parse_qs(response.text) + if 'player_response' not in text: + return text + player_response = json.loads(text['player_response'][0]) + player_response['videoDetails']['provider'] = song_meta['provider'] + player_response['videoDetails']['artists'] = song_meta['artists'] + player_response['videoDetails']['copyright'] = song_meta['copyright'] + player_response['videoDetails']['release'] = song_meta['release'] + player_response['videoDetails']['production'] = song_meta['production'] + return player_response