curl-and-python

Getting range error although the server accepts range

From: naheed <naheedcse_at_gmail.com>
Date: Thu, 19 Dec 2013 01:21:51 +0600

Hi there
I am trying to build a simple video downloader with pause-resume
functionality. I checked whether the server supports partial download by
a HEAD request. I got the following response:

> HEAD /otaku/3237ep5-Dragon_Ball_Z.mp4 HTTP/1.1
User-Agent: PycURL/7.22.0
Host: cache1.tinyvid.net
Accept: */*

< HTTP/1.1 200 OK
< Server: cloudflare-nginx
< Date: Wed, 18 Dec 2013 18:49:25 GMT
< Content-Type: video/mp4
< Content-Length: 54513381
< Connection: close
< Set-Cookie: __cfduid=da4f69981ffbbfeaac12d30299520be451387392564744;
expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.tinyvid.net; HttpOnly
< Last-Modified: Mon, 26 Nov 2012 09:59:58 GMT
< Accept-Ranges: bytes
< CF-RAY: dee0869a7b3082f
<

Seeing that the server accepts byte range- The following code runs fine
first time. But when run second time it raises range error ("HTTP server
doesn't seem to support byte ranges. Cannot resume."), although it
should have resumed from the byte i last downloaded.

import pycurl
import os
import sys
url="http://cache1.tinyvid.net/otaku/3237ep5-Dragon_Ball_Z.mp4"
c=pycurl.Curl()
c.setopt(pycurl.URL,url)
c.setopt(pycurl.FOLLOWLOCATION,0)
c.setopt(pycurl.NOPROGRESS,0)
filename = url.split("/")[-1].strip()
filepath = os.path.join(os.getcwd(), filename)
if os.path.exists(filepath):
     f = open(filepath, "ab")
     downloaded = os.path.getsize(filepath)
     c.setopt(pycurl.RESUME_FROM, downloaded)
else:
     f = open(filepath, "wb")
c.setopt(pycurl.WRITEDATA, f)
try:
     c.perform()
except pycurl.error,e:
     print e
c.close()

Am i missing something basic? Some help in this regard would be really
helpful.

Regards,
Naheed Anjum Arafat
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2013-12-18