From fcdc1f730118050e390ad2d9fa337ce62809d9a6 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 30 May 2015 15:54:38 +0200 Subject: [SimpleCrypter] Merge with SimpleDereferer --- module/plugins/crypter/Dereferer.py | 14 ++-- module/plugins/crypter/GooGl.py | 10 +-- module/plugins/crypter/LinkSaveIn.py | 6 +- module/plugins/crypter/TinyurlCom.py | 6 +- module/plugins/internal/SimpleCrypter.py | 34 ++++++--- module/plugins/internal/SimpleDereferer.py | 107 ----------------------------- module/plugins/internal/SimpleHoster.py | 2 +- 7 files changed, 42 insertions(+), 137 deletions(-) delete mode 100644 module/plugins/internal/SimpleDereferer.py (limited to 'module/plugins') diff --git a/module/plugins/crypter/Dereferer.py b/module/plugins/crypter/Dereferer.py index 8e56a7bfc..985c97f3d 100644 --- a/module/plugins/crypter/Dereferer.py +++ b/module/plugins/crypter/Dereferer.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- -from module.plugins.internal.SimpleDereferer import SimpleDereferer +from module.plugins.internal.SimpleCrypter import SimpleCrypter -class Dereferer(SimpleDereferer): +class Dereferer(SimpleCrypter): __name__ = "Dereferer" __type__ = "crypter" - __version__ = "0.12" + __version__ = "0.13" __pattern__ = r'https?://(?:www\.)?(?:\w+\.)*?(?P(?:[\d.]+|[\w\-]{3,}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)/.*?(?P(?:ht|f)tps?://.+)' __config__ = [("use_subfolder" , "bool", "Save package to subfolder" , True), @@ -36,9 +36,5 @@ class Dereferer(SimpleDereferer): self.HOSTER_NAME = "".join(part.capitalize() for part in re.split(r'(\.|\d+)', self.HOSTER_DOMAIN) if part != '.') - def getLink(self): - try: - return re.match(self.__pattern__, pyfile.url).group('LINK').strip() - - except Exception, e: - self.logWarning(e) + def getLinks(self): + return [re.match(self.__pattern__, pyfile.url).group('LINK').strip()] diff --git a/module/plugins/crypter/GooGl.py b/module/plugins/crypter/GooGl.py index 30e193b9d..b36e22884 100644 --- a/module/plugins/crypter/GooGl.py +++ b/module/plugins/crypter/GooGl.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- -from module.plugins.internal.SimpleDereferer import SimpleDereferer, create_getInfo +from module.plugins.internal.SimpleCrypter import SimpleCrypter, create_getInfo from module.common.json_layer import json_loads -class GooGl(SimpleDereferer): +class GooGl(SimpleCrypter): __name__ = "GooGl" __type__ = "crypter" - __version__ = "0.02" + __version__ = "0.03" __pattern__ = r'https?://(?:www\.)?goo\.gl/([a-zA-Z]+/)?\w+' @@ -22,11 +22,11 @@ class GooGl(SimpleDereferer): OFFLINE_PATTERN = r'has been disabled|does not exist' - def getLink(self): + def getLinks(self): rep = self.load(self.API_URL, get={'shortUrl': self.pyfile.url}) self.logDebug("JSON data: " + rep) rep = json_loads(rep) - return rep['longUrl'] if "longUrl" in rep else None + return [rep['longUrl']] if "longUrl" in rep else None getInfo = create_getInfo(GooGl) diff --git a/module/plugins/crypter/LinkSaveIn.py b/module/plugins/crypter/LinkSaveIn.py index 95652096d..dce74b689 100644 --- a/module/plugins/crypter/LinkSaveIn.py +++ b/module/plugins/crypter/LinkSaveIn.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- -from module.plugins.internal.SimpleDereferer import SimpleDereferer, create_getInfo +from module.plugins.internal.SimpleCrypter import SimpleCrypter, create_getInfo -class LinkSaveIn(SimpleDereferer): +class LinkSaveIn(SimpleCrypter): __name__ = "LinkSaveIn" __type__ = "crypter" - __version__ = "2.04" + __version__ = "2.05" __pattern__ = r'https?://(?:www\.)?linksave\.in/\w+' __config__ = [("use_subfolder" , "bool", "Save package to subfolder" , True), diff --git a/module/plugins/crypter/TinyurlCom.py b/module/plugins/crypter/TinyurlCom.py index 4b5b35457..e2cf50358 100644 --- a/module/plugins/crypter/TinyurlCom.py +++ b/module/plugins/crypter/TinyurlCom.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- -from module.plugins.internal.SimpleDereferer import SimpleDereferer, create_getInfo +from module.plugins.internal.SimpleCrypter import SimpleCrypter, create_getInfo -class TinyurlCom(SimpleDereferer): +class TinyurlCom(SimpleCrypter): __name__ = "TinyurlCom" __type__ = "crypter" - __version__ = "0.01" + __version__ = "0.02" __pattern__ = r'https?://(?:www\.)?(preview\.)?tinyurl\.com/[\w-]+' diff --git a/module/plugins/internal/SimpleCrypter.py b/module/plugins/internal/SimpleCrypter.py index b843a28f0..2d4d52f3c 100644 --- a/module/plugins/internal/SimpleCrypter.py +++ b/module/plugins/internal/SimpleCrypter.py @@ -11,7 +11,7 @@ from module.utils import fixup, html_unescape class SimpleCrypter(Crypter, SimpleHoster): __name__ = "SimpleCrypter" __type__ = "crypter" - __version__ = "0.46" + __version__ = "0.47" __pattern__ = r'^unmatchable$' __config__ = [("use_subfolder" , "bool", "Save package to subfolder" , True), #: Overrides core.config['general']['folder_per_package'] @@ -59,7 +59,7 @@ class SimpleCrypter(Crypter, SimpleHoster): URL_REPLACEMENTS = [] TEXT_ENCODING = False #: Set to True or encoding name if encoding in http header is not correct - COOKIES = True #: or False or list of tuples [(domain, name, value)] + COOKIES = True #: or False or list of tuples [(domain, name, value)] LOGIN_ACCOUNT = False LOGIN_PREMIUM = False @@ -99,18 +99,34 @@ class SimpleCrypter(Crypter, SimpleHoster): self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS) + def handleDirect(self, pyfile): + while True: + header = self.load(self.link or pyfile.url, just_header=True, decode=True) + if 'location' in header and header['location']: + self.link = header['location'] + else: + break + + def decrypt(self, pyfile): self.prepare() - self.preload() - self.checkInfo() + self.logDebug("Looking for link redirect...") + self.handleDirect(pyfile) + + if self.link: + self.urls = [self.link] + + else: + self.preload() + self.checkInfo() - self.links = self.getLinks() + self.links = self.getLinks() - if hasattr(self, 'PAGES_PATTERN') and hasattr(self, 'loadPage'): - self.handlePages(pyfile) + if hasattr(self, 'PAGES_PATTERN') and hasattr(self, 'loadPage'): + self.handlePages(pyfile) - self.logDebug("Package has %d links" % len(self.links)) + self.logDebug("Package has %d links" % len(self.links)) if self.links: self.packages = [(self.info['name'], self.links, self.info['folder'])] @@ -155,7 +171,7 @@ class SimpleCrypter(Crypter, SimpleHoster): links = [urlparse.urljoin(baseurl, link) if not urlparse.urlparse(link).scheme else link \ for link in re.findall(self.LINK_PATTERN, self.html)] - return [html_unescape(l.strip().decode('unicode-escape')) for l in links] + return [html_unescape(l.decode('unicode-escape').strip()) for l in links] def handlePages(self, pyfile): diff --git a/module/plugins/internal/SimpleDereferer.py b/module/plugins/internal/SimpleDereferer.py deleted file mode 100644 index 2e7e08321..000000000 --- a/module/plugins/internal/SimpleDereferer.py +++ /dev/null @@ -1,107 +0,0 @@ -# -*- coding: utf-8 -*- - -import re - -from module.plugins.Crypter import Crypter -from module.plugins.internal.SimpleHoster import create_getInfo, set_cookies -from module.utils import html_unescape - - -class SimpleDereferer(Crypter): - __name__ = "SimpleDereferer" - __type__ = "crypter" - __version__ = "0.14" - - __pattern__ = r'^unmatchable$' - __config__ = [] #@TODO: Remove in 0.4.10 - - __description__ = """Simple dereferer plugin""" - __license__ = "GPLv3" - __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - - - """ - Following patterns should be defined by each crypter: - - LINK_PATTERN: Regex to catch the redirect url in group(1) - example: LINK_PATTERN = r'