summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-30 15:54:38 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-30 15:54:38 +0200
commitfcdc1f730118050e390ad2d9fa337ce62809d9a6 (patch)
treebe69dbc646d385cc34b8de8cd8e0fc082a6c6882 /module/plugins
parent[XFileSharingPro][XFileSharingProFolder] Added default __pattern__ (diff)
downloadpyload-fcdc1f730118050e390ad2d9fa337ce62809d9a6.tar.xz
[SimpleCrypter] Merge with SimpleDereferer
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/crypter/Dereferer.py14
-rw-r--r--module/plugins/crypter/GooGl.py10
-rw-r--r--module/plugins/crypter/LinkSaveIn.py6
-rw-r--r--module/plugins/crypter/TinyurlCom.py6
-rw-r--r--module/plugins/internal/SimpleCrypter.py34
-rw-r--r--module/plugins/internal/SimpleDereferer.py107
-rw-r--r--module/plugins/internal/SimpleHoster.py2
7 files changed, 42 insertions, 137 deletions
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<DOMAIN>(?:[\d.]+|[\w\-]{3,}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)/.*?(?P<LINK>(?: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'<div class="link"><a href="(.+?)"'
-
- OFFLINE_PATTERN: (optional) Checks if the page is unreachable
- example: OFFLINE_PATTERN = r'File (deleted|not found)'
-
- TEMP_OFFLINE_PATTERN: (optional) Checks if the page is temporarily unreachable
- example: TEMP_OFFLINE_PATTERN = r'Server maintainance'
-
-
- You can override the getLinks method if you need a more sophisticated way to extract the redirect url.
- """
-
- URL_REPLACEMENTS = []
-
- LINK_PATTERN = None
-
- TEXT_ENCODING = False
- COOKIES = True
-
-
- def handleDirect(self, pyfile):
- header = self.load(pyfile.url, just_header=True, decode=True)
- if 'location' in header and header['location']:
- self.link = header['location']
-
-
- def decrypt(self, pyfile):
- self.prepare()
-
- self.handleDirect(pyfile)
-
- if not self.link:
- self.preload()
- self.checkStatus()
-
- self.link = self.getLink()
-
- if self.link:
- self.urls = [self.link]
-
- elif not self.urls and not self.packages: #@TODO: Remove in 0.4.10
- self.fail(_("No link grabbed"))
-
-
- def prepare(self):
- self.info = {}
- self.html = ""
- self.link = "" #@TODO: Move to hoster class in 0.4.10
-
- self.req.setOption("timeout", 120)
-
- if isinstance(self.COOKIES, list):
- set_cookies(self.req.cj, self.COOKIES)
-
- self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS)
-
-
- def preload(self):
- self.html = self.load(self.pyfile.url, cookies=bool(self.COOKIES), decode=not self.TEXT_ENCODING)
-
- if isinstance(self.TEXT_ENCODING, basestring):
- self.html = unicode(self.html, self.TEXT_ENCODING)
-
-
- def checkStatus(self):
- if hasattr(self, "OFFLINE_PATTERN") and re.search(self.OFFLINE_PATTERN, self.html):
- self.offline()
-
- elif hasattr(self, "TEMP_OFFLINE_PATTERN") and re.search(self.TEMP_OFFLINE_PATTERN, self.html):
- self.tempOffline()
-
-
- def getLink(self):
- try:
- link = re.search(self.LINK_PATTERN, self.html).group(1)
-
- except Exception, e:
- self.logWarning(e)
-
- else:
- return html_unescape(link.strip().decode('unicode-escape')) #@TODO: Move this check to plugin `load` method in 0.4.10
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py
index 1d44a6642..c333f34b0 100644
--- a/module/plugins/internal/SimpleHoster.py
+++ b/module/plugins/internal/SimpleHoster.py
@@ -511,7 +511,7 @@ class SimpleHoster(Hoster):
self.correctCaptcha()
- link = html_unescape(link.strip().decode('unicode-escape')) #@TODO: Move this check to plugin `load` method in 0.4.10
+ link = html_unescape(link.decode('unicode-escape').strip()) #@TODO: Move this check to plugin `load` method in 0.4.10
if not urlparse.urlparse(link).scheme:
url_p = urlparse.urlparse(self.pyfile.url)