diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-06-22 15:20:14 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-06-22 15:20:14 +0200 |
commit | 58de24c63f11f53137fab3854d6324c5a321a37c (patch) | |
tree | 5239c6f40b059d5bfd8caae45810e4e01a1494e6 | |
parent | sharonline captcha method (diff) | |
download | pyload-58de24c63f11f53137fab3854d6324c5a321a37c.tar.xz |
reconnect works with new plugin system
-rw-r--r-- | Plugins/Plugin.py | 4 | ||||
-rw-r--r-- | Plugins/RapidshareCom.py | 32 | ||||
-rw-r--r-- | config | 2 | ||||
-rw-r--r-- | module/download_thread.py | 10 | ||||
-rw-r--r-- | module/thread_list.py | 1 | ||||
-rw-r--r-- | pyLoadCli.py | 49 |
6 files changed, 61 insertions, 37 deletions
diff --git a/Plugins/Plugin.py b/Plugins/Plugin.py index 2f13d3c43..c0724c390 100644 --- a/Plugins/Plugin.py +++ b/Plugins/Plugin.py @@ -59,9 +59,11 @@ class Plugin(): pyfile.status.waituntil = self.time_plus_wait pyfile.status.url = self.get_file_url() pyfile.status.want_reconnect = self.want_reconnect - + + thread.wait(self.parent) + return True 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 aa6a55f03..20423197b 100644 --- a/Plugins/RapidshareCom.py +++ b/Plugins/RapidshareCom.py @@ -30,16 +30,30 @@ class RapidshareCom(Plugin): if self.config['premium']: self.multi_dl = True - def set_parent_status(self): - """ sets all available Statusinfos about a File in self.parent.status - """ - if self.html[0] == None: - self.download_html() + def prepare(self, thread): + pyfile = self.parent - self.get_wait_time() - self.parent.status.filename = self.get_file_name() - self.parent.status.url = self.get_file_url() - self.parent.status.waituntil = self.wait_until() + self.want_reconnect = False + + self.download_html() + + pyfile.status.exists = self.file_exists() + + if not pyfile.status.exists: + raise Exception, "The file was not found on the server." + + self.download_serverhtml() + + pyfile.status.filename = self.get_file_name() + + pyfile.status.waituntil = self.time_plus_wait + pyfile.status.url = self.get_file_url() + pyfile.status.want_reconnect = self.want_reconnect + + + thread.wait(self.parent) + + return True def download_html(self): """ gets the url from self.parent.url saves html in self.html and parses @@ -4,7 +4,7 @@ language: de download_folder = Downloads link_file = links.txt failed_file = failed_links.txt -use_reconnect = False +use_reconnect = True reconnect_method = ./reconnect.sh max_downloads = 3 [updates] diff --git a/module/download_thread.py b/module/download_thread.py index ce353d6f6..202ebcafb 100644 --- a/module/download_thread.py +++ b/module/download_thread.py @@ -50,6 +50,10 @@ class Status(object): return ((self.size()-self.kB_left()) * 100) / self.size() return 0 +class Reconnect(Exception): + pass + + class Download_Thread(threading.Thread): def __init__(self, parent): threading.Thread.__init__(self) @@ -66,10 +70,12 @@ class Download_Thread(threading.Thread): if self.loadedPyFile: try: self.download(self.loadedPyFile) + except Reconnect: + pass except Exception, e: traceback.print_exc() self.loadedPyFile.status.type = "failed" - self.loadedPyFile.status.error = e.message + self.loadedPyFile.status.error = str(e) finally: self.parent.job_finished(self.loadedPyFile) sleep(0.5) @@ -103,7 +109,7 @@ class Download_Thread(threading.Thread): if self.parent.init_reconnect() or self.parent.reconnecting: pyfile.status.type = "reconnected" pyfile.status.want_reconnect = False - return False + raise Reconnect sleep(1) pyfile.status.want_reconnect = False return True diff --git a/module/thread_list.py b/module/thread_list.py index 63f20c6f5..1dadb91d3 100644 --- a/module/thread_list.py +++ b/module/thread_list.py @@ -159,6 +159,7 @@ class Thread_List(object): def reconnect(self): reconn = subprocess.Popen(self.parent.config['reconnect_method']) reconn.wait() + time.sleep(1) ip = re.match(".*Current IP Address: (.*)</body>.*", urllib2.urlopen("http://checkip.dyndns.org/").read()).group(1) #versuchen neue ip aus zu lesen while ip == "": #solange versuch bis neue ip ausgelesen ip = re.match(".*Current IP Address: (.*)</body>.*", urllib2.urlopen("http://checkip.dyndns.org/").read()).group(1) diff --git a/pyLoadCli.py b/pyLoadCli.py index 0d721136b..759298409 100644 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -19,7 +19,6 @@ ### import os import sys -import thread import time from module.remote.ClientSocket import SocketThread @@ -36,7 +35,7 @@ class pyLoadCli: self.links_added = 0 os.system("clear") - self.println(1, blue("py")+ yellow("Load")+ white(" Command Line Interface")) + self.println(1, blue("py") + yellow("Load") + white(" Command Line Interface")) self.println(2, "") self.start() @@ -69,16 +68,17 @@ class pyLoadCli: return "%.2i:%.2i:%.2i" % (hours, minutes, seconds) def println(self, line, content): - print "\033["+ str(line) +";0H\033[2K" + str(content) + "\033["+ str((self.inputline if self.inputline > 0 else self.inputline + 1) - 1) +";0H" + print "\033[" + str(line) + ";0H\033[2K" + str(content) + "\033[" + str((self.inputline if self.inputline > 0 else self.inputline + 1) - 1) + ";0H" def print_input(self): self.println(self.inputline, white(" Input: ") + self.input) + self.println(self.inputline+1, "") def data_arrived(self, obj): """Handle incoming data""" if obj.command == "update": #print updated information - self.println(1, blue("py")+ yellow("Load")+ white(" Command Line Interface")) + self.println(1, blue("py") + yellow("Load") + white(" Command Line Interface")) self.println(2, "") self.println(3, white("%s Downloads:" % (len(obj.data)))) line = 4 @@ -88,14 +88,14 @@ class pyLoadCli: percent = download["percent"] z = percent / 4 speed += download['speed'] - self.println(line, blue(download["name"])) + self.println(line, cyan(download["name"])) line += 1 - self.println(line, blue("[") + yellow(z * "#" + (25-z) * " ") + blue("] ") + green(str(percent)+"%") + " Speed: " + green(str(int(download['speed'])) + " kb/s") +" Finished in: " + green(self.format_time(download['eta']))) + self.println(line, blue("[") + yellow(z * "#" + (25-z) * " ") + blue("] ") + green(str(percent) + "%") + " Speed: " + green(str(int(download['speed'])) + " kb/s") + " Finished in: " + green(self.format_time(download['eta']))) line += 1 if download["status"] == "waiting": - self.println(line, download["name"]) + self.println(line, cyan(download["name"])) line += 1 - self.println(line, "waiting") + self.println(line, "waiting: " + green(self.format_time(download["wait_until"]- time.time()))) line += 1 self.println(line, "") line += 1 @@ -114,15 +114,15 @@ class pyLoadCli: if self.pos[0] == 0:# main menu self.println(line, "") line += 1 - self.println(line, mag("1.")+" Add Links") + self.println(line, mag("1.") + " Add Links") line += 1 - self.println(line, mag("2.")+" Remove Links") + self.println(line, mag("2.") + " Remove Links") line += 1 - self.println(line, mag("3.")+" Pause Server") + self.println(line, mag("3.") + " Pause Server") line += 1 - self.println(line, mag("4.")+" Kill Server") + self.println(line, mag("4.") + " Kill Server") line += 1 - self.println(line, mag("5.")+" Quit") + self.println(line, mag("5.") + " Quit") line += 1 self.println(line, "") line += 1 @@ -133,18 +133,19 @@ class pyLoadCli: line += 1 self.println(line, "") line += 1 - self.println(line,"Links added: "+mag(str(self.links_added))) + self.println(line, "Links added: " + mag(str(self.links_added))) line += 1 self.println(line, "") line += 1 self.println(line, "") line += 1 - self.println(line, mag("0.")+" back to main menu") + self.println(line, mag("0.") + " back to main menu") line += 1 elif self.pos[0] == 2:#remove links pass - self.inputline = line +1 + self.println(line, "") + self.inputline = line + 1 self.print_input() def handle_input(self): @@ -169,7 +170,7 @@ class pyLoadCli: sys.exit() elif self.pos[0] == 1: #add links if inp[:7] == "http://": - self.thread.push_exec("add_links", [(inp, None)] ) + self.thread.push_exec("add_links", [(inp, None)]) self.links_added += 1 self.build_menu() @@ -214,25 +215,25 @@ class _GetchWindows: return msvcrt.getch() def blue(string): - return "\033[1;34m"+ string + "\033[0m" + return "\033[1;34m" + string + "\033[0m" def green(string): - return "\033[1;32m"+ string + "\033[0m" + return "\033[1;32m" + string + "\033[0m" def yellow(string): - return "\033[1;33m"+ string + "\033[0m" + return "\033[1;33m" + string + "\033[0m" def red(string): - return "\033[1;31m"+ string + "\033[0m" + return "\033[1;31m" + string + "\033[0m" def cyan(string): - return "\033[1;36m"+ string + "\033[0m" + return "\033[1;36m" + string + "\033[0m" def mag(string): - return "\033[1;35m"+ string + "\033[0m" + return "\033[1;35m" + string + "\033[0m" def white(string): - return "\033[1;37m"+ string + "\033[0m" + return "\033[1;37m" + string + "\033[0m" if __name__ == "__main__": if len(sys.argv) != 4: |