3
from flexget.plugin import register_plugin
5
log = logging.getLogger('path_by_ext')
8
class PluginPathByExt(object):
10
Allows specifying path based on content-type
15
torrent: ~/watch/torrent/
20
from flexget import validator
21
config = validator.factory('dict')
22
config.accept_any_key('any')
25
def on_feed_modify(self, feed):
26
self.ext(feed, self.set_path)
28
def set_path(self, entry, path):
29
log.debug('Setting %s path to %s' % (entry['title'], path))
32
def ext(self, feed, callback):
34
for entry in feed.entries:
35
if 'mime-type' in entry:
36
# check if configuration has mimetype that entry has
37
if entry['mime-type'] in config:
38
callback(entry, config[entry['mime-type']])
39
# check if entry mimetype extension matches in config
40
ext = mimetypes.types_map.get(entry['mime-type'])
41
path = config.get(ext) or config.get(ext[1:])
45
log.debug('Unknown mimetype %s' % entry['mime-type'])
47
# try to find from url
48
for ext, path in config.iteritems():
49
if entry['url'].endswith('.' + ext):
52
register_plugin(PluginPathByExt, 'path_by_ext')