summaryrefslogtreecommitdiffstats
path: root/module/network/HTTPDownload.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/network/HTTPDownload.py')
-rw-r--r--module/network/HTTPDownload.py66
1 files changed, 19 insertions, 47 deletions
diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py
index fe8075539..3b2bf26ca 100644
--- a/module/network/HTTPDownload.py
+++ b/module/network/HTTPDownload.py
@@ -1,21 +1,5 @@
-#!/usr/bin/env python
# -*- coding: utf-8 -*-
-"""
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- @author: RaNaN
-"""
+# @author: RaNaN
from os import remove, fsync
from os.path import dirname
@@ -25,17 +9,18 @@ from logging import getLogger
import pycurl
-from HTTPChunk import ChunkInfo, HTTPChunk
-from HTTPRequest import BadHeader
+from pyload.network.HTTPChunk import ChunkInfo, HTTPChunk
+from pyload.network.HTTPRequest import BadHeader
-from module.plugins.Plugin import Abort
-from module.utils import save_join, fs_encode
+from pyload.plugin.Plugin import Abort
+from pyload.utils import safe_join, fs_encode
-class HTTPDownload():
+
+class HTTPDownload(object):
""" loads a url http + ftp """
def __init__(self, url, filename, get={}, post={}, referer=None, cj=None, bucket=None,
- options={}, progressNotify=None, disposition=False):
+ options={}, progress=None, disposition=False):
self.url = url
self.filename = filename #complete file destination, not only name
self.get = get
@@ -63,7 +48,7 @@ class HTTPDownload():
except IOError:
self.info = ChunkInfo(filename)
- self.chunkSupport = None
+ self.chunkSupport = True
self.m = pycurl.CurlMulti()
#needed for speed calculation
@@ -71,7 +56,7 @@ class HTTPDownload():
self.speeds = []
self.lastSpeeds = [0, 0]
- self.progressNotify = progressNotify
+ self.progress = progress
@property
def speed(self):
@@ -114,7 +99,7 @@ class HTTPDownload():
fo.close()
if self.nameDisposition and self.disposition:
- self.filename = save_join(dirname(self.filename), self.nameDisposition)
+ self.filename = safe_join(dirname(self.filename), self.nameDisposition)
move(init, fs_encode(self.filename))
self.info.remove() #remove info file
@@ -130,7 +115,7 @@ class HTTPDownload():
except pycurl.error, e:
#code 33 - no resume
code = e.args[0]
- if code == 33:
+ if resume is True and code == 33:
# try again without resume
self.log.debug("Errno 33 -> Restart without resume")
@@ -151,6 +136,7 @@ class HTTPDownload():
if not resume:
self.info.clear()
self.info.addChunk("%s.chunk0" % self.filename, (0, 0)) #create an initial entry
+ self.info.save()
self.chunks = []
@@ -164,8 +150,8 @@ class HTTPDownload():
chunksDone = set() # list of curl handles that are finished
chunksCreated = False
done = False
- if self.info.getCount() > 1: # This is a resume, if we were chunked originally assume still can
- self.chunkSupport = True
+ if self.info.getCount() is 0: # This is a resume, if we were chunked originally assume still can
+ self.chunkSupport = False
while 1:
#need to create chunks
@@ -284,9 +270,9 @@ class HTTPDownload():
self.updateProgress()
if self.abort:
- raise Abort()
+ raise Abort
- #sleep(0.003) #supress busy waiting - limits dl speed to (1 / x) * buffersize
+ #sleep(0.003) #supress busy waiting - limits dl speed to (1 / x) * buffersize
self.m.select(1)
for chunk in self.chunks:
@@ -295,8 +281,8 @@ class HTTPDownload():
self._copyChunks()
def updateProgress(self):
- if self.progressNotify:
- self.progressNotify(self.percent)
+ if self.progress:
+ self.progress(self.percent)
def findChunk(self, handle):
""" linear search to find a chunk (should be ok since chunk size is usually low) """
@@ -324,17 +310,3 @@ class HTTPDownload():
del self.cj
if hasattr(self, "info"):
del self.info
-
-if __name__ == "__main__":
- url = "http://speedtest.netcologne.de/test_100mb.bin"
-
- from Bucket import Bucket
-
- bucket = Bucket()
- bucket.setRate(200 * 1024)
- bucket = None
-
- print "starting"
-
- dwnld = HTTPDownload(url, "test_100mb.bin", bucket=bucket)
- dwnld.download(chunks=3, resume=True)