Repository navigation
Expand file tree
/
Copy pathMultiHoster.py
More file actions
116 lines (79 loc) · 3.59 KB
/
Copy pathMultiHoster.py
File metadata and controls
116 lines (79 loc) · 3.59 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
import re
from pyload.plugin.Plugin import Fail, Retry
from pyload.plugin.internal.SimpleHoster import SimpleHoster, replace_patterns, set_cookies
class MultiHoster(SimpleHoster):
__name = "MultiHoster"
__type = "hoster"
__version = "0.39"
__pattern = r'^unmatchable$'
__config = [("use_premium" , "bool", "Use premium account if available" , True),
("revertfailed", "bool", "Revert to standard download if fails", True)]
__description = """Multi hoster plugin"""
__license = "GPLv3"
__authors = [("Walter Purcaro", "vuolter@gmail.com")]
LOGIN_ACCOUNT = True
def setup(self):
self.chunkLimit = 1
self.multiDL = bool(self.account)
self.resumeDownload = self.premium
def prepare(self):
self.info = {}
self.html = ""
self.link = "" #@TODO: Move to hoster class in 0.4.10
self.directDL = False #@TODO: Move to hoster class in 0.4.10
if not self.getConfig('use_premium', True):
self.retryFree()
if self.LOGIN_ACCOUNT and not self.account:
self.fail(_("Required account not found"))
self.req.setOption("timeout", 120)
if isinstance(self.COOKIES, list):
set_cookies(self.req.cj, self.COOKIES)
if self.DIRECT_LINK is None:
self.directDL = self.__pattern != r'^unmatchable$' and re.match(self.__pattern, self.pyfile.url)
else:
self.directDL = self.DIRECT_LINK
self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS)
def process(self, pyfile):
try:
self.prepare()
if self.directDL:
self.checkInfo()
self.logDebug("Looking for direct download link...")
self.handle_direct(pyfile)
if not self.link and not self.lastDownload:
self.preload()
self.checkErrors()
self.checkStatus(getinfo=False)
if self.premium and (not self.CHECK_TRAFFIC or self.checkTrafficLeft()):
self.logDebug("Handled as premium download")
self.handle_premium(pyfile)
elif not self.LOGIN_ACCOUNT or (not self.CHECK_TRAFFIC or self.checkTrafficLeft()):
self.logDebug("Handled as free download")
self.handle_free(pyfile)
self.downloadLink(self.link, True)
self.checkFile()
except Fail, e: #@TODO: Move to PluginThread in 0.4.10
if self.premium:
self.logWarning(_("Premium download failed"))
self.retryFree()
elif self.getConfig('revertfailed', True) \
and "new_module" in self.core.pluginManager.hosterPlugins[self.getClassName()]:
hdict = self.core.pluginManager.hosterPlugins[self.getClassName()]
tmp_module = hdict['new_module']
tmp_name = hdict['new_name']
hdict.pop('new_module', None)
hdict.pop('new_name', None)
pyfile.initPlugin()
hdict['new_module'] = tmp_module
hdict['new_name'] = tmp_name
raise Retry(_("Revert to original hoster plugin"))
else:
raise Fail(e)
def handle_premium(self, pyfile):
return self.handle_free(pyfile)
def handle_free(self, pyfile):
if self.premium:
raise NotImplementedError
else:
self.fail(_("Required premium account not found"))