Repository navigation
Expand file tree
/
Copy pathTXT.py
More file actions
69 lines (49 loc) · 1.85 KB
/
Copy pathTXT.py
File metadata and controls
69 lines (49 loc) · 1.85 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
# -*- coding: utf-8 -*-
import codecs
from pyload.plugin.Container import Container
from pyload.utils import fs_encode
class TXT(Container):
__name = "TXT"
__type = "container"
__version = "0.15"
__pattern = r'.+\.(txt|text)$'
__config = [("flush" , "bool" , "Flush list after adding", False ),
("encoding", "string", "File encoding" , "utf-8")]
__description = """Read link lists in plain text formats"""
__license = "GPLv3"
__authors = [("spoob", "spoob@pyload.org"),
("jeix", "jeix@hasnomail.com")]
def decrypt(self, pyfile):
try:
encoding = codecs.lookup(self.getConfig('encoding')).name
except Exception:
encoding = "utf-8"
fs_filename = fs_encode(pyfile.url.strip())
txt = codecs.open(fs_filename, 'r', encoding)
curPack = "Parsed links from %s" % pyfile.name
packages = {curPack:[],}
for link in txt.readlines():
link = link.strip()
if not link:
continue
if link.startswith(";"):
continue
if link.startswith("[") and link.endswith("]"):
# new package
curPack = link[1:-1]
packages[curPack] = []
continue
packages[curPack].append(link)
txt.close()
# empty packages fix
for key, value in packages.iteritems():
if not value:
packages.pop(key, None)
if self.getConfig('flush'):
try:
txt = open(fs_filename, 'wb')
txt.close()
except IOError:
self.logWarning(_("Failed to flush list"))
for name, links in packages.iteritems():
self.packages.append((name, links, name))