diff options
-rw-r--r-- | module/Utils.py | 25 | ||||
-rw-r--r-- | module/plugins/AccountManager.py | 12 | ||||
-rw-r--r-- | module/plugins/accounts/UploadedTo.py | 30 | ||||
-rw-r--r-- | module/plugins/accounts/X7To.py | 13 | ||||
-rw-r--r-- | module/plugins/container/RSDF.py | 24 | ||||
-rw-r--r-- | module/plugins/hoster/FreakshareCom.py | 282 |
6 files changed, 213 insertions, 173 deletions
diff --git a/module/Utils.py b/module/Utils.py index 4605aaf75..e6e40c956 100644 --- a/module/Utils.py +++ b/module/Utils.py @@ -15,6 +15,7 @@ def chmod(*args): except: pass + def decode(string): """ decode string with utf if possible """ try: @@ -22,6 +23,7 @@ def decode(string): except: return string + def removeChars(string, repl): """ removes all chars in repl from string""" if type(string) == str: @@ -29,13 +31,14 @@ def removeChars(string, repl): elif type(string) == unicode: return string.translate(dict([(ord(s), None) for s in repl])) + def save_join(*args): """ joins a path, encoding aware """ paths = [] for i, path in enumerate(args): # remove : for win comp, but not for first segment if i: - path = path.replace(":","") + path = path.replace(":", "") path = decode(path) @@ -43,6 +46,7 @@ def save_join(*args): paths.append(tmp) return join(*paths) + def compare_time(start, end): start = map(int, start) end = map(int, end) @@ -55,6 +59,7 @@ def compare_time(start, end): elif start < now and end < now and start > end: return True else: return False + def formatSize(size): """formats size of bytes""" size = int(size) @@ -65,9 +70,11 @@ def formatSize(size): steps += 1 return "%.2f %s" % (size, sizes[steps]) + def freeSpace(folder): if os.name == "nt": import ctypes + free_bytes = ctypes.c_ulonglong(0) ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes)) return free_bytes.value @@ -77,8 +84,9 @@ def freeSpace(folder): s = statvfs(folder) return s.f_bsize * s.f_bavail -def uniqify(seq, idfun=None): - # order preserving + +def uniqify(seq, idfun=None): +# order preserving if idfun is None: def idfun(x): return x seen = {} @@ -93,6 +101,7 @@ def uniqify(seq, idfun=None): result.append(item) return result + def parseFileSize(string): #returns bytes string = string.strip().lower() p = re.compile(r"(\d+[\.,]\d+)(.*)") @@ -110,6 +119,16 @@ def parseFileSize(string): #returns bytes return 0 + +def lock(func): + def new(*args): + args[0].lock.acquire() + res = func(*args) + args[0].lock.release() + return res + + return new + if __name__ == "__main__": print freeSpace(".") diff --git a/module/plugins/AccountManager.py b/module/plugins/AccountManager.py index e4c858a43..94af7cd82 100644 --- a/module/plugins/AccountManager.py +++ b/module/plugins/AccountManager.py @@ -20,12 +20,13 @@ from os.path import exists from shutil import copy +from threading import Lock + from module.PullEvents import AccountUpdateEvent -from module.utils import chmod +from module.utils import chmod, lock ACC_VERSION = 1 -######################################################################## class AccountManager(): """manages all accounts""" @@ -37,6 +38,7 @@ class AccountManager(): self.accounts = {} # key = ( plugin ) self.plugins = {} + self.lock = Lock() self.initAccountPlugins() @@ -138,7 +140,7 @@ class AccountManager(): for name in self.core.pluginManager.getAccountPlugins(): self.accounts[name] = {} - #---------------------------------------------------------------------- + @lock def updateAccount(self, plugin , user, password=None, options={}): """add or update account""" if self.accounts.has_key(plugin): @@ -149,7 +151,7 @@ class AccountManager(): self.saveAccounts() if updated: p.scheduleRefresh(user, force=False) - #---------------------------------------------------------------------- + @lock def removeAccount(self, plugin, user): """remove account""" @@ -159,7 +161,7 @@ class AccountManager(): self.saveAccounts() - + @lock def getAccountInfos(self, force=True, refresh=False): data = {} diff --git a/module/plugins/accounts/UploadedTo.py b/module/plugins/accounts/UploadedTo.py index 5fcc77498..6852e5243 100644 --- a/module/plugins/accounts/UploadedTo.py +++ b/module/plugins/accounts/UploadedTo.py @@ -30,27 +30,33 @@ class UploadedTo(Account): __author_mail__ = ("mkaay@mkaay.de") def loadAccountInfo(self, user, req): - html = req.load("http://uploaded.to/me", cookies=True) - premium = '<a href="me#premium"><em>Premium</em>' in html + req.load("http://uploaded.to/language/en") + html = req.load("http://uploaded.to/me") - if premium: - raw_traffic = re.search(r'<th colspan="2"><b class="cB">([^<]+)', html).group(1) - raw_valid = re.search(r"<td>Duration:</td>\s*<th>([^<]+)", html, re.MULTILINE).group(1) - raw_valid = re.findall(r"\d+", raw_valid) + premium = '<a href="me#premium"><em>Premium</em>' in html or '<em>Premium</em></th>' in html - traffic = int(self.parseTraffic(raw_traffic)) + if premium: + #raw_traffic = re.search(r'<th colspan="2"><b class="cB">([^<]+)', html).group(1) + raw_valid = re.search(r"<td>Duration:</td>\s*<th>([^<]+)", html, re.MULTILINE).group(1).strip() - validuntil = time() + 24 * 60 * 60 * int(raw_valid[0]) + 60 * 60 * int(raw_valid[1]) + if raw_valid == "unlimited": + validuntil = -1 + else: + raw_valid = re.findall(r"\d+", raw_valid) + validuntil = time() + 24 * 60 * 60 * int(raw_valid[0]) + 60 * 60 * int(raw_valid[1]) - return {"validuntil":validuntil, "trafficleft":traffic, "maxtraffic":50*1024*1024} + + return {"validuntil":validuntil, "trafficleft": -1} else: return {"premium" : False, "validuntil" : -1} def login(self, user, data, req): - page = req.load("http://uploaded.to/io/login", post={ "id" : user, "pw" : data["password"], "_" : ""}) - if "User and password do not match!" in page: - self.wrongPassword() req.load("http://uploaded.to/language/en") req.cj.setCookie("uploaded.to", "lang", "en") + + page = req.load("http://uploaded.to/io/login", post={ "id" : user, "pw" : data["password"], "_" : ""}) + + if "User and password do not match!" in page: + self.wrongPassword() diff --git a/module/plugins/accounts/X7To.py b/module/plugins/accounts/X7To.py index abfb13e5e..8c2bf245a 100644 --- a/module/plugins/accounts/X7To.py +++ b/module/plugins/accounts/X7To.py @@ -33,8 +33,17 @@ class X7To(Account): def loadAccountInfo(self, user, req):
page = req.load("http://www.x7.to/my")
- valid = re.search("Premium-Mitglied bis ([0-9]*-[0-9]*-[0-9]*)", page, re.IGNORECASE).group(1)
- valid = int(mktime(strptime(valid, "%Y-%m-%d")))
+ validCheck = re.search("Premium-Mitglied bis ([0-9]*-[0-9]*-[0-9]*)", page, re.IGNORECASE)
+ if validCheck:
+ valid = validCheck.group(1)
+ valid = int(mktime(strptime(valid, "%Y-%m-%d")))
+ else:
+ validCheck = re.search("Premium member until ([0-9]*-[0-9]*-[0-9]*)", page, re.IGNORECASE)
+ if validCheck:
+ valid = validCheck.group(1)
+ valid = int(mktime(strptime(valid, "%Y-%m-%d")))
+ else:
+ valid = 0
trafficleft = re.search(r'<em style="white-space:nowrap">([\d]*[,]?[\d]?[\d]?) (KB|MB|GB)</em>', page, re.IGNORECASE)
if trafficleft:
diff --git a/module/plugins/container/RSDF.py b/module/plugins/container/RSDF.py index 93e2d717b..ea5cd67f2 100644 --- a/module/plugins/container/RSDF.py +++ b/module/plugins/container/RSDF.py @@ -3,6 +3,7 @@ import base64 import binascii +import re from module.plugins.Container import Container @@ -31,17 +32,18 @@ class RSDF(Container): rsdf = open(infile, 'r') data = rsdf.read() - data = binascii.unhexlify(''.join(data.split())) - data = data.splitlines() + rsdf.close() - links = [] - for link in data: - link = base64.b64decode(link) - link = obj.decrypt(link) - decryptedUrl = link.replace('CCF: ', '') - links.append(decryptedUrl) + if re.search(r"<title>404 - Not Found</title>", data) is None: + data = binascii.unhexlify(''.join(data.split())) + data = data.splitlines() - rsdf.close() + links = [] + for link in data: + link = base64.b64decode(link) + link = obj.decrypt(link) + decryptedUrl = link.replace('CCF: ', '') + links.append(decryptedUrl) - self.log.debug("%s: adding package %s with %d links" % (self.__name__,pyfile.package().name,len(links))) - self.packages.append((pyfile.package().name, links)) + self.log.debug("%s: adding package %s with %d links" % (self.__name__,pyfile.package().name,len(links))) + self.packages.append((pyfile.package().name, links)) diff --git a/module/plugins/hoster/FreakshareCom.py b/module/plugins/hoster/FreakshareCom.py index 1c4e04dee..d795147a6 100644 --- a/module/plugins/hoster/FreakshareCom.py +++ b/module/plugins/hoster/FreakshareCom.py @@ -1,141 +1,143 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import re -from module.plugins.Hoster import Hoster -from module.plugins.ReCaptcha import ReCaptcha - -class FreakshareCom(Hoster): - __name__ = "FreakshareCom" - __type__ = "hoster" - __pattern__ = r"http://(?:www\.)?freakshare\.(net|com)/files/\S*?/" - __version__ = "0.33" - __description__ = """Freakshare.com Download Hoster""" - __author_name__ = ("sitacuisses","spoob","mkaay") - __author_mail__ = ("sitacuisses@yahoo.de","spoob@pyload.org","mkaay@mkaay.de") - - def setup(self): - self.html = None - self.wantReconnect = False - self.multiDL = False - self.req_opts = [] - - def process(self, pyfile): - self.pyfile = pyfile - pyfile.url = pyfile.url.replace("freakshare.net/","freakshare.com/") - - if self.account: - self.html = self.load(pyfile.url, cookies=False) - pyfile.name = self.get_file_name() - self.download(pyfile.url) - - else: - self.prepare() - self.get_file_url() - - self.download(self.pyfile.url, post=self.req_opts) - - - def prepare(self): - pyfile = self.pyfile - - self.wantReconnect = False - - self.download_html() - - if not self.file_exists(): - self.offline() - - self.setWait( self.get_waiting_time() ) - - pyfile.name = self.get_file_name() - - self.wait() - - return True - - def download_html(self): - self.html = self.load(self.pyfile.url, cookies=True) - - def get_file_url(self): - """ returns the absolute downloadable filepath - """ - if self.html is None: - self.download_html() - if not self.wantReconnect: - self.req_opts = self.get_download_options() # get the Post options for the Request - #file_url = self.pyfile.url - #return file_url - else: - self.offline() - - def get_file_name(self): - if self.html is None: - self.download_html() - if not self.wantReconnect: - file_name = re.search(r"<h1\sclass=\"box_heading\"\sstyle=\"text-align:center\;\">([^ ]+)", self.html).group(1) - return file_name - else: - return self.pyfile.url - - def get_waiting_time(self): - if self.html is None: - self.download_html() - - if "Der Traffic f\xc3\xbcr heute ist verbraucht!" in self.html or "Your Traffic is used up for today" in self.html: - self.wantReconnect = True - return 24*3600 - - if re.search(r"This file does not exist!", self.html) is not None: - self.offline() - - timestring = re.search('\s*var\sdownloadWait\s=\s(\d*);', self.html).group(1) - if timestring: - sec = int(timestring) + 1 #add 1 sec as tenths of seconds are cut off - else: - sec = 0 - return sec - - def file_exists(self): - """ returns True or False - """ - if self.html is None: - self.download_html() - if re.search(r"Sorry, this Download doesnt exist anymore", self.html) is not None: - return False - else: - return True - - def get_download_options(self): - re_envelope = re.search(r".*?value=\"Free\sDownload\".*?\n*?(.*?<.*?>\n*)*?\n*\s*?</form>", self.html).group(0) #get the whole request - to_sort = re.findall(r"<input\stype=\"hidden\"\svalue=\"(.*?)\"\sname=\"(.*?)\"\s\/>", re_envelope) - request_options = [] - - for item in to_sort: #Name value pairs are output reversed from regex, so we reorder them - request_options.append((item[1], item[0])) - - herewego = self.load(self.pyfile.url, None, request_options, cookies=True) # the actual download-Page - - # comment this in, when it doesnt work - # with open("DUMP__FS_.HTML", "w") as fp: - # fp.write(herewego) - - to_sort = re.findall(r"<input\stype=\".*?\"\svalue=\"(\S*?)\".*?name=\"(\S*?)\"\s.*?\/>", herewego) - request_options = [] - - # comment this in, when it doesnt work as well - #print "\n\n%s\n\n" % ";".join(["%s=%s" % x for x in to_sort]) - - for item in to_sort: #Same as above - request_options.append((item[1], item[0])) - - challenge = re.search(r"http://api\.recaptcha\.net/challenge\?k=([0-9A-Za-z]+)", herewego) - - if challenge: - re_captcha = ReCaptcha(self) - challenge, result = re_captcha.challenge(challenge.group(1)) - - request_options.append(("recaptcha_challenge_field", challenge)) - request_options.append(("recaptcha_response_field", result)) - +#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import re
+from module.plugins.Hoster import Hoster
+from module.plugins.ReCaptcha import ReCaptcha
+
+class FreakshareCom(Hoster):
+ __name__ = "FreakshareCom"
+ __type__ = "hoster"
+ __pattern__ = r"http://(?:www\.)?freakshare\.(net|com)/files/\S*?/"
+ __version__ = "0.33"
+ __description__ = """Freakshare.com Download Hoster"""
+ __author_name__ = ("sitacuisses","spoob","mkaay")
+ __author_mail__ = ("sitacuisses@yahoo.de","spoob@pyload.org","mkaay@mkaay.de")
+
+ def setup(self):
+ self.html = None
+ self.wantReconnect = False
+ self.multiDL = False
+ self.req_opts = []
+
+ def process(self, pyfile):
+ self.pyfile = pyfile
+ pyfile.url = pyfile.url.replace("freakshare.net/","freakshare.com/")
+
+ if self.account:
+ self.html = self.load(pyfile.url, cookies=False)
+ pyfile.name = self.get_file_name()
+ self.download(pyfile.url)
+
+ else:
+ self.prepare()
+ self.get_file_url()
+
+ self.download(self.pyfile.url, post=self.req_opts)
+
+
+ def prepare(self):
+ pyfile = self.pyfile
+
+ self.wantReconnect = False
+
+ self.download_html()
+
+ if not self.file_exists():
+ self.offline()
+
+ self.setWait( self.get_waiting_time() )
+
+ pyfile.name = self.get_file_name()
+
+ self.wait()
+
+ return True
+
+ def download_html(self):
+ self.html = self.load(self.pyfile.url)
+
+ def get_file_url(self):
+ """ returns the absolute downloadable filepath
+ """
+ if self.html is None:
+ self.download_html()
+ if not self.wantReconnect:
+ self.req_opts = self.get_download_options() # get the Post options for the Request
+ #file_url = self.pyfile.url
+ #return file_url
+ else:
+ self.offline()
+
+ def get_file_name(self):
+ if self.html is None:
+ self.download_html()
+ if not self.wantReconnect:
+ file_name = re.search(r"<h1\sclass=\"box_heading\"\sstyle=\"text-align:center\;\">([^ ]+)", self.html).group(1)
+ return file_name
+ else:
+ return self.pyfile.url
+
+ def get_waiting_time(self):
+ if self.html is None:
+ self.download_html()
+
+ if "Der Traffic f\xc3\xbcr heute ist verbraucht!" in self.html or "Your Traffic is used up for today" in self.html:
+ self.wantReconnect = True
+ return 24*3600
+
+ if re.search(r"This file does not exist!", self.html) is not None:
+ self.offline()
+ timestring = re.search('\s*var\sdownloadWait\s=\s(\d*);', self.html)
+ if timestring:
+ return int(timestring.group(1)) + 1 #add 1 sec as tenths of seconds are cut off
+ timestring = re.search('\s*var\stime\s=\s(\d*)[.0];', self.html)
+ if timestring:
+ return int(timestring.group(1)) + 1 #add 1 sec as tenths of seconds are cut off
+ else:
+ return 60
+
+
+ def file_exists(self):
+ """ returns True or False
+ """
+ if self.html is None:
+ self.download_html()
+ if re.search(r"Sorry, this Download doesnt exist anymore", self.html) is not None:
+ return False
+ else:
+ return True
+
+ def get_download_options(self):
+ re_envelope = re.search(r".*?value=\"Free\sDownload\".*?\n*?(.*?<.*?>\n*)*?\n*\s*?</form>", self.html).group(0) #get the whole request
+ to_sort = re.findall(r"<input\stype=\"hidden\"\svalue=\"(.*?)\"\sname=\"(.*?)\"\s\/>", re_envelope)
+ request_options = []
+
+ for item in to_sort: #Name value pairs are output reversed from regex, so we reorder them
+ request_options.append((item[1], item[0]))
+
+ herewego = self.load(self.pyfile.url, None, request_options) # the actual download-Page
+
+ # comment this in, when it doesnt work
+ # with open("DUMP__FS_.HTML", "w") as fp:
+ # fp.write(herewego)
+
+ to_sort = re.findall(r"<input\stype=\".*?\"\svalue=\"(\S*?)\".*?name=\"(\S*?)\"\s.*?\/>", herewego)
+ request_options = []
+
+ # comment this in, when it doesnt work as well
+ #print "\n\n%s\n\n" % ";".join(["%s=%s" % x for x in to_sort])
+
+ for item in to_sort: #Same as above
+ request_options.append((item[1], item[0]))
+
+ challenge = re.search(r"http://api\.recaptcha\.net/challenge\?k=([0-9A-Za-z]+)", herewego)
+
+ if challenge:
+ re_captcha = ReCaptcha(self)
+ challenge, result = re_captcha.challenge(challenge.group(1))
+
+ request_options.append(("recaptcha_challenge_field", challenge))
+ request_options.append(("recaptcha_response_field", result))
+
return request_options
\ No newline at end of file |