C. Cooney
C. Cooney

Reputation: 591

Using YouTube v3 API, is it possible to retrieve a list of videos from a public channel?

I'm attempting to download videos from a particular YouTube channel. I am starting with the video_id and trying to work back unsuccessfully to get to the channel_id, and then eventually a listing of videos on the channel.

Here is my code:

def gather_videos(api_key):
    youtube = build('youtube', 'v3', developerKey=api_key)

    video_id = [video_id]
    request = youtube.videos().list(
        part=['statistics', 'contentDetails', 'snippet', 'id'],
        id=video_id
    )
    response = request.execute()

From this, I am able to retrieve the channel_id in the response (json), but I cannot seem to make the link to an API call to retrive the full listing. I have reviewed the API documentation here (https://developers.google.com/youtube/v3/docs/channels/list), but I am a novice at interpreting the details. Is it even possible to go this route? Or will I need to conduct a search? Or perhaps use the fact I am subscribed to the channel and try to obtain the listing this way?

Upvotes: 0

Views: 131

Answers (2)

C. Cooney
C. Cooney

Reputation: 591

I utilized the following code to obtain a search list containing videos hosted on the channel:

request = youtube.search().list(
        part=['snippet'],
        channelId=channel_id,
    )

Upvotes: 0

Benjamin Loison
Benjamin Loison

Reputation: 5632

To download videos of a given YouTube channel use YouTube DL this way:

youtube-dl -i https://www.youtube.com/channel/CHANNEL_ID

If you are interested to have the playlist video metadata through the YouTube Data API v3 then this answer will meet your needs.

-i, --ignore-errors

Continue on download errors, for example to skip unavailable videos in a playlist

Source: https://github.com/ytdl-org/youtube-dl/blob/master/README.md#options

Upvotes: 1

Related Questions