YouTube_Audio_library_extra.../metadata_extracter.py

38 lines
1.5 KiB
Python
Raw Permalink Normal View History

2023-02-04 14:13:29 +01:00
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
fileName = TAB.lower().replace(' ', '_') + '.json'
with open(fileName, 'w') as f:
2023-02-04 14:13:29 +01:00
json.dump(allTracks, f, indent=4)