Question

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)

Was it helpful?

Solution 2

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

OTHER TIPS

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

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top