问题描述
我正在使用Python软件包“ apiclient.discovery”使用以下代码从youtube帐户下载视频列表:
def get_channel_videos(channel_id,name,n=1e9,):
from apiclient.discovery import build
api_key = 'APIKEYHERE'
youtube = build('youtube','v3',developerKey=api_key)
remain = n
c = n
# get Uploads playlist id
res = youtube.channels().list(id=channel_id,part='contentDetails').execute()
playlist_id = res['items'][0]['contentDetails']['relatedplaylists']['uploads']
videos = []
stats = []
next_page_token = None
while 1:
if remain>=50: batch=50
else: batch=remain
if remain <= 0: break
res = youtube.playlistItems().list(playlistId=playlist_id,part='snippet',maxResults=batch,\
pagetoken=next_page_token).execute()
videos += res['items']
next_page_token = res.get('nextPagetoken')
if next_page_token is None:
break
remain -= batch
return videos,name
可以修改此代码以下载播放列表,而不是频道的主要视频吗? 例如所有视频都在任何一个或所有这些播放列表中: https://www.youtube.com/c/JonathanHaidt1/playlists
(我已经尝试过自己但是没有运气)
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)