C#youtube视频下载控制台应用 - 不下载视频

时间:2017-10-13 23:26:09

标签: c# youtube

我正在尝试实施一个从youtube下载视频文件的程序。我写过这个有两个文件的小型Windows控制台应用程序。

Downloader.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using VideoLibrary;
using System.IO;

namespace AsyncAwait
{
    public class Downloader
    {

        public Task DownloadFilesAsync()
        {
            var tasks2 = new Func<Task>[]
            {
                 () => DownloadYoutubeVideo("https://www.youtube.com/watch?v=OGxgnH8y2NM"),
                 () => DownloadYoutubeVideo("https://www.youtube.com/watch?v=FNQxxpM1yOs"),
            };
            return Task.WhenAll(tasks2.Select(task => task()).ToArray());
        }

        private 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(@"\Users\KarthikS\Desktop" + video.FullName, video.GetBytes());
        }

        public async Task DownloadYoutubeVideo(string link)
        {
            await Task.Run(() => SaveVideoToDisk(link));
        }
    }
}

Program.cs的

class Program
{
    static void Main(string[] args)
    {
        Downloader d = new Downloader();
        d.DownloadFilesAsync().Wait();
        Console.WriteLine("finished");            
    }
}

我正在使用libvideo下载YouTube视频。该程序似乎成功运行。但不知何故,我没有看到任何我希望创建文件的文件。我错过了什么或做错了什么?

我打印出字节数和video.FullName

Number of Bytes   82019554 full name                                    Introduction - Django Web Development with Python 1 - YouTube.mp4
Number of Bytes  105567310 full name                              Practical Machine Learning Tutorial with Python Intro p.1 - YouTube.mp4

0 个答案:

没有答案
相关问题