Changeset 4bc2854bb0f9b2e4302bf6483771110b74519332

Show
Ignore:
Timestamp:
04/06/08 04:04:57 (8 months ago)
Author:
Jason Michalski <armooo@armooo.net>
git-committer:
Jason Michalski <armooo@armooo.net> 1207472697 -0500
git-parent:

[e19fdd68c9407b567c1608c8b3a5a9396ab27552]

git-author:
Jason Michalski <armooo@armooo.net> 1207472697 -0500
Message:

Resume downloads.

Still needs some work if it is not supported on the server we will get a
messed up file.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/webvideo/webvideo.py

    re19fdd6 r4bc2854  
    66 
    77import threading 
     8import urllib2 
     9import os.path 
     10import shutil 
     11import os.path 
     12import urllib 
    813import xml.etree.ElementTree as ElementTree 
    914import Queue 
     
    8388 
    8489    def processDlRequest(self): 
    85         import shutil 
    86         import os.path 
    87         import urllib2 
    88         import urllib 
    8990 
    9091        while True: 
     
    99100            file_name = os.path.join(path, '%s-%s' % (data['bodyOfferId'] ,data['url'].split('/')[-1])) 
    100101 
    101             print 'downloading %s to %s' % (data['url'], file_name) 
    102  
    103             outfile = open(file_name, 'wb') 
    104  
    105             infile = urllib2.urlopen(data['url']) 
    106             shutil.copyfileobj(infile, outfile) 
    107  
    108             print 'done downloading %s to %s' % (data['url'], file_name) 
     102            self.downloadFile(data['url'], file_name) 
    109103 
    110104            tsn = data['bodyId'] 
     
    133127                self.in_progress_lock.release() 
    134128 
     129 
     130    def downloadFile(self, url, file_path): 
     131        print 'downloading %s to %s' % (url, file_path) 
     132 
     133        outfile = open(file_path, 'awb') 
     134        size = os.path.getsize(file_path) 
     135        r = urllib2.Request(url) 
     136        if size: 
     137            r.add_header('Range', 'bytes=%s-' % size) 
     138        infile = urllib2.urlopen(r) 
     139        shutil.copyfileobj(infile, outfile, 8192) 
     140 
     141        print 'done downloading %s to %s' % (url, file_path)