From c61412841c8ea6c456f7d3472166d81132b56e95 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 19 Feb 2015 16:02:32 +0100 Subject: [LinkList] Rename to TXT --- module/plugins/container/TXT.py | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 module/plugins/container/TXT.py (limited to 'module/plugins/container/TXT.py') diff --git a/module/plugins/container/TXT.py b/module/plugins/container/TXT.py new file mode 100644 index 000000000..585da8ac6 --- /dev/null +++ b/module/plugins/container/TXT.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +import codecs + +from module.plugins.Container import Container +from module.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" + + file = fs_encode(pyfile.url.strip()) + txt = codecs.open(file, '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(file, 'wb') + txt.close() + + except IOError: + self.logWarning(_("Failed to flush list")) + + for name, links in packages.iteritems(): + self.packages.append((name, links, name)) -- cgit v1.2.3 From c039d5822c4c53661813b6fd8e2252a3b633532e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 27 Feb 2015 04:39:45 +0100 Subject: [container] Code cosmetics --- module/plugins/container/TXT.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'module/plugins/container/TXT.py') diff --git a/module/plugins/container/TXT.py b/module/plugins/container/TXT.py index 585da8ac6..98ca426d7 100644 --- a/module/plugins/container/TXT.py +++ b/module/plugins/container/TXT.py @@ -28,10 +28,10 @@ class TXT(Container): except Exception: encoding = "utf-8" - file = fs_encode(pyfile.url.strip()) - txt = codecs.open(file, 'r', encoding) - curPack = "Parsed links from %s" % pyfile.name - packages = {curPack:[],} + 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() @@ -59,7 +59,7 @@ class TXT(Container): if self.getConfig("flush"): try: - txt = open(file, 'wb') + txt = open(fs_filename, 'wb') txt.close() except IOError: -- cgit v1.2.3 From 7beb65e991bc6d1913c3b5bb2ef69e659d5b8342 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 10 Mar 2015 01:55:52 +0100 Subject: Spare code cosmetics --- module/plugins/container/TXT.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/container/TXT.py') diff --git a/module/plugins/container/TXT.py b/module/plugins/container/TXT.py index 98ca426d7..d419ee060 100644 --- a/module/plugins/container/TXT.py +++ b/module/plugins/container/TXT.py @@ -23,7 +23,7 @@ class TXT(Container): def decrypt(self, pyfile): try: - encoding = codecs.lookup(self.getConfig("encoding")).name + encoding = codecs.lookup(self.getConfig('encoding')).name except Exception: encoding = "utf-8" @@ -57,7 +57,7 @@ class TXT(Container): if not value: packages.pop(key, None) - if self.getConfig("flush"): + if self.getConfig('flush'): try: txt = open(fs_filename, 'wb') txt.close() -- cgit v1.2.3