From 1de8f589216259f42ead0dddbc2954fae8e5e528 Mon Sep 17 00:00:00 2001
From: RaNaN <Mast3rRaNaN@hotmail.de>
Date: Tue, 26 May 2009 13:24:55 +0200
Subject: logic for container plugins implemented, basic plugin now downloads
 files, RSDF plugin added

---
 .hgignore                     |  3 ++
 Core.py                       | 26 +++++++--------
 Plugins/Plugin.py             | 18 +++++-----
 Plugins/RSDF.py               | 77 +++++++++++++++++++++++++++++++++++++++++++
 Plugins/RapidshareCom.py      |  8 ++---
 Plugins/YoutubeCom.py         | 10 +++---
 module/Py_Load_File.py        |  2 +-
 module/download_thread.py     |  3 +-
 module/network/Request.py     |  4 +--
 module/socket/SocketServer.py | 59 +++++++++++++++++++++++++++++++++
 module/thread_list.py         | 55 +++++++++++++++++--------------
 11 files changed, 202 insertions(+), 63 deletions(-)
 create mode 100644 Plugins/RSDF.py
 create mode 100644 module/socket/SocketServer.py

diff --git a/.hgignore b/.hgignore
index 5ff05dcd1..227b0b926 100644
--- a/.hgignore
+++ b/.hgignore
@@ -6,3 +6,6 @@ syntax: glob
 .svn
 *.DS_Store
 *.egg-info
