How to enumerate and download video/audio clips from YouTube |
|
YouTube is considered one of the largest search engines in the world, second only to its parent company, Google: Audio DJ Studio for .NET leverages YouTube search capabilities by providing a set of methods, accessible through the Youtube property which is implemented through the Youtube class, that can perform four different types of searches:
Search available videos inside a given YouTube channel
YouTube channels can be searched by calling the Youtube.ChannelsListSearch method: in this case the search is performed by providing a string containing one or more keywords.
A successful call to this method allows the container application the be notified about the search completion through the CallbackForYoutubeEvents delegate having the nEvent parameter set to EV_YOUTUBE_SEARCH_DONE and the nData1 parameter set to YOUTUBE_SEARCH_CHANNELS.
Available results can be enumerated through the Youtube.ChannelsListSearchItemsCountGet method and, for each result, related information can be obtained through the Youtube.ChannelsListSearchItemInfoGet method; furthermore, the Youtube.ChannelsListSearchItemThumbnailGet method allows to download the thumbnail image of the channel locally.
YouTube videos can be searched by calling the Youtube.VideoListSearch method: also in this case the search is performed by providing a string containing one or more keywords.
A successful call to this method allows the container application the be notified about the search completion through the CallbackForYoutubeEvents delegate having the nEvent parameter set to EV_YOUTUBE_SEARCH_DONE and the nData1 parameter set to YOUTUBE_SEARCH_VIDEOS.
Available results can be enumerated through the Youtube.VideoListSearchItemsCountGet method and, for each result, related information can be obtained through the Youtube.VideoListSearchItemInfoGet method; furthermore, the Youtube.VideoListSearchItemThumbnailGet method allows to download the thumbnail image of the channel locally.
Search available videos inside a given YouTube channel
Videos available inside a given YouTube channel can be searched by calling the Youtube.ChannelVideoListSearch method: in this case the search is performed by providing a string containing the unique identifier of the channel as assigned by YouTube when the channel was originally created: the identifier of a channel can be obtained through a previous call to the Youtube.ChannelsListSearch method.
A successful call to this method allows the container application the be notified about the search completion through the CallbackForYoutubeEvents delegate having the nEvent parameter set to EV_YOUTUBE_SEARCH_DONE and the nData1 parameter set to YOUTUBE_SEARCH_CHANNEL_ITEMS.
Available results can be enumerated through the Youtube.ChannelVideoListSearchItemsCountGet method and, for each result, related information can be obtained through the Youtube.ChannelVideoListSearchItemInfoGet method; furthermore, the Youtube.ChannelVideoListSearchItemThumbnailGet method allows to download the thumbnail image of the video locally.
A specific video can be searched by calling the Youtube.VideoSearchByID method: in this case the search is performed by providing a string containing the unique identifier of the video as assigned by YouTube when the video was originally added to the channel or by providing a string containing the fully qualified URL of the video: both information, the identifier and the URL, can be obtained through a previous search performed by the Youtube.VideoListSearch and Youtube.ChannelVideoListSearch emthods.
A successful call to this method allows the container application the be notified about the search completion through the CallbackForYoutubeEvents delegate having the nEvent parameter set to EV_YOUTUBE_SEARCH_DONE and the nData1 parameter set to YOUTUBE_SEARCH_VIDEO_BY_ID
Each video added to YouTube may contain different types of multimedia files, typically video and audio streams mixed together (also known as "Muxed" streams), video stream only or audio stream only; these streams may be encoded with different output formats and resolutions; all of the available streams can be enumerated using the Youtube.VideoSearchByIDStreamCountGet method and related information can be obtained through the Youtube.VideoSearchByIDStreamInfoGet method.
Finally, enumerated streams can be downloaded into a local file through Youtube.VideoSearchByIDDownloadStreamToFile method or directly into a player through the Youtube.VideoSearchByIDDownloadStreamToPlayer method: the download session can be interrupted through the Youtube.VideoSearchByIDDownloadStop method.
Samples of use of the Youtube object in Visual C#.NET and Visual Basic.NET can be found inside the following samples installed with the product's setup package:
- YoutubePlayer
- YoutubeSearch