diff options
author | spoob <spoob@gmx.de> | 2009-08-27 21:52:10 +0200 |
---|---|---|
committer | spoob <spoob@gmx.de> | 2009-08-27 21:52:10 +0200 |
commit | c70bcb1a1353b8b436daeaf143936fa54c2775af (patch) | |
tree | b7965d29eb030a3d87562ac9bb35b3614faf77df | |
parent | Fixed Zippyshare.com (diff) | |
download | pyload-c70bcb1a1353b8b436daeaf143936fa54c2775af.tar.xz |
New .part download system
-rwxr-xr-x | module/network/Request.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/module/network/Request.py b/module/network/Request.py index b30766ef2..63ed217ed 100755 --- a/module/network/Request.py +++ b/module/network/Request.py @@ -3,13 +3,14 @@ """ -authored by: RaNaN +authored by: RaNaN, Spoob """ import base64 import cookielib from gzip import GzipFile import time -from os import sep +from os import sep, rename +from os.path import dirname, exists import urllib from cStringIO import StringIO @@ -202,7 +203,7 @@ class Request: self.opener.add_handler(handler) self.downloader.add_handler(handler) - def download(self, url, filename, get={}, post={}, ref=True, cookies=False): + def download(self, url, file_name, get={}, post={}, ref=True, cookies=False): if post: post = urllib.urlencode(post) @@ -218,7 +219,9 @@ class Request: if self.curl: - fp = open(filename, 'wb') + download_folder = dirname(file_name) + sep + file_temp = download_folder + str(time.time()) + ".part" + fp = open(file_temp, 'wb') self.init_curl() @@ -233,12 +236,20 @@ class Request: if ref and self.lastURL is not None: self.pycurl.setopt(pycurl.REFERER, self.lastURL) - self.dl_arrived = 0 self.dl_time = time.time() self.dl = True self.pycurl.perform() + file_count = 0 + while exists(file_name): + file_count += 1 + file_split = file_name.split(".") + temp_name = "%s-%i.%s" % (file_split[0], file_count, file_split[1]) + if not exists(temp_name): + file_name = temp_name + + rename(file_temp, file_name) self.dl = False self.dl_finished = time.time() |