0

I am working on a download manager. I tried to download a content from Google Drive. I used AddRange to get the file partially but despite Range:60000000-61000000 returns the correct size, the Range:600000000-610000000 returns -1. It doesnt overflow the file size which is almost 1.3GB. I dont understand why this problem happens. How can I fix it?

var tabUrl = "https://drive.google.com/u/0/uc?export=download&confirm=03hU&id=0B1eUy3QmH0GJMnMzOTd0ZmxBTWs";
var url = "https://doc-0g-b4-docs.googleusercontent.com/docs/securesc/lsbj6u3i2broqhjlhh1rgl1pur9nv89c/2ipaf9daok4r1ccc59df1knp3itb6ov6/1608404475000/05822274146576777383/05815548638186256017/0B1eUy3QmH0GJMnMzOTd0ZmxBTWs?e=download&authuser=0&nonce=carmpci74c5ie&user=05815548638186256017&hash=dm8janki6hh5u70h2t9t83t2gq922app";
var request = (HttpWebRequest)WebRequest.Create(url);
var whc = new WebHeaderCollection();
request.SetHeaderValue("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362");
request.AllowAutoRedirect = true;
request.Method = "GET";
request.Timeout = 30000;
request.KeepAlive = false;
request.ReadWriteTimeout = 3000;
before.Raise(null, new BeforeSendingRequestEventArgs(request));
request.AddRange(60000000, 61000000);

Request Headers As Json:

      {
         "name":"Sec-Fetch-User",
         "value":"?1"
      },
      {
         "name":"Sec-Fetch-Dest",
         "value":"document"
      },
      {
         "name":"sec-ch-ua",
         "value":"\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\""
      },
      {
         "name":"sec-ch-ua-mobile",
         "value":"?0"
      },
      {
         "name":"Referer",
         "value":"https://drive.google.com/"
      },
      {
         "name":"Accept-Encoding",
         "value":"gzip, deflate, br"
      },
      {
         "name":"Accept-Language",
         "value":"tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7"
      },
      {
         "name":"Cookie",
         "value":"AUTH_r6g6bi1696lsg9bjdc9ud1ssvo24su70_nonce=carmpci74c5ie"
      }
   ],
   "taburl":"https://drive.google.com/u/0/uc?export=download&confirm=03hU&id=0B1eUy3QmH0GJMnMzOTd0ZmxBTWs",
   "url":"https://doc-0g-b4-docs.googleusercontent.com/docs/securesc/lsbj6u3i2broqhjlhh1rgl1pur9nv89c/2ipaf9daok4r1ccc59df1knp3itb6ov6/1608404475000/05822274146576777383/05815548638186256017/0B1eUy3QmH0GJMnMzOTd0ZmxBTWs?e=download&authuser=0&nonce=carmpci74c5ie&user=05815548638186256017&hash=dm8janki6hh5u70h2t9t83t2gq922app",
   "filename":"Ins.rar",
   "size":0
}
Ali Tor
  • 2,772
  • 2
  • 27
  • 58
  • Does the server definitely support partial? – Caius Jard Dec 19 '20 at 19:14
  • It doesnt return the `Accept-Ranges=bytes` but it returns the correct size for some ranges and `Status=Partial Content`. e.g for `Range:bytes=0-5` the `Content-Length=6` and for the first range in my question it returns `1000001`. So the examples show that it supports ranged requests. – Ali Tor Dec 19 '20 at 19:19
  • So a range of 60 - 61 M returns an expected 1M but a range of 600 - 610M returns -1 instead of 10M? What does 600 - 601 M return? What does 60-70M return? – Caius Jard Dec 19 '20 at 20:14
  • Also, I noted when I was trying your file I couldn't download the file from url, but I could visit tabUrl and get the confirmation page from where I could launch a download (I didn't check if my download url matches yours, I was looking for accept/range header) -- is there any chance that your request is failing for some other "I don't think you invoked it from the tabUrl on a browser like normal people do" type reason like you forget to set a cookie or referer? – Caius Jard Dec 19 '20 at 20:18
  • @CaiusJard, I tried your questions. 600-601M returned 1000001 as expected, 60-70M returned -1. I developed an extension working with Chrome and it sends headers and cookies to my application when a download requested in browser. So I use it in request, without cookie the url doesnt work correctly as you tried. The url that contains file can be expired, it is needed to refresh with a new one – Ali Tor Dec 19 '20 at 22:01
  • 1
    I'm not really sure if this means your problem is solved or not? It looks like you cannot request 10 megabytes partial ever? Or cannot request 10 megabytes without a cookie? Maybe if you're doing it partial, they have a limit of some lower number of Mb, perhaps to allow behavior like video players have where they request a few Mb for buffering / to allow seeking. Perhaps you will have to work out the max partial you can request, and then keep to that maximum – Caius Jard Dec 20 '20 at 07:45
  • Yes it seems it doesnt accept ranges that have size > 1Mb. So a second question appears. Am I able to change this limit or how to get the limit value to be sure? I couldnt find anything related in google – Ali Tor Dec 20 '20 at 16:28
  • It's not something I can answer I'm afraid.. I suspect it is that way to allow reasonable seeking of video content with minimal buffering of content that won't be viewed. Perhaps you can create an algo that starts off at 1Mb and then requests 1.1 (add 10%), then 20% more than 1.1... and keep creeping it up and down, so it always automatically tunes for as much as possible.. – Caius Jard Dec 20 '20 at 19:03
  • Thanks , btw I guess it can be determined from the Response header `Transfer-Encoding=chunked` that Range has limit – Ali Tor Dec 20 '20 at 19:21

0 Answers0