From 4bc2854bb0f9b2e4302bf6483771110b74519332 Mon Sep 17 00:00:00 2001 From: Jason Michalski Date: Sun, 6 Apr 2008 04:04:57 -0500 Subject: [PATCH] Resume downloads. Still needs some work if it is not supported on the server we will get a messed up file. --- plugins/webvideo/webvideo.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/plugins/webvideo/webvideo.py b/plugins/webvideo/webvideo.py index ed28e9c..4fd522f 100644 --- a/plugins/webvideo/webvideo.py +++ b/plugins/webvideo/webvideo.py @@ -5,6 +5,11 @@ import config import xmpp import threading +import urllib2 +import os.path +import shutil +import os.path +import urllib import xml.etree.ElementTree as ElementTree import Queue @@ -82,10 +87,6 @@ class WebVideo(Video): self.in_progress_lock.release() def processDlRequest(self): - import shutil - import os.path - import urllib2 - import urllib while True: data = self.work_queue.get() @@ -98,14 +99,7 @@ class WebVideo(Video): path = settings['path'] file_name = os.path.join(path, '%s-%s' % (data['bodyOfferId'] ,data['url'].split('/')[-1])) - print 'downloading %s to %s' % (data['url'], file_name) - - outfile = open(file_name, 'wb') - - infile = urllib2.urlopen(data['url']) - shutil.copyfileobj(infile, outfile) - - print 'done downloading %s to %s' % (data['url'], file_name) + self.downloadFile(data['url'], file_name) tsn = data['bodyId'] file_info = VideoDetails() @@ -132,3 +126,16 @@ class WebVideo(Video): finally: self.in_progress_lock.release() + + def downloadFile(self, url, file_path): + print 'downloading %s to %s' % (url, file_path) + + outfile = open(file_path, 'awb') + size = os.path.getsize(file_path) + r = urllib2.Request(url) + if size: + r.add_header('Range', 'bytes=%s-' % size) + infile = urllib2.urlopen(r) + shutil.copyfileobj(infile, outfile, 8192) + + print 'done downloading %s to %s' % (url, file_path) -- 2.11.4.GIT