Rishabh Chopra
Rishabh Chopra

Reputation: 95

How to search for YouTube videos over a specific subset of channels?

I want to get a list of all videos associated with a specific search term from a subset of channels. The subset of channels is:

For example, if I search for the term force, I want all YouTube videos related to that search term from the above 3 channels to appear in the results.

How can I do this using the YouTube Data API's Search.list endpoint? The argument for author mentioned in the explainer video seems to be deprecated.

Upvotes: 0

Views: 130

Answers (1)

stvar
stvar

Reputation: 6955

By using the Search.list API endpoint, you have at your disposal the following request parameter:

channelId (string)

The channelId parameter indicates that the API response should only contain resources created by the channel.

Note: Search results are constrained to a maximum of 500 videos if your request specifies a value for the channelId parameter and sets the type parameter value to video, but it does not also set one of the forContentOwner, forDeveloper, or forMine filters.

Given the above specification, you'll have to call Search.list three times, passing to each invocation of it one of the ID of the channels of your interest.

Note that the neither of channel user names minutephysics, AsapSCIENCE and khanacademy is a valid channel ID, but that's easily resolvable:

$ python3 youtube-search.py --user-name minutephysics
UCUHW94eEFW7hkUMVaZz4eDg

$ python3 youtube-search.py --user-name AsapSCIENCE
UCC552Sd-3nyi_tk2BudLUzA

$ python3 youtube-search.py --user-name khanacademy
UC4a-Gbdw7vOaccHmFo40b9g

Above I made use of my public (MIT licensed) Python 3 script youtube-search.py; this script is able to search the API for custom URLs and respectively query the API for user names.

Note that youtube-search.py requires a valid API key to be passed to it as argument of the command line option --app-key or, otherwise, passed on as the environment variable YOUTUBE_DATA_APP_KEY. (Use the command line option --help for brief helping info.)

Upvotes: 1

Related Questions