summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar sebnapi <devnull@localhost> 2009-05-10 20:41:41 +0200
committerGravatar sebnapi <devnull@localhost> 2009-05-10 20:41:41 +0200
commita78e7b73331f34875b51ec145553d7434f286cec (patch)
tree8b36f68d55948ae213e17176613060a7bfa966d2
parentApproach for Plugindesign (diff)
downloadpyload-a78e7b73331f34875b51ec145553d7434f286cec.tar.xz
new plugin-sys
-rw-r--r--Core.py40
-rw-r--r--Plugins/Plugin.py58
-rw-r--r--[-rwxr-xr-x]Plugins/RapidshareCom.py120
-rw-r--r--download_thread.py9
4 files changed, 180 insertions, 47 deletions
diff --git a/Core.py b/Core.py
index c0c3a5d56..f69d59608 100644
--- a/Core.py
+++ b/Core.py
@@ -47,9 +47,7 @@ class Core(object):
#self.applicationPath = ""
self.search_updates = False
self.plugins_folder = ""
- self.read_config()
- self.plugins = {}
- self.get_plugins(self.plugins_folder)
+ self.read_config()
self.thread_list = Thread_List(self)
self.create_download_folder(self.download_folder)
self.create_link_file(self.link_file)
@@ -67,19 +65,31 @@ class Core(object):
self.plugins_folder = 'Plugins'
path.append(self.plugins_folder)
- def get_plugins(self, plugin_folder):
+ def get_avial_plugins(self, plugin_folder):
""" searches the plugin-folder for plugins
"""
- for file in glob(plugin_folder + sep + '*.py'):
- if file.endswith('.py'):
- self.plugin_file = basename(file).replace('.py', '')
- try:
- self.new_plugin = __import__(self.plugin_file)
- if self.new_plugin.plugin_type in "hoster" or self.new_plugin.plugin_type in "container":
- print "Plugin geladen: " + self.new_plugin.plugin_name
- self.plugins[self.plugin_file] = __import__(self.plugin_file)
- except:
- print "Fehlerhaftes Plugin: " + self.plugin_file
+ #for file in glob(plugin_folder + "/" + '*.py'):
+ #if file.endswith('.py'):
+ #self.plugin_file = basename(file).replace('.py', '')
+ #print self.plugin_file
+ #try:
+ #self.new_plugin = __import__(self.plugin_file)
+ #if self.new_plugin.plugin_type in "hoster" or self.new_plugin.plugin_type in "container":
+ #print "Plugin geladen: " + self.new_plugin.plugin_name
+ #self.plugins[self.plugin_file] = __import__(self.plugin_file)
+ #except:
+ #print "Fehlerhaftes Plugin: " + self.plugin_file
+ pluginlist = []
+ import os
+ for f in os.listdir(plugin_folder):
+ if f.split(".")[1] == "py":
+ pluginlist.append(__import__(f.split('.')[0],globals(),locals(),[]))
+ print pluginlist
+ for modul in pluginlist:
+ instance = modul.Test_plug()
+ print instance.Function()
+ print instance.pluginProp ['name']
+ print "s"
def _get_links(self, link_file):
""" funktion nur zum testen ohne gui bzw. tui
@@ -174,4 +184,4 @@ class Core(object):
break
testLoader = Core()
-testLoader.start()
+testLoader.get_avial_plugins('Plugins')
diff --git a/Plugins/Plugin.py b/Plugins/Plugin.py
new file mode 100644
index 000000000..591d32594
--- /dev/null
+++ b/Plugins/Plugin.py
@@ -0,0 +1,58 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from time import time
+
+
+class Plugin():
+
+ def __init__(self, parent):
+ self.plugin_name = None
+ self.plugin_pattern = None
+ self.plugin_type = ""
+ pluginProp = {}
+ pluginProp ['name'] = "Beispiel Plugin"
+ pluginProp ['version'] = "0.1"
+ pluginProp ['format'] = "*.py"
+ pluginProp ['description'] = """bla"""
+ pluginProp ['author'] = "Author"
+ pluginProp ['author_email'] = "nn@nn.de"
+ self.pluginProp = pluginProp
+ self.parent = parent
+ self.html = ""
+ self.time_plus_wait = None #time() + wait in seconds
+
+ def set_parent_status(self):
+ """ sets all available Statusinfos about a File in self.parent.status
+ """
+ pass
+
+ def download_html(self):
+ """ gets the url from self.parent.url saves html in self.html and parses
+ """
+ html = ""
+ self.html = html
+
+ def file_exists(self):
+ """ returns True or False
+ """
+ if self.html != None:
+ self.download_html()
+
+ def get_file_url(self):
+ """ returns the absolute downloadable filepath
+ """
+ if self.html != None:
+ self.download_html()
+
+ def get_file_name(self):
+ pass
+
+ def wait_until(self):
+ if self.html != None:
+ self.download_html()
+ return self.time_plus_wait
+
+
+ def __call__(self):
+ return self.plugin_name
diff --git a/Plugins/RapidshareCom.py b/Plugins/RapidshareCom.py
index a3ca09e87..69a8cf933 100755..100644
--- a/Plugins/RapidshareCom.py
+++ b/Plugins/RapidshareCom.py
@@ -1,37 +1,97 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
import urllib2
import urllib
import re
import time
-plugin_name = "Rapidshare.com"
-plugin_type = "hoster"
-plugin_pattern = r"http://(?:www.)?rapidshare.com/files/"
-
-def get_file_url(url):
- root_url = urllib2.urlopen(url).read()
+from Plugin import Plugin
+from time import time
- if re.search(r".*The File could not be found.*", root_url) != None or re.search(r"(<p>This limit is reached.</p>)", root_url) or re.search(r"(.*is momentarily not available.*)", root_url):
- return ("missing", url)
- else:
- last_url = urllib2.urlopen(re.search(r"<form action=\"(.*?)\"", root_url).group(1), urllib.urlencode({"dl.start" : "Free"})).read()
- if re.search(r".*is already downloading.*", last_url) != None:
- print "IP laed bereits Datei von Rapidshare"
- return ('wait', 10)
+class RapidshareCom(Plugin):
+
+ def __init__(self, parent):
+ self.plugin_name = "Rapidshare.com"
+ self.plugin_pattern = r"http://(?:www.)?rapidshare.com/files/"
+ self.plugin_type = "hoster"
+ self.plugin_config = {}
+ pluginProp = {}
+ pluginProp ['name'] = "RapidshareCom"
+ pluginProp ['version'] = "0.1"
+ pluginProp ['format'] = "*.py"
+ pluginProp ['description'] = """Rapidshare Plugin"""
+ pluginProp ['author'] = "spoob"
+ pluginProp ['author_email'] = "nn@nn.de"
+ self.pluginProp = pluginProp
+ self.parent = parent
+ self.html = ""
+ self.html_old = None #time() where loaded the HTML
+ self.time_plus_wait = None #time() + wait in seconds
+
+ def set_parent_status(self):
+ """ sets all available Statusinfos about a File in self.parent.status
+ """
+ if self.html == None:
+ self.download_html()
+ self.parent.status.filename = self.get_file_name()
+ self.parent.status.url = self.get_file_url()
+ self.parent.status.wait = self.wait_until()
+
+ def download_html(self):
+ """ gets the url from self.parent.url saves html in self.html and parses
+ """
+ url = self.parent.url
+ html = urllib2.urlopen(url).read()
+ self.html = html
+ self.html_old = time()
+ file_server_url = re.search(r"<form action=\"(.*?)\"", self.html).group(1)
+ free_user_encode = urllib.urlencode({"dl.start" : "Free"})
+ self.free_user_html = urllib2.urlopen(file_server_url, free_user_encode).read()
+ if re.search(r".*is already downloading.*", self.html) != None:
+ 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
+ except:
+ if re.search(r".*Currently a lot of users.*", self.html) != None:
+ return ('wait', 2*60)
+ wait_seconds = re.search(r"var c=(.*);.*", self.html).group(1)
+ self.time_plus_wait = time() + wait_seconds
+
+ def file_exists(self):
+ """ returns True or False
+ """
+ if self.html == None:
+ 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):
+ return False
else:
- try:
- wait_minutes = re.search(r"Or try again in about (\d+) minute", last_url).group(1)
- return ('wait', wait_minutes)
-
- except:
- if re.search(r".*Currently a lot of users.*", last_url) != None:
- return ('wait', 2)
- else:
- wait_seconds = re.search(r"var c=(.*);.*", last_url).group(1)
- file_url = re.search(r".*name=\"dlf\" action=\"(.*)\" method=.*", last_url).group(1)
- file_name = file_url.split('/')[-1]
-
- for second in range(1, int(wait_seconds) + 1):
- print "Noch " + str(int(wait_seconds) + 1 - second - 1) + " Sekunden zum Download von " + file_name
- time.sleep(1)
-
- return ("download", (file_url, file_name))
+ return True
+
+ def get_file_url(self):
+ """ returns the absolute downloadable filepath
+ """
+ if self.html == None:
+ self.download_html()
+ 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)
+
+ 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]
+
+ def wait_until(self):
+ if self.html == None:
+ self.download_html()
+ return self.time_plus_wait
+
+
+ def __call__(self):
+ return self.plugin_name
diff --git a/download_thread.py b/download_thread.py
index ee4d4deca..7808d22f1 100644
--- a/download_thread.py
+++ b/download_thread.py
@@ -26,8 +26,8 @@ import urllib
class Status(object):
""" Saves all status information
"""
- def __init__(self, id, status_queue):
- self.status_queue = status_queue
+ def __init__(self, id):
+ self.status_queue = None
self.id = id
self.total_kb = 0
self.downloaded_kb = 0
@@ -37,6 +37,8 @@ class Status(object):
self.url = None
def __call__(self, blocks_read, block_size, total_size):
+ if self.status_queue == None:
+ return False
self.start = time()
self.last_status = time()
self.total_kb = total_size / 1024
@@ -49,6 +51,9 @@ class Status(object):
if self.last_status+0.2 < time():
self.status_queue.put(copy(self))
self.last_status = time()
+
+ def set_status_queue(self, queue):
+ self.status_queue = queue
class Download_Thread(threading.Thread):