forked from pyload/pyload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiHoster.py
More file actions
75 lines (54 loc) · 2.22 KB
/
MultiHoster.py
File metadata and controls
75 lines (54 loc) · 2.22 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
# -*- coding: utf-8 -*-
from time import time
from pyload.utils import remove_chars
from Account import Account
def normalize(domain):
""" Normalize domain/plugin name, so they are comparable """
return remove_chars(domain.strip().lower(), "-.")
#noinspection PyUnresolvedReferences
class MultiHoster(Account):
"""
Base class for MultiHoster services.
This is also an Account instance so you should see :class:`Account` and overwrite necessary methods.
Multihoster becomes only active when an Account was entered and the MultiHoster addon was activated.
You need to overwrite `loadHosterList` and a corresponding :class:`Hoster` plugin with the same name should
be available to make your service working.
"""
#: List of hoster names that will be replaced so pyLoad will recognize them: (orig_name, pyload_name)
replacements = [("freakshare.net", "freakshare.com"), ("uploaded.net", "uploaded.to")]
#: Load new hoster list every x seconds
hoster_timeout = 300
def __init__(self, *args, **kwargs):
# Hoster list
self.hoster = []
# Timestamp
self.ts = 0
Account.__init__(self, *args, **kwargs)
def loadHosterList(self, req):
"""Load list of supported hoster
:return: List of domain names
"""
raise NotImplementedError
def isHosterUsuable(self, domain):
""" Determine before downloading if hoster should be used.
:param domain: domain name
:return: True to let the MultiHoster download, False to fallback to default plugin
"""
return True
def getHosterList(self, force=False):
if self.ts + self.hoster_timeout < time() or force:
req = self.getAccountRequest()
try:
self.hoster = self.loadHosterList(req)
except Exception, e:
self.logError(e)
return []
finally:
req.close()
for rep in self.replacements:
if rep[0] in self.hoster:
self.hoster.remove(rep[0])
if rep[1] not in self.hoster:
self.hoster.append(rep[1])
self.ts = time()
return self.hoster