Upload video using C #?

I am trying to pipe you a pipe using C # code, but I am not getting the correct code. I searched a lot of links but didn't get the correct links and code.

I want to upload a video in my local folder with C # code. I tried one link, but this code was just getting zero video in my local folder, so anyone has an idea how to do this.

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 I'm trying to download: " https://www.youtube.com/embed/UCsiNPbLbwZk43FOCRrdKBlA.mp4 "

+3


source to share


3 answers


I found a solution for uploading videos using C # code.

First you need to install libvideo in Visual Studio in the < NuGet Package Manager .

Here execute the command "Fry this command" on the console of the box:

Install-Package VideoLibrary

      



First add this namespace at the top to your controller:

using VideoLibrary;

      

Now just write just the code and pass the link to the url:

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());

      

+2


source


You can embed youtube-dl into your application.
It provides extensive Youtube download options.

Basically, you are doing 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 expand it to suit your needs.

Process class

0


source


Check out YoutubeExplode for a more up-to-date solution . It offers a rich API for querying and downloading Youtube videos and, unlike other libraries, is still actively supported.

0


source







All Articles