-1

I have a C# application I wrote that loops thru certain youtubers and retrieves video information from them. All I care about is the videos themselves. I recently ran into a problem where someone either created or updated a playlist and now it's erroring out because it's pulling that in as well. Is there a way anyone knows to skip playlists when querying YouTube? This is how I pull a list of videos for a particular youtuber today.

YouTubeService yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = YTubeAPIKey });
var searchListRequest = yt.Search.List("snippet");
searchListRequest.MaxResults = YTubeDownloadsPerUser;
searchListRequest.Order = SearchResource.ListRequest.OrderEnum.Date;  // grab and order by newest to oldest
searchListRequest.ChannelId = youtubers;
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

1 Answers1

0

According to the official doc of the Search.list API endpoint, if you'll include within the endpoint invoking request parameters the following one set appropriately, then you'll obtain only items corresponding to videos:

type (string)
The type parameter restricts a search query to only retrieve a particular type of resource. The value is a comma-separated list of resource types. The default value is video,channel,playlist.

Acceptable values are:

  • channel
  • playlist
  • video

Consequently, just add the following line to your code for the API to provide you with resources pertaining only to videos:

searchListRequest.Type = "video";

Also note that having set the request parameter channelId implies that Search.list will return a limited number of items (the emphasis below is mine):

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.

stvar
  • 6,551
  • 2
  • 13
  • 28