我的目标是将ID,标题和标签附加到YouTube频道的所有视频的数组arr
中。
这是我尝试过的
client = get_authenticated_service()
results1 = search_list_by_keyword(client,
part='snippet',
maxResults=50,
channelId=someChannelId)
for z in range(len(results1['items'])):
#print(results1['items'][z]['id'])
try:
id = results1['items'][z]['id']['videoId']
except:
continue;
results2 = videos_list_by_id(client,
part='snippet,contentDetails,statistics',
id=id)
title = results2['items'][0]['snippet']['title']
tags = results2['items'][0]['snippet']['tags']
print (title)
row = []
row.append(id)
row.append(title)
row.append(tags)
if 'something' not in tags:
arr.append(row)
nextPageToken = results1['nextPageToken']
while 1==1:
try:
print 'Continue at %s:' % (nextPageToken)
results1 = search_list_by_keyword(client,
part='snippet',
maxResults=50,
channelId=someChannelId,
pageToken=nextPageToken)
nextPageToken = results1['nextPageToken']
for z in range(len(results1['items'])):
id = results1['items'][z]['id']['videoId']
results2 = videos_list_by_id(client,
part='snippet,contentDetails,statistics',
id=id)
title = results2['items'][0]['snippet']['title']
tags = results2['items'][0]['snippet']['tags']
print (title)
if 'Podcast' in tags:
tags.remove('Podcast')
row = []
row.append(id)
row.append(title)
row.append(tags)
if 'something' not in tags:
arr.append(row)
except:
break
和
def search_list_by_keyword(client, **kwargs):
# See full sample for function
kwargs = remove_empty_kwargs(**kwargs)
response = client.search().list(
**kwargs
).execute()
return response
它一直工作到while 1==1
,此后,print (title)
打印的结果越来越少。标题的最终数量约为该频道公开视频总数的一半。
如何获取所有视频的ID,标题和标签?