diff options
-rw-r--r-- | module/network/HTTPRequest.py | 10 | ||||
-rw-r--r-- | module/plugins/hoster/EnteruploadCom.py | 3 | ||||
-rw-r--r-- | module/plugins/hoster/FshareVn.py | 42 | ||||
-rw-r--r-- | module/plugins/internal/SimpleHoster.py | 76 |
4 files changed, 75 insertions, 56 deletions
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index e58fd114e..40f18f2a5 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -28,7 +28,11 @@ from cStringIO import StringIO from module.plugins.Plugin import Abort def myquote(url): - return quote(url, safe="%/:=&?~#+!$,;'@()*[]") + return quote(url.encode('utf_8') if isinstance(url, unicode) else url, safe="%/:=&?~#+!$,;'@()*[]") + +def myurlencode(data): + return urlencode(dict((x.encode('utf_8') if isinstance(x, unicode) else x, \ + y.encode('utf_8') if isinstance(y, unicode) else y ) for x, y in data.iteritems())) bad_headers = range(400, 404) + range(405, 418) + range(500, 506) @@ -141,7 +145,7 @@ class HTTPRequest(): def setRequestContext(self, url, get, post, referer, cookies, multipart=False): """ sets everything needed for the request """ - url = myquote(str(url)) + url = myquote(url) if get: get = urlencode(get) @@ -158,7 +162,7 @@ class HTTPRequest(): elif type(post) == str: pass else: - post = urlencode(post) + post = myurlencode(post) self.c.setopt(pycurl.POSTFIELDS, post) else: diff --git a/module/plugins/hoster/EnteruploadCom.py b/module/plugins/hoster/EnteruploadCom.py index 5e899ae96..37e24a93f 100644 --- a/module/plugins/hoster/EnteruploadCom.py +++ b/module/plugins/hoster/EnteruploadCom.py @@ -29,7 +29,8 @@ class EnteruploadCom(SimpleHoster): __author_mail__ = ("zoidberg@mujmail.cz")
FILE_INFO_PATTERN = r'<h3>(?P<N>[^<]+)</h3>\s*<span>File size:\s*(?P<S>[0-9.]+)\s*(?P<U>[kKMG])i?B</span>'
- FILE_OFFLINE_PATTERN = r'<(b|h2)>File Not Found</(b|h2)>|<font class="err">No such file with this filename</font>'
+ FILE_OFFLINE_PATTERN = r'<(b|h2)>File Not Found</(b|h2)>|<font class="err">No such file with this filename</font>'
+ TEMP_OFFLINE_PATTERN = r'>This server is in maintenance mode\. Refresh this page in some minutes\.<'
URL_REPLACEMENTS = [(r"(http://(?:www\.)?enterupload.com/\w+).*", r"\1")]
FORM1_PATTERN = r'<form method="POST" action=\'\' style="display: none;">(.*?)</form>'
diff --git a/module/plugins/hoster/FshareVn.py b/module/plugins/hoster/FshareVn.py index 91cc167b1..5a8b00c17 100644 --- a/module/plugins/hoster/FshareVn.py +++ b/module/plugins/hoster/FshareVn.py @@ -11,67 +11,77 @@ def getInfo(urls): "action" : "check_link", "arrlinks" : url }, decode = True) - + file_info = parseFileInfo(FshareVn, url, html) - + yield file_info class FshareVn(SimpleHoster): __name__ = "FshareVn" __type__ = "hoster" __pattern__ = r"http://(www\.)?fshare.vn/file/.*" - __version__ = "0.11" + __version__ = "0.12" __description__ = """FshareVn Download Hoster""" __author_name__ = ("zoidberg") __author_mail__ = ("zoidberg@mujmail.cz") FILE_INFO_PATTERN = r'<p>(?P<N>[^<]+)<\\/p>\\r\\n\s*<p>(?P<S>[0-9,.]+)\s*(?P<U>[kKMG])i?B<\\/p>' FILE_OFFLINE_PATTERN = r'<div class=\\"f_left file_(enable|w)\\">' - + DOWNLOAD_URL_PATTERN = r"<a class=\"bt_down\" id=\"down\".*window.location='([^']+)'\">" FORM_PATTERN = r'<form action="" method="post" name="frm_download">(.*?)</form>' FORM_INPUT_PATTERN = r'<input[^>]* name="?([^" ]+)"? value="?([^" ]+)"?[^>]*>' - VIP_URL_PATTERN = r'<form action="([^>]+)" method="get" name="frm_download">' + VIP_URL_PATTERN = r'<form action="([^>]+)" method="get" name="frm_download">' + WAIT_PATTERN = u"Vui lòng chờ cho lượt download kế tiếp !" def process(self, pyfile): self.html = self.load('http://www.fshare.vn/check_link.php', post = { "action": "check_link", "arrlinks": pyfile.url }, decode = True) - self.getFileInfo() - if self.account: + self.getFileInfo() + if self.account and self.premium: self.handlePremium() else: self.handleFree() def handleFree(self): self.html = self.load(self.pyfile.url, decode = True) + if self.WAIT_PATTERN in self.html: + self.retry(300, 20, "Try again later...") + found = re.search(self.FORM_PATTERN, self.html, re.DOTALL) if not found: self.parseError('FORM') form = found.group(1) inputs = dict(re.findall(self.FORM_INPUT_PATTERN, form)) - - self.html = self.load(self.pyfile.url, post = inputs) - + + self.html = self.load(self.pyfile.url, post = inputs, decode = True) + + if self.WAIT_PATTERN in self.html: + self.retry(300, 20, "Try again later...") + found = re.search(self.DOWNLOAD_URL_PATTERN, self.html) if not found: self.parseError('Free URL') url = found.group(1) - + found = re.search(r'var count = (\d+)', self.html) self.setWait(int(found.group(1)) if found else 30) self.wait() - + self.download(url) - + def handlePremium(self): header = self.load(self.pyfile.url, just_header = True) if 'location' in header and header['location'].startswith('http://download'): self.logDebug('Direct download') self.download(self.pyfile.url) else: - self.html = self.load(self.pyfile.url) + self.html = self.load(self.pyfile.url) found = re.search(self.VIP_URL_PATTERN, self.html) - if not found: self.parseError('VIP URL') + if not found: + if self.retries >= 3: self.resetAccount() + self.account.relogin(self.user) + self.retry(5, 1, 'VIP URL not found') url = found.group(1) self.logDebug('VIP URL: ' + url) - self.download(url)
\ No newline at end of file + self.download(url)
\ No newline at end of file diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 4a03ec60a..14cb8a15e 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -13,7 +13,7 @@ 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 """ from urlparse import urlparse @@ -29,10 +29,11 @@ def reSub(string, ruleslist): string = sub(rf, rt, string) return string -def parseFileInfo(self, url = '', html = ''): +def parseFileInfo(self, url = '', html = '', infomode = False): if not html and hasattr(self, "html"): html = self.html info = {"name" : url, "size" : 0, "status" : 3} - + online = False + if hasattr(self, "FILE_OFFLINE_PATTERN") and search(self.FILE_OFFLINE_PATTERN, html): # File offline info['status'] = 1 @@ -40,28 +41,31 @@ def parseFileInfo(self, url = '', html = ''): for pattern in ("FILE_INFO_PATTERN", "FILE_NAME_PATTERN", "FILE_SIZE_PATTERN"): try: info = dict(info, **search(getattr(self, pattern), html).groupdict()) + online = True except AttributeError: continue - - if len(info) > 3: - # File online, return name and size - info['status'] = 2 - if 'N' in info: info['name'] = reSub(info['N'], self.FILE_NAME_REPLACEMENTS) - if 'S' in info: - size = info['S'] + info['U'] if 'U' in info else info['S'] - print repr(size) - size = parseFileSize(reSub(size, self.FILE_SIZE_REPLACEMENTS)) - print repr(self.FILE_SIZE_REPLACEMENTS), repr(size) - info['size'] = size - - print info - return info + + if online: + # File online, return name and size + info['status'] = 2 + if 'N' in info: info['name'] = reSub(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) + info['size'] = parseFileSize(size) + elif isinstance(info['size'], (str, unicode)): + if 'units' in info: info['size'] += info['units'] + info['size'] = parseFileSize(info['size']) + + if infomode: + return info + else: + return info['name'], info['size'], info['status'], url def create_getInfo(plugin): def getInfo(urls): for url in urls: file_info = parseFileInfo(plugin, url, getURL(reSub(url, plugin.FILE_URL_REPLACEMENTS), decode=True)) - yield file_info['name'], file_info['size'], file_info['status'], url + yield file_info return getInfo class PluginParseError(Exception): @@ -73,7 +77,7 @@ class PluginParseError(Exception): class SimpleHoster(Hoster): __name__ = "SimpleHoster" - __version__ = "0.13" + __version__ = "0.14" __pattern__ = None __type__ = "hoster" __description__ = """Base hoster plugin""" @@ -81,8 +85,8 @@ class SimpleHoster(Hoster): __author_mail__ = ("zoidberg@mujmail.cz") """ These patterns should be defined by each hoster: - FILE_INFO_PATTERN = r'(?P<N>file_name) (?P<S>file_size) (?P<U>units)' - or FILE_NAME_INFO = r'(?P<N>file_name)' + FILE_INFO_PATTERN = r'(?P<N>file_name) (?P<S>file_size) (?P<U>units)' + or FILE_NAME_INFO = r'(?P<N>file_name)' and FILE_SIZE_INFO = r'(?P<S>file_size) (?P<U>units)' FILE_OFFLINE_PATTERN = r'File (deleted|not found)' TEMP_OFFLINE_PATTERN = r'Server maintainance' @@ -93,12 +97,12 @@ class SimpleHoster(Hoster): FILE_URL_REPLACEMENTS = [] def setup(self): - self.resumeDownload = self.multiDL = True if self.account else False + self.resumeDownload = self.multiDL = True if self.account else False def process(self, pyfile): - pyfile.url = reSub(pyfile.url, self.FILE_URL_REPLACEMENTS) + pyfile.url = reSub(pyfile.url, self.FILE_URL_REPLACEMENTS) self.html = self.load(pyfile.url, decode = True) - self.file_info = self.getFileInfo() + self.file_info = self.getFileInfo() if self.account: self.handlePremium() else: @@ -106,34 +110,34 @@ class SimpleHoster(Hoster): def getFileInfo(self): self.logDebug("URL: %s" % self.pyfile.url) - if hasattr(self, "TEMP_OFFLINE_PATTERN") and search(self.TEMP_OFFLINE_PATTERN, html): + if hasattr(self, "TEMP_OFFLINE_PATTERN") and search(self.TEMP_OFFLINE_PATTERN, self.html): self.tempOffline() - - file_info = parseFileInfo(self) - if file_info['status'] == 1: + + file_info = parseFileInfo(self, infomode = True) + if file_info['status'] == 1: self.offline() elif file_info['status'] != 2: - self.logDebug(file_info) + self.logDebug(file_info) self.parseError('File info') - + if file_info['name']: self.pyfile.name = file_info['name'] else: self.pyfile.name = html_unescape(urlparse(self.pyfile.url).path.split("/")[-1]) - + if file_info['size']: self.pyfile.size = file_info['size'] else: self.logError("File size not parsed") self.logDebug("FILE NAME: %s FILE SIZE: %s" % (self.pyfile.name, self.pyfile.size)) - return file_info - + return file_info + def handleFree(self): self.fail("Free download not implemented") - + def handlePremium(self): self.fail("Premium download not implemented") - + def parseError(self, msg): - raise PluginParseError(msg)
\ No newline at end of file + raise PluginParseError(msg)
\ No newline at end of file |