I use webclient download to youtube, i have an 100 mb connection but my mp4 download rate 100kb/s :)
WebClient client = New WebClient;
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 6.1; .NET CLR 1.0.3705;)");
client.Proxy = Null;
client.DownloadFileAsync(New Uri(url.ToString()), directory + file.ToString());
How to fix this problem or where my wrong?
I think youtube block my speed but i tried Internet download manager then very fast down this video.
Thanks for help!
Sorry for my bad English.
Ertim Abon
There's nothing inherently wrong with your code - the "problem" is on the other end. YouTube throttles the connection so that the video is downloaded at about the same speed as it's played. This saves on bandwidth if (when!) people don't watch the entire video. Well-configured video streaming websites will give you a burst at the start and then stream the rest at a lower speed.
The only way around it would be to see if you could make multiple requests to different parts of the video to get the "burst" multiple times, for instance with Range headers. They might not like you doing that though.
Related
I have done a bit of research on this problem before. I had a look at this question and it didn't help me. Basically I am trying to build a program to help people use a website, and I need to get the recaptcha V2 challenge images from google's recaptcha API. I keep getting a
Specified value has invalid HTTP characters
when attempting to download the stream
try
{
WebClientEx wc = new WebClientEx(cookieJar);
wc.Headers.Add("Referer", recaptchaframe_url);
wc.Headers.Add("UserAgent:", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
Stream responsestream = wc.OpenRead("http://www.google.com" + challengeimageurl);
}
catch (Exception ex)
{
MessageBox.Show("This program was unable to download CAPTCHA image" + ex.Message);
}
I was able to get past this error by converting all manually set headers in the webclient to their .NET properties. (eg UserAgernt to HttpRequestHeader.UserAgent. It appears that it's useless to set header names manually.
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#
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);
I'm a newbie and I'm developing a windows application. I need to download a video file from my site and that's my issue here. I had designed a custom down-loader, through which I can download images, text files from my site. But I wasn't able download videos from my site. Could anyone please help me out..?
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri("http://mysitename.com/Videos/vid.mp4"), "c:\\movie.mp4");
I don't want to download by means of response content dispatch because my client wants me to download through custom browser.. so please let me know solutions from you experts.. thank you
I have tried to download a video file with WebClient and it works. My setup is as below:
I have a virtualdirectory(Video) in defaultwebsite (IIS) which has this video file.
I just use the below code to download the video file to C drive:
var client = new WebClient();
Uri address = new Uri("http://localhost/Video/wildlife.wmv");
client.DownloadFileAsync(address, #"c:\video.wmv");
Also note since you are downloading in Async fashion, wait for about a min for the operation to complete for the full file to be downloaded. Initially it shows 0 bytes but based on the size it takes some time to complete it.
UPDATE: If your server doesnt have the file mime type specified then just add to the collection of mime types that IIS can serve and you can download the file without any problem.
When adding MIME type the following values to be used are (for your scenario):
File Extension: .mp4
MIME Type: video/mp4
To add mime types in IIS follow these links:
For IIS 4,5
For IIS 6
For IIS 7
This sounds more like a server issue, but if you are doubting your code, you may want to try download sync (I have had some issues in the past downloading async). Another way is to use the WebRequest class. If this server is very remote, try pinging beforehand. I think that you should also check to make sure the file is on the server, and if the file is really big, you should check to see if the file finished uploading.
I am trying to upload zip files to a asp.net server. Its working fine on my local box when I run the server from VS but not for larger zips remotely. Remotely I am running IIS6.
It works great both remotely and locally on zips smaller than about 10mb and has been for months. Only recently have I needed anything larger.
Here is my code for uploading:
WebClient client = new WebClient();
client.UploadProgressChanged += onProgress;
client.UploadFileCompleted += onComplete;
client.UploadFileAsync(new Uri(url), filePath);
return client;
My code for receiving is:
Request.Files[0].SaveAs(pathToSave);
My web.config looks like:
<httpRuntime maxRequestLength="102400" useFullyQualifiedRedirectUrl="true" executionTimeout="5400"/>
The error I am getting remotely is that Request.Files is length 0.
Any idea on this or the best way to debug?
Webclient is a wrapper for HttpWebRequest. and I recommend to user HttpWebRequestinstead.
as you cant override timeout on webclient.
i faced the same issue. and now I'm using HttpWebRequest. much much better.
I would highly recommend using Darren's asp.net upload/download control. Uploading large files in asp.net is a pain.
I have an iPhone/iPad application made in MonoTouch, which is already in the apple store. However there's still an issue that hasn't been completely solved. I need to be able to upload large files to our servers. Sizes can vary from 2-100 Mb in size. I have tried several approaches:
Using SOAP Web Services, sending the byte array: a) Sending the whole file. Crashed. b) Splitting in chunks of 1Mb. Crashed after 10-15 chunks (varies).
Using WebClient.UploadFile. Works most of the time with smaller files < 5 Mb, but every now and then it crashes and everything larger than 10-12 Mb crashes. On the server, I have a aspx page that receives the information sent through a POST
Here is the actual code from the device:
WebClient wc = new WebClient ();
string sLFN = sLocalFileName;
FileInfo fi = new FileInfo (sLFN)
string sUri = getUri ();
byte [] f = wc.UploadFile (sUri, sLFN)
I believe that the memory capacity of the iPhone / iPad is something that directly affects this.
Does anybody has any recomendation or suggested approach that I should follow?
Thanks in advance
Edgar Herrador
I'd recommend using Streaming & Chunking. You're probably exceeding the message size when passing large files.
Are you getting any exceptions ?
Have you tried WCF streaming (http://msdn.microsoft.com/en-us/library/ms733742.aspx)?