Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_urlrewriter(self, name):
info = get_plugin_by_name(name)
return info.instance
def __init__(self):
try:
self.backlog = plugin.get_plugin_by_name('backlog')
except plugin.DependencyError:
log.warning('Unable utilize backlog plugin, failed entries may not be retried properly.')
def on_task_prepare(self, task, config):
series = {}
for input_name, input_config in config.get('from', {}).items():
input_plugin = plugin.get_plugin_by_name(input_name)
method = input_plugin.phase_handlers['input']
try:
result = method(task, input_config)
except PluginError as e:
log.warning('Error during input plugin %s: %s' % (input_name, e))
continue
if not result:
log.warning('Input %s did not return anything' % input_name)
continue
for entry in result:
s = series.setdefault(entry['title'], {})
if entry.get('tvdb_id'):
s['set'] = {'tvdb_id': entry['tvdb_id']}
# Allow configure_series to set anything available to series
def aggregate_inputs(task, inputs):
from flexget import plugin
entries = []
entry_titles = set()
entry_urls = set()
entry_locations = set()
for item in inputs:
for input_name, input_config in item.items():
input = plugin.get_plugin_by_name(input_name)
if input.api_ver == 1:
raise plugin.PluginError('Plugin %s does not support API v2' % input_name)
method = input.phase_handlers['input']
try:
result = method(task, input_config)
except plugin.PluginError as e:
log.warning('Error during input plugin %s: %s', input_name, e)
continue
if not result:
log.warning('Input %s did not return anything', input_name)
continue
for entry in result:
urls = ([entry['url']] if entry.get('url') else []) + entry.get('urls', [])
def on_task_filter(self, task, config):
if not config:
return
for entry in task.entries:
try:
plugin.get_plugin_by_name('imdb_lookup').instance.lookup(entry)
except plugin.PluginError:
entry.reject('imdb required')
if 'imdb_id' not in entry and 'imdb_url' not in entry:
entry.reject('imdb required')
def on_task_input(self, task, config):
for input_name, input_config in config['from'].items():
input = plugin.get_plugin_by_name(input_name)
method = input.phase_handlers['input']
try:
result = method(task, input_config)
except plugin.PluginError as e:
log.warning('Error during input plugin %s: %s' % (input_name, e))
continue
# A 0 or -1 limit means don't limit.
if config['amount'] < 1:
return result
return itertools.islice(result, config['amount'])
if isinstance(action, str):
if not phase == 'filter':
continue
# Simple entry action (accept, reject or fail) was specified as a string
for entry in passed_entries:
entry_actions[action](entry, 'Matched requirement: %s' % requirement)
else:
# Other plugins were specified to run on this entry
fake_task = Task(task.manager, task.name, config=action, options=task.options)
fake_task.session = task.session
# This entry still belongs to our feed, accept/reject etc. will carry through.
fake_task.all_entries[:] = passed_entries
methods = {}
for plugin_name, plugin_config in action.items():
p = plugin.get_plugin_by_name(plugin_name)
method = p.phase_handlers.get(phase)
if method:
methods[method] = (fake_task, plugin_config)
# Run the methods in priority order
for method in sorted(methods, reverse=True):
method(*methods[method])
def on_task_learn(self, task, config):
config = self.prepare_config(config)
if not config.get('remove_on_accept'):
return
for item in config.get('lists'):
for plugin_name, plugin_config in item.items():
thelist = plugin.get_plugin_by_name(plugin_name).instance.get_list(plugin_config)
if task.manager.options.test and thelist.online:
log.info('`%s` is marked as online, would remove accepted items outside of --test mode.',
plugin_name)
continue
for entry in task.accepted:
log.verbose('Removing %s from list %s', entry.get('title', 'entry'), plugin_name)
thelist -= task.accepted
if isinstance(action, basestring):
if not phase == 'filter':
continue
# Simple entry action (accept, reject or fail) was specified as a string
for entry in passed_entries:
entry_actions[action](entry, 'Matched requirement: %s' % requirement)
else:
# Other plugins were specified to run on this entry
fake_task = Task(task.manager, task.name, config=action, options=task.options)
fake_task.session = task.session
# This entry still belongs to our feed, accept/reject etc. will carry through.
fake_task.all_entries[:] = passed_entries
methods = {}
for plugin_name, plugin_config in action.iteritems():
p = plugin.get_plugin_by_name(plugin_name)
method = p.phase_handlers.get(phase)
if method:
methods[method] = (fake_task, plugin_config)
# Run the methods in priority order
for method in sorted(methods, reverse=True):
method(*methods[method])
elif what.startswith('tmdb_id='):
result['tmdb_id'] = what[8:]
else:
result['title'] = what
if not lookup:
# If not doing an online lookup we can return here
return result
search_entry = Entry(title=result['title'] or '')
for field in ['imdb_id', 'tmdb_id']:
if result.get(field):
search_entry[field] = result[field]
# Put lazy lookup fields on the search entry
plugin.get_plugin_by_name('imdb_lookup').instance.register_lazy_fields(search_entry)
plugin.get_plugin_by_name('tmdb_lookup').instance.lookup(search_entry)
try:
# Both ids are optional, but if movie_name was populated at least one of them will be there
return {'title': search_entry['movie_name'], 'imdb_id': search_entry.get('imdb_id'),
'tmdb_id': search_entry.get('tmdb_id')}
except KeyError as e:
raise QueueError(e.message)