summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-05-19 14:19:31 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-05-19 14:19:31 +0200
commit0036345203f37f7f29cc60cbf19b4f355ee8e0ce (patch)
tree74093dc90b9e520bcc43e3409f417668be43c9c9
parentfunzt im moment nicht, aber ich arbeite daran (diff)
downloadpyload-0036345203f37f7f29cc60cbf19b4f355ee8e0ce.tar.xz
UploadedTo funktioniert jetzt auch. Wartezeit wird auch berücksichigt.
TODO: Reconnect verwalten, Download Verwaltung -> von einem Plugin nur eine Datei gleichzeitig, Zeit zum Downloaden etc..
-rw-r--r--Core.py26
-rw-r--r--Plugins/Plugin.py1
-rw-r--r--Plugins/RapidshareCom.py28
-rw-r--r--Plugins/UploadedTo.py22
-rw-r--r--Py_Load_File.py7
-rw-r--r--download_thread.py22
6 files changed, 69 insertions, 37 deletions
diff --git a/Core.py b/Core.py
index e3937d019..4093927f4 100644
--- a/Core.py
+++ b/Core.py
@@ -29,7 +29,7 @@ from sys import path, exit
from logging import warning, basicConfig
import urllib2
import re
-from time import sleep
+from time import sleep, time
import pickle
#my imports
@@ -216,7 +216,7 @@ class Core(object):
def __new_py_load_file(self, url, plugin):
- plugin_name = plugin.__name__
+ #plugin_name = plugin.__name__
new_file = PyLoadFile(self, plugin, url)
new_file.download_folder = self.download_folder
self.thread_list.append_py_load_file(new_file)
@@ -225,13 +225,19 @@ class Core(object):
def _test_print_status(self):
if len(self.thread_list.threads)>0:
for pyfile in self.thread_list.py_load_files:
- if pyfile.status != None:
- fn = pyfile.status.filename
- p = round(float(pyfile.status.downloaded_kb)/pyfile.status.total_kb, 2)
- s = round(pyfile.status.rate, 2)
- del pyfile.status
- pyfile.status = None
- print fn + ": " + str(p) + " @ " + str(s) + "kB/s"
+ if pyfile.status.type == 'downloading':
+ try:
+ fn = pyfile.status.filename
+ p = round(float(pyfile.status.downloaded_kb)/pyfile.status.total_kb, 2)
+ s = round(pyfile.status.rate, 2)
+ del pyfile.status #?!?
+ pyfile.status = None
+ print fn + ": " + str(p) + " @ " + str(s) + "kB/s"
+ except:
+ print pyfile.status.filename, "downloading"
+
+ if pyfile.status.type == 'waiting':
+ print pyfile.status.filename + ": " + "wartet", pyfile.status.waituntil -time()
def start(self):
""" starts the machine
@@ -239,7 +245,7 @@ class Core(object):
while True:
self._get_links(self.link_file)
self.thread_list.status()
- # self._test_print_status()
+ self._test_print_status()
sleep(1)
if len(self.thread_list.threads) == 0:
break
diff --git a/Plugins/Plugin.py b/Plugins/Plugin.py
index 933c72004..44ba119e1 100644
--- a/Plugins/Plugin.py
+++ b/Plugins/Plugin.py
@@ -21,6 +21,7 @@ class Plugin():
self.parent = parent
self.html = None
self.time_plus_wait = None #time() + wait in seconds
+ self.want_reconnect = None
def set_parent_status(self):
""" sets all available Statusinfos about a File in self.parent.status
diff --git a/Plugins/RapidshareCom.py b/Plugins/RapidshareCom.py
index 60095bfd5..586fa0157 100644
--- a/Plugins/RapidshareCom.py
+++ b/Plugins/RapidshareCom.py
@@ -28,6 +28,7 @@ class RapidshareCom(Plugin):
self.html = None
self.html_old = None #time() where loaded the HTML
self.time_plus_wait = None #time() + wait in seconds
+ self.want_reconnect = False
def set_parent_status(self):
""" sets all available Statusinfos about a File in self.parent.status
@@ -52,14 +53,13 @@ class RapidshareCom(Plugin):
self.time_plus_wait = time() + 10*60
try:
wait_minutes = re.search(r"Or try again in about (\d+) minute", self.html).group(1)
- self.time_plus_wait = time() + 60 * wait_minutes
+ self.time_plus_wait = time() + 60 * int(wait_minutes)
+ self.want_reconnect = True
except:
if re.search(r".*Currently a lot of users.*", self.html) != None:
- return ('wait', 2*60)
+ self.time_plus_wait = time() + 2*60
wait_seconds = re.search(r"var c=(.*);.*", self.html).group(1)
- self.time_plus_wait = time() + int(wait_seconds)
-
- print self.time_plus_wait - time()
+ self.time_plus_wait = time() + int(wait_seconds) + 5
def file_exists(self):
""" returns True or False
@@ -68,11 +68,11 @@ class RapidshareCom(Plugin):
self.download_html()
if re.search(r".*The File could not be found.*", self.html) != None or \
re.search(r"(<p>This limit is reached.</p>)", self.html) or \
- re.search(r"(.*is momentarily not available.*)", self.html):
+ re.search(r"(.*is momentarily not available.*)", self.html) or \
+ re.search(r"(.*The uploader has removed this file from the server.*)", self.html):
return False
else:
return True
- #The uploader has removed this file from the server.
def get_file_url(self):
""" returns the absolute downloadable filepath
@@ -82,14 +82,20 @@ class RapidshareCom(Plugin):
if (self.html_old + 5*60) > time(): # nach einiger zeit ist die file_url nicht mehr aktuell
self.download_html()
- file_url_pattern = r".*name=\"dlf\" action=\"(.*)\" method=.*"
- return re.search(file_url_pattern, self.html).group(1)
+ if not self.want_reconnect:
+ file_url_pattern = r".*name=\"dlf\" action=\"(.*)\" method=.*"
+ return re.search(file_url_pattern, self.html).group(1)
+ else:
+ return False
def get_file_name(self):
if self.html == None:
self.download_html()
- file_name_pattern = r".*name=\"dlf\" action=\"(.*)\" method=.*"
- return re.search(file_name_pattern, self.html).group(1).split('/')[-1]
+ if not self.want_reconnect:
+ file_name_pattern = r".*name=\"dlf\" action=\"(.*)\" method=.*"
+ return re.search(file_name_pattern, self.html).group(1).split('/')[-1]
+ else:
+ return self.parent.url
def wait_until(self):
if self.html == None:
diff --git a/Plugins/UploadedTo.py b/Plugins/UploadedTo.py
index dad5db3a9..fe2c3ec37 100644
--- a/Plugins/UploadedTo.py
+++ b/Plugins/UploadedTo.py
@@ -2,6 +2,7 @@
import urllib2
import re
+from time import time
from Plugin import Plugin
class UploadedTo(Plugin):
@@ -23,6 +24,7 @@ class UploadedTo(Plugin):
self.html = None
self.html_old = None #time() where loaded the HTML
self.time_plus_wait = None #time() + wait in seconds
+ self.want_reconnect = None
def set_parent_status(self):
""" sets all available Statusinfos about a File in self.parent.status
@@ -35,10 +37,12 @@ class UploadedTo(Plugin):
def download_html(self):
url = self.parent.url
- html = urllib2.urlopen(url).read()
+ self.html = urllib2.urlopen(url).read()
+
try:
wait_minutes = re.search(r"Or wait (\d+) minutes", self.html).group(1)
- self.time_plus_wait = time() + 60 * wait_minutes
+ self.time_plus_wait = time() + 60 * int(wait_minutes)
+ self.want_reconnect = True
except:
self.time_plus_wait = 0
@@ -47,14 +51,20 @@ class UploadedTo(Plugin):
"""
if self.html == None:
self.download_html()
- file_url_pattern = r".*<form name=\"download_form\" method=\"post\" action=\"(.*)\">"
- return re.search(file_url_pattern, self.html).group(1)
+ if not self.want_reconnect:
+ file_url_pattern = r".*<form name=\"download_form\" method=\"post\" action=\"(.*)\">"
+ return re.search(file_url_pattern, self.html).group(1)
+ else:
+ return False
def get_file_name(self):
if self.html == None:
self.download_html()
- file_name_pattern = r"<title>\s*(.*?)\s+\.\.\."
- return re.search(file_name_pattern, self.html).group(1)
+ if not self.want_reconnect:
+ file_name_pattern = r"<title>\s*(.*?)\s+\.\.\."
+ return re.search(file_name_pattern, self.html).group(1)
+ else:
+ return self.parent.url
def file_exists(self):
""" returns True or False
diff --git a/Py_Load_File.py b/Py_Load_File.py
index 1d20e05e0..dc1c2ba75 100644
--- a/Py_Load_File.py
+++ b/Py_Load_File.py
@@ -9,7 +9,6 @@ class PyLoadFile:
pluginClass = getattr(plugin, plugin.__name__)
self.plugin = pluginClass(self)
self.url = url
- self.dl = None
self.filename = "filename"
self.download_folder = ""
self.status = Status(self.id)
@@ -20,7 +19,9 @@ class PyLoadFile:
def prepareDownload(self):
- self.status.exist = True #self.plugin.file_exists()
+ self.status.exists = True #self.plugin.file_exists()
self.status.filename = self.plugin.get_file_name()
self.status.waituntil = self.plugin.time_plus_wait
- self.status.dl = self.plugin.get_file_url()
+ self.status.url = self.plugin.get_file_url()
+ self.status.want_reconnect = self.plugin.want_reconnect
+
diff --git a/download_thread.py b/download_thread.py
index b90559650..2b6fafdab 100644
--- a/download_thread.py
+++ b/download_thread.py
@@ -27,6 +27,7 @@ class Status(object):
""" Saves all status information
"""
def __init__(self, id):
+ self.type = None
self.status_queue = None
self.id = id
self.total_kb = 0
@@ -35,6 +36,9 @@ class Status(object):
self.expected_time = 0
self.filename = None
self.url = None
+ self.exists = None
+ self.waituntil = None
+ self.want_reconnect = None
def __call__(self, blocks_read, block_size, total_size):
if self.status_queue == None:
@@ -61,6 +65,7 @@ class Download_Thread(threading.Thread):
threading.Thread.__init__(self)
self.shutdown = False
self.parent = parent
+ self.setDaemon(True)
self.start()
def run(self):
@@ -78,11 +83,14 @@ class Download_Thread(threading.Thread):
pyfile.prepareDownload()
if not status.exists:
- return False
-
- while (time() < status.waituntil):
- print "waiting"
- sleep(1)
+ self.shutdown = True
+
+ if status.want_reconnect:
+ print "handle reconnect"
+ self.shutdown = True
+ while (time() < status.waituntil):
+ status.type = "waiting"
+ sleep(1) #eventuell auf genaue zeit warten
#missing wenn datei nicht auf server vorhanden
#if type=="check":
@@ -96,8 +104,8 @@ class Download_Thread(threading.Thread):
# status.type = "waiting"
# print params
# sleep(params+1)
-
+ print "going to download"
status.type = "downloading"
#startet downloader
- urllib.urlretrieve(status.dl, pyfile.download_folder + "/" + status.filename, status)
+ urllib.urlretrieve(status.url, pyfile.download_folder + "/" + status.filename, status)
self.shutdown = True