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
You can check out libvideo. It's much more up-to-date than YoutubeExtractor, and is fast and clean to use.
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.
Since all the other answers are outdated, I've written a library that is up-to-date:
http://github.com/flagbug/YoutubeExtractor
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.
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).