+*.project
+*.pydevproject
+Downloads/*
\ No newline at end of file
diff --git a/Core.py b/Core.py
index 15a97d21f..e674c45a8 100644
--- a/Core.py
+++ b/Core.py
@@ -149,12 +149,8 @@ class Core(object):
 
     def append_link(self, link):
         if link not in self.thread_list.get_loaded_urls():
-            plugin = self.get_hoster(link)
-            if plugin != None:
-                self.__new_py_load_file(link)
-            else:
-                return False
-    
+            self.__new_py_load_file(link)
+                
     def extend_links(self, links):
         for link in links:
             self.append_link(link)
@@ -195,14 +191,14 @@ class Core(object):
     #def addLinks(self, newLinks, atTheBeginning):
         #pass
         
-    def get_hoster(self, url):
-        """ searches the right plugin for an url
-        """
-        for plugin, plugin_pattern in self.plugins_avaible.items():
-            if re.match(plugin_pattern, url) != None: #guckt ob übergebende url auf muster des plugins passt
-                return plugin
-        #logger: kein plugin gefunden
-        return None
+#    def get_hoster(self, url):
+#        """ searches the right plugin for an url
+#        """
+#        for plugin, plugin_pattern in self.plugins_avaible.items():
+#            if re.match(plugin_pattern, url) != None: #guckt ob übergebende url auf muster des plugins passt
+#                return plugin
+#        #logger: kein plugin gefunden
+#        return None
             
             
     def __new_py_load_file(self, url):
@@ -217,7 +213,7 @@ class Core(object):
             for pyfile in self.thread_list.py_downloading:
                 if pyfile.status.type == 'downloading':
                     print pyfile.status.filename + ": speed is" ,int(pyfile.status.get_speed()) ,"kb/s"
-                    print pyfile.status.filename + ": arraive in" ,pyfile.status.get_ETA() ,"seconds"
+                    print pyfile.status.filename + ": arraives in" ,pyfile.status.get_ETA() ,"seconds"
 
                     #try:
                     #    fn = pyfile.status.filename
diff --git a/Plugins/Plugin.py b/Plugins/Plugin.py
index 1babd3686..90781f765 100644
--- a/Plugins/Plugin.py
+++ b/Plugins/Plugin.py
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
+import re
 from time import time
 from module.network.Request import Request
 
@@ -11,11 +12,11 @@ class Plugin():
         self.plugin_pattern = None
         self.plugin_type = "hoster"
         pluginProp = {}
-        pluginProp ['name'] = "Beispiel Plugin"
+        pluginProp ['name'] = "Base Plugin"
         pluginProp ['version'] = "0.1"
         pluginProp ['format'] = "*.py"
         pluginProp ['description'] = """bla"""
-        pluginProp ['author'] = "Author"
+        pluginProp ['author'] = "Spoob"
         pluginProp ['author_email'] = "nn@nn.de"
         self.pluginProp = pluginProp 
         self.parent = parent
@@ -23,7 +24,7 @@ class Plugin():
         self.html = None
         self.time_plus_wait = None #time() + wait in seconds
         self.want_reconnect = None
-	self.multi_dl = True
+        self.multi_dl = True
     
     def set_parent_status(self):
         """ sets all available Statusinfos about a File in self.parent.status
@@ -39,25 +40,26 @@ class Plugin():
     def file_exists(self):
         """ returns True or False 
         """
-        if self.html != None:
-            self.download_html()
+        return True
         
     def get_file_url(self):
         """ returns the absolute downloadable filepath
         """
         if self.html != None:
             self.download_html()
-	return self.parent.url
+        return self.parent.url
 
     
     def get_file_name(self):
-        raise NotImplementedError
+        return re.findall("([^\/=]+)",self.parent.url)[-1]
     
     def wait_until(self):
         if self.html != None:
             self.download_html()
         return self.time_plus_wait
-        
+    
+    def proceed(self, url, location):
+        self.req.download(url, location)
     
     def __call__(self):
         return self.plugin_name
diff --git a/Plugins/RSDF.py b/Plugins/RSDF.py
new file mode 100644
index 000000000..65f85edb4
--- /dev/null
+++ b/Plugins/RSDF.py
@@ -0,0 +1,77 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+import urllib2
+import urllib
+import re
+import time
+import binascii
+import base64
+import sys
+
+from Plugin import Plugin
+from time import time
+
+class RSDF(Plugin):
+    
+    def __init__(self, parent):
+        Plugin.__init__(self, parent)
+        self.plugin_name = "RSDF"
+        self.plugin_pattern = r".*\.rsdf"
+        self.plugin_type = "container"
+        self.plugin_config = {}
+        pluginProp = {}
+        pluginProp ['name'] = "RSDF"
+        pluginProp ['version'] = "0.1"
+        pluginProp ['format'] = "*.py"
+        pluginProp ['description'] = """RSDF Plugin"""
+        pluginProp ['author'] = "RaNaN"
+        pluginProp ['author_email'] = "RaNaN@pyload.org"
+        self.pluginProp = pluginProp
+        self.parent = parent
+        self.multi_dl = True
+        self.links = []
+        
+    def file_exists(self):
+        """ returns True or False 
+        """
+        return True
+
+    def get_file_url(self):
+        """ returns the absolute downloadable filepath
+        """
+        return self.parent.url
+    
+    def __call__(self):
+        return self.plugin_name
+
+    def proceed(self, url, location):
+        try:
+            from Crypto.Cipher import AES
+            
+            infile = url.replace("\n","")
+            Key = binascii.unhexlify('8C35192D964DC3182C6F84F3252239EB4A320D2500000000')
+    
+            IV = binascii.unhexlify('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF')
+            IV_Cipher = AES.new(Key,AES.MODE_ECB)
+            IV = IV_Cipher.encrypt(IV)
+    
+            obj = AES.new(Key,AES.MODE_CFB,IV)
+    
+            rsdf = open(infile,'r')
+    
+            data = rsdf.read()
+            data = binascii.unhexlify(''.join(data.split()))
+            data = data.splitlines()
+    
+            for link in data:
+                link = base64.b64decode(link)
+                link = obj.decrypt(link)
+                decryptedUrl = link.replace('CCF: ','')
+                self.links.append(decryptedUrl)
+    
+            rsdf.close()
+            print self.links
+        
+        except:
+            print "Kein Crypto installiert, RSDF Plugin kann nicht genutzt werden"
\ No newline at end of file
diff --git a/Plugins/RapidshareCom.py b/Plugins/RapidshareCom.py
index f512b2460..0579ac8f8 100644
--- a/Plugins/RapidshareCom.py
+++ b/Plugins/RapidshareCom.py
@@ -17,22 +17,20 @@ class RapidshareCom(Plugin):
         self.plugin_pattern = r"http://(?:www.)?rapidshare.com/files/"
         self.plugin_type = "hoster"
         self.plugin_config = {}
-	pluginProp = {}
+        pluginProp = {}
         pluginProp ['name'] = "RapidshareCom"
         pluginProp ['version'] = "0.1"
         pluginProp ['format'] = "*.py"
         pluginProp ['description'] = """Rapidshare Plugin"""
         pluginProp ['author'] = "spoob"
         pluginProp ['author_email'] = "nn@nn.de"
-	pluginProp ['multi_dl'] = False
-	self.pluginProp = pluginProp
+        self.pluginProp = pluginProp
         self.parent = parent
         self.html = [None, None]
-        self.prehtml = None
         self.html_old = None         #time() where loaded the HTML
         self.time_plus_wait = None   #time() + wait in seconds
         self.want_reconnect = False
-	self.multi_dl = False
+        self.multi_dl = False
     
     def set_parent_status(self):
         """ sets all available Statusinfos about a File in self.parent.status
diff --git a/Plugins/YoutubeCom.py b/Plugins/YoutubeCom.py
index 7224323bb..20a9bd7d1 100644
--- a/Plugins/YoutubeCom.py
+++ b/Plugins/YoutubeCom.py
@@ -13,14 +13,14 @@ class YoutubeCom(Plugin):
         self.plugin_pattern = r"http://(www\.)?(de\.)?\youtube\.com/watch\?v=(.*)"
         self.plugin_type = "hoster"
         self.plugin_config = {}
-	pluginProp = {}
+        pluginProp = {}
         pluginProp ['name'] = "YoutubeCom"
         pluginProp ['version'] = "0.1"
         pluginProp ['format'] = "*.py"
         pluginProp ['description'] = """Youtube Plugin"""
         pluginProp ['author'] = "spoob"
         pluginProp ['author_email'] = "spoob@pyload.org"
-	self.pluginProp = pluginProp
+        self.pluginProp = pluginProp
         self.parent = parent
         self.html = None
         self.html_old = None         #time() where loaded the HTML
@@ -54,9 +54,9 @@ class YoutubeCom(Plugin):
     def get_file_name(self):
         if self.html == None:
             self.download_html()
-
-         file_name_pattern = r"<title>YouTube - (.*)</title>"
-         return re.search(file_name_pattern, self.html).group(1).replace("/", "") + '.mp4'
+        
+        file_name_pattern = r"<title>YouTube - (.*)</title>"
+        return re.search(file_name_pattern, self.html).group(1).replace("/", "") + '.mp4'
         
     def file_exists(self):
         """ returns True or False 
diff --git a/module/Py_Load_File.py b/module/Py_Load_File.py
index 9f962ffb3..ce2a10924 100644
--- a/module/Py_Load_File.py
+++ b/module/Py_Load_File.py
@@ -27,7 +27,7 @@ class PyLoadFile:
     
     def prepareDownload(self):
         self.status.exists = self.plugin.file_exists()
-	if self.status.exists:
+        if self.status.exists:
             self.status.filename = self.plugin.get_file_name()
             self.status.waituntil = self.plugin.time_plus_wait
             self.status.url = self.plugin.get_file_url()
diff --git a/module/download_thread.py b/module/download_thread.py
index f103b2271..6eb90138f 100644
--- a/module/download_thread.py
+++ b/module/download_thread.py
@@ -102,7 +102,6 @@ class Download_Thread(threading.Thread):
 
 	if not status.exists:
 	    raise "FileDontExists" #i know its deprecated, who cares^^
-
             
         if status.want_reconnect:
             print "handle reconnect"
@@ -115,7 +114,7 @@ class Download_Thread(threading.Thread):
 	    status.type = "downloading"
             print status.url , status.filename
             
-	    pyfile.plugin.req.download(status.url, pyfile.download_folder + "/" + status.filename)
+	    pyfile.plugin.proceed(status.url, pyfile.download_folder + "/" + status.filename)
             status.type = "finished"
         except:
             status.type = "failed"
diff --git a/module/network/Request.py b/module/network/Request.py
index 7ddeec876..1c0317cc7 100755
--- a/module/network/Request.py
+++ b/module/network/Request.py
@@ -39,7 +39,7 @@ class Request:
 	#self.opener.add_handler()
 	
 	self.opener.addheaders = [
-        ("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8"),
+        ("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.10"),
         ("Accept-Encoding","gzip,deflate"),
         ("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
         ("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7"),
@@ -47,7 +47,7 @@ class Request:
         ("Keep-Alive","300")]
 
 	self.downloader.addheaders = [
-        ("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8"),
+        ("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.10"),
         ("Accept-Encoding","gzip,deflate"),
         ("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
         ("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7")]
diff --git a/module/socket/SocketServer.py b/module/socket/SocketServer.py
new file mode 100644
index 000000000..5466195e8
--- /dev/null
+++ b/module/socket/SocketServer.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+# -'- coding: utf-8 -*.
+"""
+authored by:  RaNaN
+
+This modul class handels all incoming and outgoing data between server and gui
+
+"""
+import threading
+import socket
+import asyncore
+import asynchat
+
+class ServerThread(threading.Thread):
+	
+	def __init__(self):
+		threading.Thread.__init__ (self)
+		self.server = MainServerSocket(7272)
+
+	def run(self):
+		asyncore.loop()
+		
+	def stop(self):
+		asyncore.socket_map.clear()
+		self.server.close()
+
+
+class MainServerSocket(asyncore.dispatcher):
+    def __init__(self, port):
+        print 'initing MSS'
+        asyncore.dispatcher.__init__(self)
+        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.bind(('',port))
+        self.listen(5)
+    def handle_accept(self):
+        newSocket, address = self.accept()
+        print "Connected from", address
+        SecondaryServerSocket(newSocket)
+    def handle_close(self):
+	    print "going to close"
+	    self.close()
+
+
+
+class SecondaryServerSocket(asynchat.async_chat):
+    def __init__(self, *args):
+        print 'initing SSS'
+        asynchat.async_chat.__init__(self, *args)
+        self.set_terminator('\n')
+        self.data = []
+    def collect_incoming_data(self, data):
+        self.data.append(data)
+    def found_terminator(self):
+        self.push(''.join(self.data))
+        self.data = []
+        #having fun with the data
+    def handle_close(self):
+        print "Disconnected from", self.getpeername()
+        self.close()
\ No newline at end of file
diff --git a/module/thread_list.py b/module/thread_list.py
index 1f967540b..979a98c60 100644
--- a/module/thread_list.py
+++ b/module/thread_list.py
@@ -32,9 +32,9 @@ class Thread_List(object):
         self.download_queue = Queue()
         #self.status_queue = Queue()
         self.f_relation = [0,0]
-	self.lock = Lock()
-	self.py_downloading = [] # files downloading
-	self.occ_plugins = [] #occupied plugins	
+        self.lock = Lock()
+        self.py_downloading = [] # files downloading
+        self.occ_plugins = [] #occupied plugins	
 
     def create_thread(self):
         """ creates thread for Py_Load_File and append thread to self.threads
@@ -61,32 +61,37 @@ class Thread_List(object):
 
     def get_job(self):
         # return job if suitable, otherwise send thread idle
-	self.lock.acquire()
-	
-	pyfile = None
-	
-	for i in range(len(self.py_load_files)):
-	    if not self.py_load_files[i].modul.__name__ in self.occ_plugins:
-	        pyfile = self.py_load_files.pop(i)
-
-	if pyfile:	
-		self.py_downloading.append(pyfile)	
-		if not pyfile.plugin.multi_dl:
-	            self.occ_plugins.append(pyfile.modul.__name__)
-	
-	self.lock.release()
+        self.lock.acquire()
+        
+        pyfile = None
+        for i in range(len(self.py_load_files)):
+            if not self.py_load_files[i].modul.__name__ in self.occ_plugins:
+                pyfile = self.py_load_files.pop(i)
+                break
+        
+        if pyfile:
+            self.py_downloading.append(pyfile)	
+            if not pyfile.plugin.multi_dl:
+                self.occ_plugins.append(pyfile.modul.__name__)
+        
+        self.lock.release()
         return pyfile
-   
+    
+    
     def job_finished(self, pyfile):
-	self.lock.acquire()
-	
-	self.occ_plugins.remove(pyfile.modul.__name__)
-	self.py_downloading.remove(pyfile)	
+        self.lock.acquire()
+        
+        if not pyfile.plugin.multi_dl:
+            self.occ_plugins.remove(pyfile.modul.__name__)
+	    
+        self.py_downloading.remove(pyfile)	
+        
+        if pyfile.plugin.plugin_type == "container":
+            self.parent.extend_links(pyfile.plugin.links)
 
 	#remove from list, logging etc
-
-	self.lock.release()
-	return True
+        self.lock.release()
+        return True
 
     def extend_py_load_files(self):
         pass
-- 
cgit v1.2.3