import logging
from flexget.plugin import *

log = logging.getLogger('listdir')


class InputListdir:
    """
        Uses local path content as an input.
        
        Example:
        
        listdir: /storage/movies/
    """
    
    def validator(self):
        from flexget import validator
        root = validator.factory()
        root.accept('path')
        bundle = root.accept('list')
        bundle.accept('path')
        return root
        
    def get_config(self, feed):
        config = feed.config.get('listdir', None)
        #if only a single path is passed turn it into a 1 element list
        if isinstance(config, basestring):
            config = [config]
        return config

    def on_feed_input(self, feed):
        from flexget.feed import Entry
        import os
        config = self.get_config(feed)
        for path in config: 
            for name in os.listdir(unicode(path)):
                e = Entry()
                e['title'] = name
                e['url'] = 'file://%s' % (os.path.join(path, name))
                e['location'] = os.path.join(path, name)
                feed.entries.append(e)

register_plugin(InputListdir, 'listdir')

@@ -39,9 +39,23 @@
 ort 
-*
+register_plugin
 %0A%0Alo
@@ -162,25 +162,17 @@
  input.%0A
-        
 %0A
+
         
@@ -180,25 +180,17 @@
 xample:%0A
-        
 %0A
+
         
@@ -223,21 +223,17 @@
     %22%22%22%0A
-    
 %0A
+
     def 
@@ -441,17 +441,9 @@
 oot%0A
-        
 %0A
+
     
@@ -529,17 +529,18 @@
        #
-i
+ I
 f only a
@@ -846,17 +846,16 @@
  config:
- 
 %0A       
@@ -960,16 +960,229 @@
  = name%0A
+                filepath = os.path.join(path, name)%0A                # Windows paths need an extra / prepended to them%0A                if not filepath.startswith('/'):%0A                    filepath = '/' + filepath%0A
         
@@ -1219,32 +1219,16 @@
  %25 (
-os.path.join(path, name)
+filepath
 )%0A  

Fix url of entries made by listdir on Windows.