import subprocess, json def execute(command): return subprocess.check_output(command, shell = True).decode('utf-8') def getJSON(command): return json.loads(execute(command)) SAPISIDHASH = 'CENSORED' SECURE_3PSID = 'CENSORED' SECURE_3PAPISID = 'CENSORED' CHANNEL_ID = 'CENSORED' ON_BEHALF_OF_USER = 'CENSORED' # `TAB` can either be `Music` or `Sound effects` TAB = 'Music' allTracks = [] nextPageToken = '' TAB_REQUEST = '' if TAB == 'Music' else ',"filter":{"trackTypeIn":{"values":["CREATOR_MUSIC_TRACK_TYPE_SOUNDEFFECT"]}}' while True: command = f"curl -s 'https://studio.youtube.com/youtubei/v1/creator_music/list_tracks' -H 'Content-Type: application/json' -H 'Authorization: SAPISIDHASH {SAPISIDHASH}' -H 'X-Goog-AuthUser: 0' -H 'Origin: https://studio.youtube.com' -H 'Cookie: __Secure-3PSID={SECURE_3PSID}; __Secure-3PAPISID={SECURE_3PAPISID}'" + ' --data-raw \'{"channelId":"' + CHANNEL_ID + '"' + TAB_REQUEST + ',"pageInfo":{"pageSize":100' + ('' if nextPageToken == '' else f',"pageToken":"{nextPageToken}"') + '},"context":{"client":{"clientName":62,"clientVersion":"1.20230201"},"user":{"onBehalfOfUser":"' + ON_BEHALF_OF_USER + '"}}}\'' data = getJSON(command) allTracks += data['tracks'] print(len(allTracks)) pageInfo = data['pageInfo'] if 'nextPageToken' in pageInfo: nextPageToken = pageInfo['nextPageToken'] else: break with open('music.json', 'w') as f: json.dump(allTracks, f, indent=4)