Fixing a youtube downloader class

女生的网名这么多〃 提交于 2019-12-24 20:27:27

问题


A Little time ago I opend a thread (link at the bottom). And I'm happy to say it has been fixed, that is partially. It still uses the wrong youtube links. And since youtube keeps updating all examples i could find where broken. I think this has to do with the "regular" expressions. Could someone enlighten me on that subject?

And now for the error at hand: An unhandled exception of type 'System.Net.WebException' occurred in System.dll Additional information: The remote server returned an error: (403) Forbidden. At Line 22: wc.DownloadFile(kvp.Value, @"C:\Users\waralot\Downloads\youtube\"+kvp.Key);

The console during compilation is here: pastebin.com/BrgKkAmk

Original project at HackForums: http://www.hackforums.net/showthread.php?tid=2052105

My current version: http://pastebin.com/2iH2vQ2L

Again my first thread can be found here: Converting a Youtube downloader form VB to C#


回答1:


Take a look at my YoutubeExtractor library. It provides methods to download videos from YouTube.




回答2:


Seems like Youtube blocks you from accessing the link, this may because you don't set an user-agent for your WebClient.

Try adding this before you try to download the video.

wc.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

Code for url cleanup also needs to be changed like so.

//clean up residual tags and encoded strings
link = slink.Replace("url=", "");
link = link.Replace("\\u0026", "&");
link = HttpUtility.UrlDecode(link);


来源:https://stackoverflow.com/questions/9959167/fixing-a-youtube-downloader-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!