diff options
Diffstat (limited to 'module/plugins/container/LinkList.py')
-rw-r--r-- | module/plugins/container/LinkList.py | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/module/plugins/container/LinkList.py b/module/plugins/container/LinkList.py index 305da8a38..ccb9b2fa3 100644 --- a/module/plugins/container/LinkList.py +++ b/module/plugins/container/LinkList.py @@ -2,17 +2,18 @@ import codecs -from pyload.plugin.Container import Container -from pyload.utils import fs_encode +from module.plugins.Container import Container +from module.utils import fs_encode class LinkList(Container): __name__ = "LinkList" - __version__ = "0.12" + __type__ = "container" + __version__ = "0.14" - __pattern__ = r'.+\.txt' - __config__ = [("clear", "bool", "Clear Linklist after adding", False), - ("encoding", "string", "File encoding (default utf-8)", "")] + __pattern__ = r'.+\.txt$' + __config__ = [("flush" , "bool" , "Flush list after adding", False ), + ("encoding", "string", "File encoding" , "utf-8")] __description__ = """Read link lists in txt format""" __license__ = "GPLv3" @@ -22,50 +23,47 @@ class LinkList(Container): def decrypt(self, pyfile): try: - file_enc = codecs.lookup(self.getConfig("encoding")).name - except Exception: - file_enc = "utf-8" - - file_name = fs_encode(pyfile.url) + encoding = codecs.lookup(self.getConfig("encoding")).name - txt = codecs.open(file_name, 'r', file_enc) - links = txt.readlines() - curPack = "Parsed links from %s" % pyfile.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 links: + 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 - - delete = [] - - for key,value in packages.iteritems(): + for key, value in packages.iteritems(): if not value: - delete.append(key) + packages.pop(key, None) - for key in delete: - del packages[key] - - if self.getConfig("clear"): + if self.getConfig("flush"): try: - txt = open(file_name, 'wb') + txt = open(file, 'wb') txt.close() - except Exception: - self.logWarning(_("LinkList could not be cleared")) + + except IOError: + self.logWarning(_("Failed to flush list")) for name, links in packages.iteritems(): self.packages.append((name, links, name)) |