summaryrefslogtreecommitdiffstats
path: root/module/plugins/container/LinkList.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2015-01-29 15:56:57 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2015-01-29 15:56:57 +0100
commitcb9e67a5437ddfafd6a93f5a208b9faf3f2d5575 (patch)
tree2175310fe13226ac859dac57d5e3a1d14d9223bf /module/plugins/container/LinkList.py
parent[ExtractArchive] Fix typo (thx SelmaUrban) (diff)
downloadpyload-cb9e67a5437ddfafd6a93f5a208b9faf3f2d5575.tar.xz
Some file encoding fixup + optimizations
Diffstat (limited to 'module/plugins/container/LinkList.py')
-rw-r--r--module/plugins/container/LinkList.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/module/plugins/container/LinkList.py b/module/plugins/container/LinkList.py
index 9c76c4341..cff1b9915 100644
--- a/module/plugins/container/LinkList.py
+++ b/module/plugins/container/LinkList.py
@@ -8,11 +8,12 @@ from module.utils import fs_encode
class LinkList(Container):
__name__ = "LinkList"
- __version__ = "0.13"
+ __type__ = "container"
+ __version__ = "0.14"
__pattern__ = r'.+\.txt$'
- __config__ = [("clear", "bool", "Clear Linklist after adding", False),
- ("encoding", "string", "File encoding (default utf-8)", "")]
+ __config__ = [("clear" , "bool" , "Clear Linklist after adding" , False),
+ ("encoding", "string", "File encoding (default utf-8)", "" )]
__description__ = """Read link lists in txt format"""
__license__ = "GPLv3"
@@ -22,38 +23,42 @@ class LinkList(Container):
def decrypt(self, pyfile):
try:
- file_enc = codecs.lookup(self.getConfig("encoding")).name
- except Exception:
- file_enc = "utf-8"
+ encoding = codecs.lookup(self.getConfig("encoding")).name
- file_name = fs_encode(pyfile.url)
+ except Exception:
+ encoding = "utf-8"
- txt = codecs.open(file_name, 'r', file_enc)
- links = txt.readlines()
+ file = fs_encode(pyfile.url.strip())
+ txt = codecs.open(file, 'r', encoding)
+ links = txt.readlines()
curPack = "Parsed links from %s" % pyfile.name
packages = {curPack:[],}
for link in links:
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
delete = []
- for key,value in packages.iteritems():
+ for key, value in packages.iteritems():
if not value:
delete.append(key)
@@ -62,8 +67,9 @@ class LinkList(Container):
if self.getConfig("clear"):
try:
- txt = open(file_name, 'wb')
+ txt = open(file, 'wb')
txt.close()
+
except Exception:
self.logWarning(_("LinkList could not be cleared"))