diff options
author | GammaC0de <GammaC0de@users.noreply.github.com> | 2015-05-29 23:33:10 +0200 |
---|---|---|
committer | GammaC0de <GammaC0de@users.noreply.github.com> | 2015-05-29 23:33:10 +0200 |
commit | 844dfd92f590e531ca2f7fd86305fcbc13a03721 (patch) | |
tree | 5303bd07749b362dab071ada6197fe37dda85b27 /module/plugins/container/TXT.py | |
parent | [BitshareCom] Code cosmetics (diff) | |
parent | [SimpleHoster] Fix DB error (diff) | |
download | pyload-844dfd92f590e531ca2f7fd86305fcbc13a03721.tar.xz |
Merge pull request #1 from pyload/stable
sync stable
Diffstat (limited to 'module/plugins/container/TXT.py')
-rw-r--r-- | module/plugins/container/TXT.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/module/plugins/container/TXT.py b/module/plugins/container/TXT.py new file mode 100644 index 000000000..d419ee060 --- /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" + + 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)) |