Downloading video from YouTube
C#.NetYoutubeYoutube ApiC# Problem Overview
I wish to download a video from YouTube and then extract its audio.
Can anyone point me to some C# code to download a video?
For clarification purposes, I already know how to extract audio from a .FLV file like these.
C# Solutions
Solution 1 - C#
I've written a library that is up-to-date, since all the other answers are outdated:
Solution 2 - C#
You can check out libvideo. It's much more up-to-date than YoutubeExtractor, and is fast and clean to use.
Solution 3 - C#
Gonna give another answer, since the libraries mentioned haven't been actively developed anymore.
Consider using YoutubeExplode. It has a very rich and consistent API and allows you to do a lot of other things with youtube videos beside downloading them.
Solution 4 - C#
I suggest you to take a look into SharpGrabber - a .NET Standard library I've written just for this purpose. It is newer than YouTubeExtractor and libvideo.
It supports YouTube
and Instagram
as the time of this answer. This project also offers high-quality video and audio muxing and a cross-platform desktop application.
Solution 5 - C#
To all interested:
The "Coding for fun" book's chapter 4 "InnerTube: Download, Convert, and Sync YouTube Videos" deals with the topic. The code and discussion are at http://www.c4fbook.com/InnerTube.
[PLEASE BEWARE] While the overall concepts are valid some years after the publication, non-documented details of the youtube internals the project relies on can have changed (see the comment at the bottom of the page behind the second link).
Solution 6 - C#
libvideo https://github.com/omansak/libvideo (aka VideoLibrary) is a modern .NET library for downloading YouTube videos. It is portable to most platforms and is very lightweight.
This is recommended for more downloads and more popularity.
Use it for just few simple codes:
using VideoLibrary;
void SaveVideoToDisk(string link)
{
var youTube = YouTube.Default;
var video = youTube.GetVideo(link);
File.WriteAllBytes(@"C:\" + video.FullName, video.GetBytes());
}