forked from pyload/pyload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.py
More file actions
76 lines (57 loc) · 2.07 KB
/
container.py
File metadata and controls
76 lines (57 loc) · 2.07 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
import os
import urllib.parse
from ..helpers import exists
from .decrypter import BaseDecrypter
class BaseContainer(BaseDecrypter):
__name__ = "Container"
__type__ = "base"
__version__ = "0.15"
__status__ = "stable"
__pattern__ = r"^unmatchable$"
__config__ = [
("enabled", "bool", "Activated", True),
("use_premium", "bool", "Use premium account if available", True),
(
"folder_per_package",
"Default;Yes;No",
"Create folder for each package",
"Default",
),
]
__description__ = """Base container decrypter plugin"""
__license__ = "GPLv3"
__authors__ = [("mkaay", "mkaay@mkaay.de"), ("Walter Purcaro", "vuolter@gmail.com")]
def process(self, pyfile):
"""
Main method.
"""
self._make_tmpfile()
self.decrypt(pyfile)
if self.links:
self._generate_packages()
elif not self.packages:
self.error(self._("No link grabbed"), "decrypt")
self._delete_tmpfile()
self._create_packages()
def _delete_tmpfile(self):
if os.path.basename(self.pyfile.name).startswith("tmp_"):
self.remove(self.pyfile.url, try_trash=False)
def _make_tmpfile(self):
"""
Loads container to disk if its stored remotely and overwrite url, or check
existent on several places at disk.
"""
remote = bool(urllib.parse.urlparse(self.pyfile.url).netloc)
if remote:
content = self.load(self.pyfile.url)
upload_path = os.path.join(self.pyload.tempdir, "upload")
os.makedirs(upload_path, exist_ok=True)
self.pyfile.name = "tmp_" + self.pyfile.name
self.pyfile.url = os.path.join(upload_path, self.pyfile.name)
try:
with open(self.pyfile.url, mode="wb") as fp:
fp.write(content.encode())
except IOError as exc:
self.fail(exc)
elif not exists(self.pyfile.url):
self.fail(self._("File not found"))