flexget.plugins.input.listdir
Covered: 20 lines
Missed: 16 lines
Skipped 10 lines
Percent: 55 %
 1
"""Plugin for filesystem feeds."""
 2
import os
 3
import logging
 4
from flexget import plugin
 5
from flexget.entry import Entry
 7
log = logging.getLogger('listdir')
10
class Listdir(plugin.Plugin):
11
    """
12
        Uses local path content as an input.
14
        Example:
16
        listdir: /storage/movies/
17
    """
19
    def validator(self):
20
        from flexget import validator
21
        root = validator.factory()
22
        root.accept('path')
23
        bundle = root.accept('list')
24
        bundle.accept('path')
25
        return root
27
    def on_feed_input(self, feed, config):
29
        if isinstance(config, basestring):
30
            config = [config]
31
        entries = []
32
        for path in config:
33
            path = os.path.expanduser(path)
34
            for name in os.listdir(unicode(path)):
35
                e = Entry()
36
                e['title'] = name
37
                filepath = os.path.join(path, name)
39
                if not filepath.startswith('/'):
40
                    filepath = '/' + filepath
41
                e['url'] = 'file://%s' % filepath
42
                e['location'] = os.path.join(path, name)
43
                e['filename'] = name
44
                entries.append(e)
45
        return entries