I am trying to download you tube video using c# code but i am not getting proper code. I have searched many link but din't get any proper links and code.
I want to download the you tube video in my local folder with c# code. I have tried one link but that code just getting null video in my local folder so any one have the idea how can do that.
Below is the code i have tried so far.
var VedioUrl = "https://www.youtube.com/embed/" + objYouTube.VideoID + ".mp4";
WebRequest MyRequest = HttpWebRequest.Create(VedioUrl);
WebResponse MyResponse = MyRequest.GetResponse();
string RealURL = MyResponse.ResponseUri.ToString();
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(RealURL);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(receiveStream, encode);
StreamWriter writer = new StreamWriter(Server.MapPath("~/youtube/" + objYouTube.VideoID + ".mp4"), true);
writer.Write(readStream.ReadToEnd());
writer.Close();
so here is my video url which i am trying to download : "https://www.youtube.com/embed/UCsiNPbLbwZk43FOCRrdKBlA.mp4"
Go to the video URL and add “ss” before the “youtube.com…” and click enter. You will be directed to another page where you will save the video. This page is the parent website of ssyoutube.com, known as savefrom.net. This page will display all the information regarding the YouTube video you want to download.
You can download YouTube videos on your computer using VLC media player. You can also use WinX YouTube Downloader on PC or MacX YouTube Downloader on Mac. To download YouTube videos on the mobile app, simply tap "Download" on the selected video.
I have find the solution for download you tube videos using c# code.
First need install the "libvideo" on NuGet package manager console in visual studio.
Here Fire this command on package manger console :
Install-Package VideoLibrary
First add this namespace on top in your controller :
using VideoLibrary;
Now here just write just code and pass the url link :
var VedioUrl = "https://www.youtube.com/embed/" + objYouTube.VideoID + ".mp4";
var youTube = YouTube.Default;
var video = youTube.GetVideo(VedioUrl);
System.IO.File.WriteAllBytes(Server.MapPath("~/youtube/" + video.FullName + ".mp4"), video.GetBytes());
You can embed youtube-dl in your app.
It provides extensive Youtube download options.
Basically, you do something like this.
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
public static void Main()
{
Process myProcess = new Process();
try
{
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = @"yourpath\youtube-dl.exe";
myProcess.StartInfo.CreateNoWindow = false;
myProcess.StartInfo.Arguments = "https://www.youtube.com/watch?v=KFqrp4KSxio";
myProcess.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
You can use this C# wapper for youtube-dl.
You can extend it to suite your needs.
Process Class
For a more up to date solution, check out YoutubeExplode. It offers rich API to query and download Youtube videos and, unlike other libraries, is still actively maintained.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With