Repository navigation
Expand file tree
/
Copy pathSimpleDereferer.py
More file actions
94 lines (60 loc) · 2.58 KB
/
Copy pathSimpleDereferer.py
File metadata and controls
94 lines (60 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
import re
import urllib
from pyload.plugin.Crypter import Crypter
from pyload.plugin.internal.SimpleHoster import getFileURL, set_cookies
class SimpleDereferer(Crypter):
__name = "SimpleDereferer"
__type = "crypter"
__version = "0.11"
__pattern = r'^unmatchable$'
__config = [("use_subfolder" , "bool", "Save package to subfolder" , True),
("subfolder_per_pack", "bool", "Create a subfolder for each package", True)]
__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.
"""
LINK_PATTERN = None
TEXT_ENCODING = False
COOKIES = True
def decrypt(self, pyfile):
link = getFileURL(self, pyfile.url)
if not link:
try:
link = urllib.unquote(re.match(self.__pattern, pyfile.url).group('LINK'))
except Exception:
self.prepare()
self.preload()
self.checkStatus()
link = self.getLink()
if link.strip():
self.urls = [link]
def prepare(self):
self.info = {}
self.html = ""
self.req.setOption("timeout", 120)
if isinstance(self.COOKIES, list):
set_cookies(self.req.cj, self.COOKIES)
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:
return re.search(self.LINK_PATTERN, self.html).group(1)
except Exception:
pass