summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar zoidberg10 <zoidberg@mujmail.cz> 2012-02-11 01:06:48 +0100
committerGravatar zoidberg10 <zoidberg@mujmail.cz> 2012-02-11 01:06:48 +0100
commita03d96fdd4c1ca1354ff304efb3cf88bb49f72a3 (patch)
treea9d013ffbf6b4f40f52a01a1249dbee368c40e0e /module
parentMerge (diff)
downloadpyload-a03d96fdd4c1ca1354ff304efb3cf88bb49f72a3.tar.xz
fix uloz.to premium, add turbobit.net free
Diffstat (limited to 'module')
-rw-r--r--module/plugins/hoster/TurbobitNet.py87
-rw-r--r--module/plugins/hoster/UlozTo.py24
-rw-r--r--module/plugins/internal/SimpleHoster.py28
3 files changed, 120 insertions, 19 deletions
diff --git a/module/plugins/hoster/TurbobitNet.py b/module/plugins/hoster/TurbobitNet.py
new file mode 100644
index 000000000..ee55d257b
--- /dev/null
+++ b/module/plugins/hoster/TurbobitNet.py
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-
+"""
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+ @author: zoidberg
+"""
+
+import re
+
+from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo
+from module.plugins.ReCaptcha import ReCaptcha
+
+from pycurl import HTTPHEADER
+
+class TurbobitNet(SimpleHoster):
+ __name__ = "TurbobitNet"
+ __type__ = "hoster"
+ __pattern__ = r"http://(?:\w*\.)?turbobit.net/(?P<ID>\w+).*"
+ __version__ = "0.01"
+ __description__ = """Turbobit.net plugin"""
+ __author_name__ = ("zoidberg")
+ __author_mail__ = ("zoidberg@mujmail.cz")
+
+ FILE_SIZE_PATTERN = r"<span class='file-icon1 document'>[^<]*</span>\s*\((?P<S>[^\)]+)\)"
+ FILE_NAME_PATTERN = r'<meta name="keywords" content="(?P<N>[^,]+)'
+ FILE_OFFLINE_PATTERN = r'<h2>File Not Found</h2>'
+ FILE_URL_REPLACEMENTS = [(r'(?<=http://)(.*?)(?=turbobit.net/)', '')]
+ SH_COOKIES = [("turbobit.net", "user_lang", "en")]
+
+ CAPTCHA_KEY_PATTERN = r'src="http://api\.recaptcha\.net/challenge\?k=([^"]+)"'
+ DOWNLOAD_URL_PATTERN = r'(?P<url>/download/redirect/[^"\']+)'
+ LIMIT_WAIT_PATTERN = r'<div id="time-limit-text">\s*.*?<span id=\'timeout\'>(\d+)</span> seconds'
+
+ def handleFree(self):
+ self.url = "http://turbobit.net/download/free/%s" % self.file_info['ID']
+ self.html = self.load(self.url)
+
+ found = re.search(self.CAPTCHA_KEY_PATTERN, self.html)
+ captcha_key = found.group(1) if found else '6LcTGLoSAAAAAHCWY9TTIrQfjUlxu6kZlTYP50_c'
+ recaptcha = ReCaptcha(self)
+
+ for i in range(5):
+ found = re.search(self.LIMIT_WAIT_PATTERN, self.html)
+ if found:
+ self.setWait(int(found.group(1)), True)
+ self.wait()
+ self.retry()
+
+ action, inputs = self.parseHtmlForm("action='#'")
+ inputs['recaptcha_challenge_field'], inputs['recaptcha_response_field'] = recaptcha.challenge(captcha_key)
+ if not inputs: self.parseError("inputs")
+ self.logDebug(inputs)
+
+ self.html = self.load(self.url, post = inputs)
+
+ if not "<div class='download-timer-header'>" in self.html:
+ self.invalidCaptcha()
+ else:
+ self.correctCaptcha()
+ break
+ else: self.fail("Invalid captcha")
+
+ self.req.http.lastURL = self.url
+ self.req.http.c.setopt(HTTPHEADER, ["X-Requested-With: XMLHttpRequest"])
+
+ self.setWait(60, False)
+ self.wait()
+
+ self.html = self.load("http://turbobit.net/download/getLinkAfterTimeout/" + self.file_info['ID'])
+ found = re.search(self.DOWNLOAD_URL_PATTERN, self.html)
+ if not found: self.parseError("free download link")
+ self.url = "http://turbobit.net" + found.group('url')
+ self.logDebug(self.url)
+ self.download(self.url)
+
+getInfo = create_getInfo(TurbobitNet) \ No newline at end of file
diff --git a/module/plugins/hoster/UlozTo.py b/module/plugins/hoster/UlozTo.py
index a67e52d4d..54138e7e5 100644
--- a/module/plugins/hoster/UlozTo.py
+++ b/module/plugins/hoster/UlozTo.py
@@ -27,7 +27,7 @@ class UlozTo(SimpleHoster):
__name__ = "UlozTo"
__type__ = "hoster"
__pattern__ = r"http://(\w*\.)?(uloz\.to|ulozto\.(cz|sk|net)|bagruj.cz|zachowajto.pl)/(?:live/)?(?P<id>\w+/[^/?]*)"
- __version__ = "0.84"
+ __version__ = "0.85"
__description__ = """uloz.to"""
__author_name__ = ("zoidberg")
@@ -45,11 +45,12 @@ class UlozTo(SimpleHoster):
CAPTCHA_PATTERN = r'<img class="captcha" src="(.*?(\d+).png)" alt="" />'
def setup(self):
- self.multiDL = self.resumeDownload = True
+ self.multiDL = self.premium
+ self.resumeDownload = True
def process(self, pyfile):
pyfile.url = re.sub(r"(?<=http://)([^/]+)", "www.ulozto.net", pyfile.url)
- self.html = self.load(pyfile.url, decode = True, cookies = False)
+ self.html = self.load(pyfile.url, decode = True, cookies = True)
passwords = self.getPassword().splitlines()
while self.PASSWD_PATTERN in self.html:
@@ -70,6 +71,8 @@ class UlozTo(SimpleHoster):
self.handlePremium()
else:
self.handleFree()
+
+ self.doCheckDownload()
def handleFree(self):
parsed_url = self.findDownloadURL(premium=False)
@@ -87,18 +90,16 @@ class UlozTo(SimpleHoster):
captcha_text = self.decryptCaptcha(captcha_url)
self.log.debug('CAPTCHA_URL:' + captcha_url + ' CAPTCHA ID:' + captcha_id + ' CAPTCHA TEXT:' + captcha_text)
-
- # download and check
- self.download(parsed_url, post={"captcha[id]": captcha_id, "captcha[text]": captcha_text, "freeDownload": "Download"}, cookies=True)
- self.doCheckDownload()
-
+
self.setStorage("captcha_id", captcha_id)
self.setStorage("captcha_text", captcha_text)
+ self.multiDL = True
+
+ self.download(parsed_url, post={"captcha[id]": captcha_id, "captcha[text]": captcha_text, "freeDownload": "Download"}, cookies=True)
def handlePremium(self):
parsed_url = self.findDownloadURL(premium=True)
self.download(parsed_url, post={"download": "Download"})
- self.doCheckDownload()
def findDownloadURL(self, premium=False):
msg = "%s link" % ("Premium" if premium else "Free")
@@ -113,7 +114,8 @@ class UlozTo(SimpleHoster):
"wrong_captcha": re.compile(self.CAPTCHA_PATTERN),
"offline": re.compile(self.FILE_OFFLINE_PATTERN),
"passwd": self.PASSWD_PATTERN,
- "paralell_dl": re.compile(r'<title>Uloz.to - Ji. stahuje.</title>')
+ "paralell_dl": "<title>Uloz.to - Již stahuješ</title>",
+ "not_found": "<title>Ulož.to</title>"
})
if check == "wrong_captcha":
@@ -130,5 +132,7 @@ class UlozTo(SimpleHoster):
self.setWait(300, True)
self.wait()
self.retry()
+ elif check == "not_found":
+ self.fail("Server error - file not downloadable")
getInfo = create_getInfo(UlozTo) \ No newline at end of file
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py
index 0aab2334c..555eefee3 100644
--- a/module/plugins/internal/SimpleHoster.py
+++ b/module/plugins/internal/SimpleHoster.py
@@ -23,14 +23,21 @@ from time import time
from module.plugins.Hoster import Hoster
from module.utils import html_unescape, fixup, parseFileSize
from module.network.RequestFactory import getURL
+from module.network.CookieJar import CookieJar
-def reSub(string, ruleslist):
+def replace_patterns(string, ruleslist):
for r in ruleslist:
rf, rt = r
string = re.sub(rf, rt, string)
#self.logDebug(rf, rt, string)
return string
+def set_cookies(cj, cookies):
+ for cookie in cookies:
+ if isinstance(cookie, tuple) and len(cookie) == 3:
+ domain, name, value = cookie
+ cj.setCookie(domain, name, value)
+
def parseHtmlTagAttrValue(attr_name, tag):
m = re.search(r"%s\s*=\s*([\"']?)((?<=\")[^\"]+|(?<=')[^']+|[^\s\"'][^>\s]+)\1" % attr_name, tag)
return m.group(2) if m else ''
@@ -62,9 +69,9 @@ def parseFileInfo(self, url = '', html = '', infomode = False):
# File online, return name and size
info['status'] = 2
if 'N' in info:
- info['name'] = reSub(info['N'], self.FILE_NAME_REPLACEMENTS)
+ info['name'] = replace_patterns(info['N'], self.FILE_NAME_REPLACEMENTS)
if 'S' in info:
- size = reSub(info['S'] + info['U'] if 'U' in info else info['S'], self.FILE_SIZE_REPLACEMENTS)
+ size = replace_patterns(info['S'] + info['U'] if 'U' in info else info['S'], self.FILE_SIZE_REPLACEMENTS)
info['size'] = parseFileSize(size)
elif isinstance(info['size'], (str, unicode)):
if 'units' in info: info['size'] += info['units']
@@ -80,8 +87,10 @@ def parseFileInfo(self, url = '', html = '', infomode = False):
def create_getInfo(plugin):
def getInfo(urls):
for url in urls:
- file_info = parseFileInfo(plugin, url, getURL(reSub(url, plugin.FILE_URL_REPLACEMENTS), \
- decode = not plugin.SH_BROKEN_ENCODING))
+ cj = CookieJar(plugin.__name__)
+ if isinstance(plugin.SH_COOKIES, list): set_cookies(cj, plugin.SH_COOKIES)
+ file_info = parseFileInfo(plugin, url, getURL(replace_patterns(url, plugin.FILE_URL_REPLACEMENTS), \
+ decode = not plugin.SH_BROKEN_ENCODING, cookies = cj))
yield file_info
return getInfo
@@ -97,7 +106,7 @@ class PluginParseError(Exception):
class SimpleHoster(Hoster):
__name__ = "SimpleHoster"
- __version__ = "0.18"
+ __version__ = "0.20"
__pattern__ = None
__type__ = "hoster"
__description__ = """Base hoster plugin"""
@@ -117,14 +126,15 @@ class SimpleHoster(Hoster):
FILE_URL_REPLACEMENTS = []
SH_BROKEN_ENCODING = False # Set to True or encoding name if encoding in http header is not correct
- SH_COOKIES = True
- SH_CHECK_TRAFFIC = False
+ SH_COOKIES = True # or False or list of tuples [(domain, name, value)]
+ SH_CHECK_TRAFFIC = False # True = force check traffic left for a premium account
def setup(self):
self.resumeDownload = self.multiDL = True if self.premium else False
+ if isinstance(self.SH_COOKIES, list): set_cookies(self.req.cj, self.SH_COOKIES)
def process(self, pyfile):
- pyfile.url = reSub(pyfile.url, self.FILE_URL_REPLACEMENTS)
+ pyfile.url = replace_patterns(pyfile.url, self.FILE_URL_REPLACEMENTS)
self.html = self.load(pyfile.url, decode = not self.SH_BROKEN_ENCODING, cookies = self.SH_COOKIES)
self.file_info = self.getFileInfo()
if self.premium and (not self.SH_CHECK_TRAFFIC or self.checkTrafficLeft()):