3
from flexget.entry 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.
33
def optik_series(option, opt, value, parser):
34
"""--inject <TITLE> [URL] [ACCEPTED] [IMMORTAL]"""
37
for arg in parser.rargs[:]:
38
if arg.startswith('-'):
42
InputInject.options['entry'] = {'title': arg}
44
InputInject.options['entry']['url'] = arg
46
field, val = arg.split('=')
47
InputInject.options['entry'][field] = yaml.load(val)
49
if arg.lower() == 'accept':
50
InputInject.options['accept'] = True
52
InputInject.options['accept'] = str_to_boolean(arg)
54
if arg.lower() == 'force':
55
InputInject.options['entry']['immortal'] = True
57
InputInject.options['entry']['immortal'] = str_to_boolean(arg)
59
log.critical('Unknown --inject parameter %s' % arg)
62
def on_feed_input(self, feed):
63
if not InputInject.options:
66
# disable other inputs
67
log.info('Disabling the rest of the input phase.')
68
feed.disable_phase('input')
70
# create our injected entry
74
entry = Entry(InputInject.options['entry'], injected=True)
75
if not 'url' in entry:
76
entry['url'] = 'http://localhost/inject/%s' % ''.join([random.choice(string.letters + string.digits) for x in range(1, 30)])
77
if entry.get('immortal'):
78
log.debug('Injected entry is immortal')
80
feed.entries.append(entry)
82
if InputInject.options.get('accept', False):
83
log.debug('accepting the injection')
84
feed.accept(entry, '--inject accepted')
87
register_plugin(InputInject, '--inject', debug=True, builtin=True)
89
register_parser_option('--inject', action='callback', callback=InputInject.optik_series,
90
help='Injects entry to all executed feeds: <TITLE> [URL] [ACCEPT] [FORCE]')