Search code examples
c#proxyyoutubeyoutube-dl

Proxy for downloading with libvideo in C#


Is anyone familiar with libvideo? I have [libvideo][1] in an application.

How can I inject the proxy config into the libvideo?

using VideoLibrary;

void SaveVideoToDisk(string link)
{
    var youTube = YouTube.Default; // starting point for YouTube actions
    var video = youTube.GetVideo(link); // gets a Video object with info about the video
    File.WriteAllBytes(@"C:\" + video.FullName, video.GetBytes());
}

Solution

  • It seems libvideo does not support proxy. So I have to use youtube-dl and corrected the above code

    public static void YouTubeDownloaderWithProxy(string link, string path)
    {
        Process youTube = new Process();
        try
        {
            string code = link.Split('/').LastOrDefault();
            string proxy = @"http://....:8585/";
            string youtubeUrl = @"https://www.youtube.com/watch?v=" + "code";
    
            youTube.StartInfo.UseShellExecute = true;
            youTube.StartInfo.CreateNoWindow = false;
            youTube.StartInfo.FileName = Application.StartupPath + @"\youtube-dl.exe";
            youTube.StartInfo.Arguments = $"--proxy {proxy} -o '{path}' {youtubeUrl}";
    
            youTube.Start();
            youTube.WaitForExit();
            youTube.Dispose();
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
    
    }