I'm creating a youtube downloader for my project, so I've been playing around with YouTube API. I have a problem putting the data into a dictionary, so for example, this is the data:
result = {'kind': 'youtube#searchListResponse', 'etag': '5JMmuS5CVq2hYbanuVXwLKfuwXk', 'nextPageToken': 'CAEQAA', 'regionCode': 'US', 'pageInfo': {'totalResults': 1000000, 'resultsPerPage': 1}, 'items': [{'kind': 'youtube#searchResult', 'etag': '_quYyNz6XPXmAaWfx4pkGm_ZXRA', 'id': {'kind': 'youtube#video', 'videoId': 'Jn09UdSb3aA'}, 'snippet': {'publishedAt': '2020-03-04T12:00:04Z', 'channelId': 'UCyOfqgtsQaM3S-VZnsYnHjQ', 'title': 'The Best of Chopin', 'description': 'Buy the MP3 album on the Official Halidon Music Store: Listen to our playlist on Spotify: ialClassics Order “100 ...', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/Jn09UdSb3aA/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/Jn09UdSb3aA/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/Jn09UdSb3aA/hqdefault.jpg', 'width': 480, 'height': 360}}, 'channelTitle': 'HALIDONMUSIC', 'liveBroadcastContent': 'none', 'publishTime': '2020-03-04T12:00:04Z'}}]}
search = {}
search_data = []
for item in result['items']:
title = item['snippet']['title']
description = item['snippet']['description']
video = item['id']['videoId']
search['title'] = title
search['description'] = description
search['videoId'] = video
search_data.append(search)
And I have a difficult time adding each data into the dictionary with the "title" as a key. So I want the dictionary to be looks like this:
{'The Best of Chopin':
{'description': 'Buy ... : AYhx Listen .... ',
'videoId': 'Jn09UdSb3aA'},
'The Next Title':
{'description': 'blah blah',
'videoId':'121212121'},
'The Third one.... and goes on
I've been reading multiple articles about the nested dictionary, but I see lots of iterating through but not how to create.. I tried and played around a bit but I wasn't able to get it done. The only close solution that I tried was using "enumerate" in for loop to create with a key, but I'm trying to use the title as the key.. How can I do this? Any advice will be appreciated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…