Get list of video from a youtube channel

☆樱花仙子☆ 提交于 2021-01-23 09:38:32

问题


I'm using these apis https://developers.google.com/youtube/ and I can't figure out how, given a youtube channel address, get the video list with related infos (single video url and title, at least)


回答1:


It's a bit convoluted, but can be done relatively painlessly. The trick is in knowing that a channel is really just a list of videos uploaded by a particular user. So if, when you say you have a youtube channel address, that address takes the form of:

http://www.youtube.com/user/[username]

Then you can get the videos with the user uploads feed:

https://gdata.youtube.com/feeds/api/users/[username]/uploads

As a side note, if you use the feed:

https://gdata.youtube.com/feeds/api/users/[username]

You'll get back extra info about the user, including a series of elements that give you various feed links (one of which is the uploads feed I mentioned above) that also contain info such as number of videos, etc.

If instead your channel URL is in the form:

https://www.youtube.com/channel/UC[userid]

Note that this kind of URL always starts with UC and then a long string. In this case, just drop the UC, and visit this feed:

https://gdata.youtube.com/feeds/api/users/[userid]/uploads



回答2:


I know this is no longer relevant, but for anyone here in 2020, youll need a youtube v3 api key

What you can use is

https://www.googleapis.com/youtube/v3/search?key=[API_KEY]&channelId=[CHANNEL_ID]&part=snippet,id&order=date&maxResults=50

you can remove snippet and it will not give the names and other information of all of the videos. ID gives the video id

send a get request to the URL




回答3:


This method is especially useful if a) the channel has more than 50 videos or if b) desire youtube video ids formatted in a flat txt list:

  1. Obtain a Youtube API v3 key (see https://stackoverflow.com/a/65440324/2585501)
  2. Obtain the Youtube Channel ID of the channel (see https://stackoverflow.com/a/16326307/2585501)
  3. Obtain the Uploads Playlist ID of the channel: https://www.googleapis.com/youtube/v3/channels?id={channel Id}&key={API key}&part=contentDetails (based on https://www.youtube.com/watch?v=RjUlmco7v2M)
  4. Install youtube-dl (e.g. pip3 install --upgrade youtube-dl or sudo apt-get install youtube-dl)
  5. Download the Uploads Playlist using youtube-dl: youtube-dl -j --flat-playlist "https://<yourYoutubePlaylist>" | jq -r '.id' | sed 's_^_https://youtu.be/_' > videoList.txt (see https://superuser.com/questions/1341684/youtube-dl-how-download-only-the-playlist-not-the-files-therein)


来源:https://stackoverflow.com/questions/13218343/get-list-of-video-from-a-youtube-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!