下载视频时YoutubeExtractor上的System.Net.WebException 环境 Windows 8.1 Visual Studio 2017社区 C# WPF应用程序 问题 YoutubeExtractor在下载视频时引发System.Net.WebException

下载视频时YoutubeExtractor上的System.Net.WebException 环境 Windows 8.1 Visual Studio 2017社区 C# WPF应用程序 问题 YoutubeExtractor在下载视频时引发System.Net.WebException,c#,wpf,visual-studio,download,youtube,C#,Wpf,Visual Studio,Download,Youtube,我找到了Nuget的YoutubeExtractor,但它不起作用。VideoInfo对象不是空的。我在Youtube上尝试了几个视频,同样的例外也出现了。我在谷歌上搜索了这个问题,它没有给我多少帮助 这是密码 var videos = DownloadUrlResolver.GetDownloadUrls(@"https://www.youtube.com/watch?v=M1wLtAXDgqg"); VideoInfo video = videos .First(info =>

我找到了Nuget的YoutubeExtractor,但它不起作用。VideoInfo对象不是空的。我在Youtube上尝试了几个视频,同样的例外也出现了。我在谷歌上搜索了这个问题,它没有给我多少帮助

这是密码

var videos = DownloadUrlResolver.GetDownloadUrls(@"https://www.youtube.com/watch?v=M1wLtAXDgqg");
VideoInfo video = videos
    .First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360);

if (video.RequiresDecryption)
    DownloadUrlResolver.DecryptDownloadUrl(video);

var videoDownloader = new VideoDownloader(video, System.IO.Path.Combine("D:", video.Title + video.VideoExtension));

videoDownloader.DownloadProgressChanged += (sender_, args) => Console.WriteLine(args.ProgressPercentage);

videoDownloader.Execute(); // I got the exception here.
我如何解决这个问题?谢谢

编辑:2017/10/26 13:42 GMT

Alexey'Tyrrz'Golub的回答帮了大忙!我更正了他的原始代码,现在就是了

using YoutubeExplode;
using YoutubeExplode.Models.MediaStreams;

var client = new YoutubeClient();
var video = await client.GetVideoAsync("bHzHlSLhtmM");
// double equal signs after s.VideoQuality instead of one
var streamInfo = video.MuxedStreamInfos.First(s => s.Container == Container.Mp4 && s.VideoQuality == VideoQuality.Medium360);
// "D:\\" instead of "D:"
var pathWithoutExtension = System.IO.Path.Combine("D:\\", video.Title);
// streamInfo.Container.GetFileExtension() instead of video.VideoExtension (video doesn't have the property)
var path = System.IO.Path.ChangeExtension(pathWithoutExtension, streamInfo.Container.GetFileExtension());
// new Progress<double>() instead of new Progress()
await client.DownloadMediaStreamAsync(streamInfo, path, new Progress<double>(d => Console.WriteLine(d.ToString("p2"))));
使用YoutubeExplode;
使用YoutubeExplode.Models.MediaStreams;
var client=new YoutubeClient();
var video=await client.GetVideoAsync(“bHzHlSLhtmM”);
//在s.VideoQuality后面加上两个等号,而不是一个
var streamInfo=video.MuxedStreamInfos.First(s=>s.Container==Container.Mp4&&s.VideoQuality==VideoQuality.Medium360);
//“D:\\”而不是“D:”
var Path withoutextension=System.IO.Path.Combine(“D:\\”,video.Title);
//streamInfo.Container.GetFileExtension()而不是video.VideoExtension(video没有该属性)
var path=System.IO.path.ChangeExtension(pathWithoutExtension,streamInfo.Container.GetFileExtension());
//新进度()而不是新进度()
等待client.downloadmediastreasync(streamInfo,path,newprogress(d=>Console.WriteLine(d.ToString(“p2”)));

如果其他方法都不起作用,您可以尝试使用哪一种更为最新且维护良好的库

您的代码将是:

var client = new YoutubeClient();
var video = await client.GetVideoAsync("M1wLtAXDgqg");
var streamInfo = video.MuxedStreamInfos.First(s => s.Container == Container.Mp4 && s.VideoQuality == VideoQuality.Medium360);
var path = System.IO.Path.Combine("D:\\", video.Title + "." + streamInfo.Container.GetFileExtension());
await client.DownloadMediaStreamAsync(streamInfo, path, new Progress<double>(d => Console.WriteLine(d.ToString("p2")));
var client=newyoutubeclient();
var video=await client.GetVideoAsync(“M1wLtAXDgqg”);
var streamInfo=video.MuxedStreamInfos.First(s=>s.Container==Container.Mp4&&s.VideoQuality==VideoQuality.Medium360);
var path=System.IO.path.Combine(“D:\\”,video.Title+“+streamInfo.Container.GetFileExtension());
等待client.downloadmediastreasync(streamInfo,path,newprogress(d=>Console.WriteLine(d.ToString(“p2”)));

谢谢!这是你的库。我在你的代码中发现了一些错误,并用正确的代码更新了我的原始帖子,效果很好。请检查一下。@dixhom很抱歉,我写这篇文章时很困,忘了检查。x_x@dixhom不过,很高兴你找到了答案!