flexget.plugins.input_listdir
Covered: 13 lines
Missed: 21 lines
Skipped 11 lines
Percent: 38 %
 1
import logging
 2
from flexget.plugin import register_plugin
 4
log = logging.getLogger('listdir')
 7
class InputListdir(object):
 8
    """
 9
        Uses local path content as an input.
11
        Example:
13
        listdir: /storage/movies/
14
    """
16
    def validator(self):
17
        from flexget import validator
18
        root = validator.factory()
19
        root.accept('path')
20
        bundle = root.accept('list')
21
        bundle.accept('path')
22
        return root
24
    def on_feed_input(self, feed, config):
25
        from flexget.feed import Entry
26
        import os
28
        if isinstance(config, basestring):
29
            config = [config]
30
        entries = []
31
        for path in config:
32
            for name in os.listdir(unicode(path)):
33
                e = Entry()
34
                e['title'] = name
35
                filepath = os.path.join(path, name)
37
                if not filepath.startswith('/'):
38
                    filepath += '/'
39
                e['url'] = 'file://%s' % filepath
40
                e['location'] = os.path.join(path, name)
41
                entries.append(e)
42
        return entries
44
register_plugin(InputListdir, 'listdir', api_ver=2)