2017-09-30 3 views
1

Umwelt

  • Windows-8.1
  • Visual Studio 2017 Gemeinschafts
  • C#
  • WPF-Anwendung

Ausgabe

  • YoutubeExtractor löst System.Net.WebException beim Herunterladen eines Videos aus.

Ich habe YoutubeExtractor von Nuget und es funktioniert nicht. Das VideoInfo-Objekt ist nicht null. Ich habe mehrere Videos auf Youtube ausprobiert und dieselben Ausnahmen sind aufgetaucht. Ich habe das Thema gegooglet und es hat mir nicht viel geholfen.System.Net.WebException auf YoutubeExtractor beim Herunterladen eines Videos

Hier ist der Code.

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. 

Wie kann ich dieses Problem lösen? Vielen Dank.

EDIT: 2017.10.26 13.42 GMT

Alexey 'Tyrrrz' Golub Antwort so viel geholfen! Ich habe seinen ursprünglichen Code korrigiert und hier ist es.

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

Antwort

1

Wenn nichts anderes funktioniert, können Sie YoutubeExplode versuchen, die eine mehr up-to-date ist und gepflegt Bibliothek für diese.

würde Ihr Code dann:

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"))); 
+1

Dank! Es ist also deine Bibliothek. Ich habe einige Fehler in Ihrem Code gefunden und meinen ursprünglichen Beitrag mit dem korrigierten Code aktualisiert, der gut funktioniert hat. Überprüfen Sie bitte das. – dixhom

+0

@dixhom Entschuldigung, ich war müde, als ich das schrieb und vergessen zu überprüfen. x_x –

+0

@dixhom sehr froh, dass du es herausgefunden hast! –

Verwandte Themen