3
from flexget.feed import Entry
4
from flexget.plugin import *
5
from flexget.utils.tools import str_to_boolean
7
log = logging.getLogger('inject')
10
class InputInject(object):
12
Allows injecting imaginary entry for FlexGet to process.
16
--inject <TITLE> [URL] [ACCEPTED] [IMMORTAL]
18
Random url will be generated. All other inputs from freed(s) are disabled.
23
flexget --inject "Some.Series.S02E12.Imaginary" --feed my-series --learn
25
This would inject imaginary series into a single feed and learn it as a downloaded,
26
assuming feed accepts the injected entry.
31
from flexget import validator
32
return validator.factory('any')
37
def optik_series(option, opt, value, parser):
38
"""--inject <TITLE> [URL] [ACCEPTED] [IMMORTAL]"""
41
for arg in parser.rargs[:]:
42
if arg.startswith('-'):
46
InputInject.options['entry'] = {'title': arg}
48
InputInject.options['entry']['url'] = arg
50
field, val = arg.split('=')
51
InputInject.options['entry'][field] = yaml.load(val)
53
if arg.lower() == 'accept':
54
InputInject.options['accept'] = True
56
InputInject.options['accept'] = str_to_boolean(arg)
58
if arg.lower() == 'force':
59
InputInject.options['entry']['immortal'] = True
61
InputInject.options['entry']['immortal'] = str_to_boolean(arg)
63
log.critical('Unknown --inject parameter %s' % arg)
66
def on_feed_input(self, feed):
67
if not InputInject.options:
70
# disable other inputs
71
log.info('Disabling the rest of the input phase.')
72
feed.disable_phase('input')
74
# create our injected entry
78
entry = Entry(InputInject.options['entry'], injected=True)
79
if not 'url' in entry:
80
entry['url'] = 'http://localhost/inject/%s' % ''.join([random.choice(string.letters + string.digits) for x in range(1, 30)])
81
if entry.get('immortal'):
82
log.debug('Injected entry is immortal')
84
feed.entries.append(entry)
86
if InputInject.options.get('accept', False):
87
log.debug('accepting the injection')
88
feed.accept(entry, '--inject accepted')
91
register_plugin(InputInject, '--inject', debug=True, builtin=True)
93
register_parser_option('--inject', action='callback', callback=InputInject.optik_series,
94
help='Injects entry to all executed feeds: <TITLE> [URL] [ACCEPT] [FORCE]')