flexget Package

flexget Package

flexget.__init__.main()

Main entry point for Command Line Interface

entry Module

class flexget.entry.Entry(*args, **kwargs)

Bases: dict

Represents one item in feed. Must have url and title fields.

Stores automatically original_url key, which is necessary because plugins (eg. urlrewriters) may change url into something else and otherwise that information would be lost.

Entry will also transparently convert all ascii strings into unicode and raises EntryUnicodeError if conversion fails on any value being set. Such failures are catched by Feed and trigger abort().

get(key, default=None, eval_lazy=True, lazy=None)

Overridden so that our __getitem__ gets used for LazyFields

Parameters:
  • key (string) – Name of the key
  • default (object) – Value to be returned if key does not exists
  • eval_lazy (bool) – Allow evaluating LazyFields or not
  • lazy (bool) – Provided for backwards compatibility
Returns:

Value or given default

is_lazy(field)
Parameters:field (string) – Name of the field to check
Returns:True if field is lazy loading.
Return type:bool
isvalid()
Returns:True if entry is valid. Return False if this cannot be used.
Return type:bool
register_lazy_fields(fields, func)

Register a list of fields to be lazily loaded by callback func.

Parameters:
  • fields – List of field names that are registered as lazy fields
  • func – Callback function which is called when lazy field needs to be evaluated. Function call will get params (entry, field). See LazyField class for more details.
render(template)

Renders a template string based on fields in the entry.

Parameters:template (string) – A template string that uses jinja2 or python string replacement format.
Returns:The result of the rendering.
Return type:string
Raises RenderError:
 If there is a problem.
safe_str()
setdefault(key, value=None)

Overridden so our __setitem__ is not avoided.

take_snapshot(name)

Takes a snapshot of the entry under name. Snapshots can be accessed via snapshots. :param string name: Snapshot name

unregister_lazy_fields(fields, func)
Parameters:
  • fields (list) – List of field names to unregister. If given field is not lazy loading, value is set to None
  • func (function) – Function to be removed from registered.
Returns:

Number of removed functions

Return type:

int

update(*args, **kwargs)

Overridden so our __setitem__ is not avoided.

update_using_map(field_map, source_item)

Populates entry fields from a source object using a dictionary that maps from entry field names to attributes (or keys) in the source object.

Parameters:
  • field_map – A dictionary mapping entry field names to the attribute in source_item (or keys, if source_item is a dict)(nested attributes/dicts are also supported, separated by a dot,) or a function that takes source_item as an argument
  • source_item – Source of information to be used by the map
exception flexget.entry.EntryUnicodeError(key, value)

Bases: exceptions.Exception

This exception is thrown when trying to set non-unicode compatible field value to entry.

class flexget.entry.LazyField(entry, field, func)

Bases: object

LazyField is a type of Entry field which is evaluated only when it’s value is requested. This way FlexGet can avoid doing heavy lookups from the internet or database for details that may not be needed ever.

Stores callback function(s) to which populates Entry fields. Callback is ran when it’s called or to get a string representation.

event Module

Provides small event framework

class flexget.event.Event(name, func, priority=128)

Bases: object

Represents one registered event.

flexget.event.add_event_handler(name, func, priority=128)
Parameters:
  • name (string) – Event name
  • func (function) – Function that acts as event handler
  • priority – Priority for this hook
Returns:

Event created

Return type:

Event

Raises Exception:
 

If func is already registered in an event

flexget.event.event(name, priority=128)

Register event to function with a decorator

flexget.event.fire_event(name, *args, **kwargs)

Trigger an event with name. If event is not hooked by anything nothing happens.

Parameters:
  • name – Name of event to be called
  • args – List of arguments passed to handler function
  • kwargs – Key Value arguments passed to handler function
flexget.event.get_events(name)
Parameters:name (String) – event name
Returns:List of Event for name ordered by priority
flexget.event.remove_event_handler(name, func)

Warning

Not implemented!

feed Module

class flexget.feed.Feed(manager, name, config)

Bases: object

Represents one feed in the configuration.

Fires events:

  • feed.execute.before_plugin

    Before a plugin is about to be executed. Note that since this will also include all builtin plugins the amount of calls can be quite high

    parameters: feed, keyword

  • feed.execute.after_plugin

    After a plugin has been executed.

    parameters: feed, keyword

  • feed.execute.completed

    After feed execution has been completed

    parameters: feed

abort(**kwargs)

Abort this feed execution, no more plugins will be executed after the current one exists.

accept(entry, reason=None, **kwargs)

Accept entry immediately with optional but highly recommendable reason.

Parameters:
  • entry (Entry) – To be aceppeted
  • reason (string) – Optional reason
  • kwargs – Optional kwargs will be passed to plugins hooking action
disable_phase(phase)

Disable phase from execution.

All disabled phases are re-enabled by Feed._reset() after feed execution has been completed.

Parameters:phase (string) – Name of phase
Raises ValueError:
 phase could not be found.
execute(*args, **kw)

Executes the feed.

Parameters:
  • disable_phases (list) – Disable given phases names during execution
  • entries (list) – Entries to be used in execution instead of using the input. Disables input phase.
fail(entry, reason=None, **kwargs)

Fails entry immediately with optional but highly recommendable reason.

Parameters:
  • entry (Entry) – To be failed
  • reason (string) – Optional reason
  • kwargs – Optional kwargs will be passed to plugins hooking action
find_entry(category='entries', **values)

Find and return Entry with given attributes from feed or None

Parameters:
  • category (string) – entries, accepted, rejected or failed. Defaults to entries.
  • values – Key values of entries to be searched
Returns:

Entry or None

max_reruns = 5
plugins(phase=None)

Get currently enabled plugins.

Parameters:phase (string) – Optional, limits to plugins currently configured on given phase, sorted in phase order.
Returns:An iterator over configured flexget.plugin.PluginInfo instances enabled on this feed.
purge()

Purges rejected and failed entries. Failed entries will be removed from entries, accepted and rejected Rejected entries will be removed from entries and accepted

reject(entry, reason=None, **kwargs)

Reject entry immediately and permanently with optional but highly recommendable reason.

Parameters:
  • entry (Entry) – To be rejected
  • reason (string) – Optional reason
  • kwargs – Optional kwargs will be passed to plugins hooking action
rerun()

Immediately re-run the feed after execute has completed, feed can be re-run up to max_reruns times.

trace(entry, message)

Add tracing message to entry.

Note

Not yet supported in any meaningful way

undecided

Iterate over undecided entries

validate()

Called during feed execution. Validates config, prints errors and aborts feed if invalid.

static validate_config(config)

Plugin configuration validation. Return list of error messages that were detected.

flexget.feed.root_config_validator()

Returns a validator for the ‘feeds’ key of config.

flexget.feed.useFeedLogging(func)

logger Module

class flexget.logger.FlexGetFormatter

Bases: logging.Formatter

Custom formatter that can handle both regular log records and those created by FlexGetLogger

flexget_fmt = '%(asctime)-15s %(levelname)-8s %(name)-13s %(feed)-15s %(message)s'
format(record)
plain_fmt = '%(asctime)-15s %(levelname)-8s %(name)-29s %(message)s'
class flexget.logger.FlexGetLogger(name, level=0)

Bases: logging.Logger

Custom logger that adds feed and execution info to log records.

debugall(msg, *args, **kwargs)

Log at TRACE level (more detailed than DEBUG).

local = <thread._local object at 0x3959ef0>
makeRecord(name, level, fn, lno, msg, args, exc_info, func=None, extra=None)
trace(msg, *args, **kwargs)

Log at TRACE level (more detailed than DEBUG).

verbose(msg, *args, **kwargs)

Log at VERBOSE level (displayed when FlexGet is run interactively.)

class flexget.logger.PrivacyFilter

Bases: logging.Filter

Edits log messages and <hides> obviously private information.

filter(record)
flexget.logger.flush_logging_to_console()

Flushes memory logger to console

flexget.logger.initialize(unit_test=False)

Prepare logging.

flexget.logger.set_execution(execution)
flexget.logger.set_feed(feed)
flexget.logger.start(filename=None, level=20, debug=False)

After initialization, start file logging.

manager Module

class flexget.manager.Manager(options)

Bases: object

Manager class for FlexGet

Fires events:

  • manager.startup

    After manager has been initialized. This is when application becomes ready to use

  • manager.upgrade

    Upgrade plugin database schemas etc

  • manager.execute.started

    When execute is about the be started, this happens before any feed phases occur including on_process_start

  • manager.execute.completed

    After manager has executed all Feeds

  • manager.shutdown

    When the manager is exiting

acquire_lock()
check_lock()

Checks if there is already a lock, returns True if there is.

create_feeds()

Creates instances of all configured feeds

db_cleanup()

Perform database cleanup if cleanup interval has been met.

disable_feeds()

Disables all feeds.

enable_feeds()

Enables all feeds.

execute(*args, **kw)
find_config()

Find the configuration file and then call load_config() to load it

init_sqlalchemy()

Initialize SQLAlchemy

initialize()

Separated from __init__ so that unit tests can modify options before loading config.

load_config(config)

Warning

Calls sys.exit(1) if configuration file could not be loaded. This is something we probably want to change.

Parameters:config (string) – Path to configuration file
options = None
pre_check_config(fn)

Checks configuration file for common mistakes that are easily detectable

process_end(feeds=None)

Execute process_end for all feeds.

Parameters:feeds (list) – Optional list of Feed instances, defaults to all.
process_start(feeds=None)

Execute process_start for feeds.

Parameters:feeds (list) – Optional list of Feed instances, defaults to all.
release_lock()
save_config()

Dumps current config to yaml config file

setup_yaml()

Set up the yaml loader to return unicode objects for strings by default

shutdown()

Application is being exited

unit_test = False
validate_config()

Check all root level keywords are valid.

flexget.manager.register_config_key(key, validator, required=False)

Registers a valid root level key for the config.

Parameters:
  • key (string) – Name of the root level key being registered.
  • validator – Validator for the key. Accepts: flexget.validator.Validator instance, function returning Validator instance, or validator type string.
  • required (bool) – Specify whether this is a mandatory key.
flexget.manager.useExecLogging(func)

options Module

class flexget.options.CoreOptionParser(unit_test=False, **kwargs)

Bases: flexget.options.OptionParser

Contains all the options that should only be used when running without a ui

parse_args(args=None)
class flexget.options.OptionParser(**kwargs)

Bases: optparse.OptionParser

Contains all the options that both the core and webui should have

plugin Module

Plugin Loading & Management.

exception flexget.plugin.PluginWarning(value, logger=<flexget.logger.FlexGetLogger object at 0x3a9c190>, **kwargs)

Bases: exceptions.Warning

exception flexget.plugin.PluginError(value, logger=<flexget.logger.FlexGetLogger object at 0x3a9c190>, **kwargs)

Bases: exceptions.Exception

flexget.plugin.register_plugin

alias of PluginInfo

flexget.plugin.register_parser_option(*args, **kwargs)

Adds a parser option to the global parser.

flexget.plugin.register_feed_phase(name, before=None, after=None)

Adds a new feed phase to the available phases.

flexget.plugin.get_plugin_by_name(name, issued_by='???')

Get plugin by name, preferred way since this structure may be changed at some point.

flexget.plugin.get_plugins_by_group(group)

Return an iterator over all plugins with in specified group.

flexget.plugin.get_plugin_keywords()

Return iterator over all plugin keywords.

flexget.plugin.get_plugins_by_phase(phase)

Return an iterator over all plugins that hook :phase:

flexget.plugin.get_phases_by_plugin(name)

Return all phases plugin :name: hooks

class flexget.plugin.internet(logger=None)

Bases: object

@internet decorator for plugin phase methods.

Catches all internet related exceptions and raises PluginError with relevant message. Feed handles PluginErrors by aborting the feed.

flexget.plugin.priority(value)

Priority decorator for phase methods

schema Module

class flexget.schema.Meta

Bases: type

Metaclass for objects returned by versioned_base factory

class flexget.schema.PluginSchema(plugin, version=0)

Bases: sqlalchemy.ext.declarative.Base

id
plugin
version
flexget.schema.after_table_create(event, target, bind, tables=None, **kw)

Sets the schema version to most recent for a plugin when it’s tables are freshly created.

flexget.schema.get_version(plugin)
flexget.schema.register_plugin_table(tablename, plugin, version)
flexget.schema.set_version(plugin, version)
flexget.schema.upgrade(plugin)

Used as a decorator to register a schema upgrade function.

The wrapped function will be passed the current schema version and a session object. The function should return the new version of the schema after the upgrade.

There is no need to commit the session, it will commit automatically if an upgraded schema version is returned.

Example:

from flexget import schema
@schema.upgrade('your_plugin')
def upgrade(ver, session):
     if ver == 2:
         # upgrade
         ver = 3
     return ver
flexget.schema.versioned_base(plugin, version)

Returns a class which can be used like Base, but automatically stores schema version when tables are created.

validator Module

class flexget.validator.AnyValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(value, **kwargs)
name = 'any'
schema()
validate(data)
validateable(data)
class flexget.validator.BooleanValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(name, **kwargs)
name = 'boolean'
schema()
validate(data)
validateable(data)
class flexget.validator.ChoiceValidator(parent=None, **kwargs)

Bases: flexget.validator.Validator

accept(value, ignore_case=False)
Parameters:
  • value – accepted text, int or boolean
  • ignore_case (bool) – Whether case matters for text values
accept_choices(values, **kwargs)

Same as accept but with multiple values (list)

name = 'choice'
schema()
validate(data)
validateable(data)
class flexget.validator.DecimalValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(name, **kwargs)
name = 'decimal'
schema()
validate(data)
validateable(data)
class flexget.validator.DictValidator(parent=None, **kwargs)

Bases: flexget.validator.Validator

accept(value, key=None, required=False, **kwargs)
Parameters:
  • value – validator name, instance or function that returns an instance, which validates the given key
  • key (string) – The dictionary key to accept
  • required (bool) – = Mark this key as required
Raises ValueError:
 

key was not specified

accept_any_key(value, **kwargs)

Accepts any leftover keys in dictionary, which will be validated with value

accept_valid_keys(value, key_type=None, key_validator=None, **kwargs)

Accepts keys that pass a given validator, and validates them using validator specified in value

Parameters:
  • value – Validator name, instance or function returning an instance that will be used to validate dict values.
  • key_type – Name of validator or list of names that determine which keys in this dict value will govern
  • key_validator (Validator) – A validator instance that will be used to determine which keys in the dict value will govern
Raises ValueError:
 

If both key_type and key_validator are specified.

name = 'dict'
reject_key(key, message=None)

Rejects a key

reject_keys(keys, message=None)

Reject list of keys

require_key(key)

Flag key as mandatory

schema()
validate(data)
validateable(data)
class flexget.validator.EqualsValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(value, **kwargs)
name = 'equals'
schema()
validate(data)
validateable(data)
class flexget.validator.Errors

Bases: object

Create and hold validator error messages.

add(msg)

Add new error message to current path.

back_out_errors(num=1)

Remove last num errors from list

count()

Return number of errors.

path_add_level(value='?')

Adds level into error message path

path_remove_level()

Removes level from path by depth number

path_update_value(value)

Updates path level value

class flexget.validator.FileValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.TextValidator

name = 'file'
schema()
validate(data)
class flexget.validator.IntegerValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(name, **kwargs)
name = 'integer'
schema()
validate(data)
validateable(data)
class flexget.validator.IntervalValidator(parent=None, **kwargs)

Bases: flexget.validator.RegexpMatchValidator

name = 'interval'
class flexget.validator.LazyValidator(func, parent=None)

Bases: object

Acts as a wrapper for a Validator instance, but does not generate the instance until one of its attributes needs to be accessed. Used to create validators that may otherwise cause endless loops.

schema()

Return the schema of our instance if it has already been created, otherwise return ‘ondemand’ type.

class flexget.validator.ListValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(value, **kwargs)
name = 'list'
schema()
validate(data)
validateable(data)
class flexget.validator.NumberValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(name, **kwargs)
name = 'number'
schema()
validate(data)
validateable(data)
class flexget.validator.PathValidator(parent=None, allow_replacement=False, **kwargs)

Bases: flexget.validator.TextValidator

name = 'path'
schema()
validate(data)
class flexget.validator.RegexpMatchValidator(parent=None, **kwargs)

Bases: flexget.validator.Validator

accept(regexp, **kwargs)
add_regexp(regexp_list, regexp)
name = 'regexp_match'
reject(regexp)
schema()
validate(data)
validateable(data)
class flexget.validator.RegexpValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(name, **kwargs)
name = 'regexp'
schema()
validate(data)
validateable(data)
class flexget.validator.RootValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(value, **kwargs)
name = 'root'
schema()
validate(data)
validateable(data)
class flexget.validator.TextValidator(parent=None, message=None, **kwargs)

Bases: flexget.validator.Validator

accept(name, **kwargs)
name = 'text'
schema()
validate(data)
validateable(data)
class flexget.validator.UrlValidator(parent=None, protocols=None, **kwargs)

Bases: flexget.validator.TextValidator

name = 'url'
schema()
validate(data)
class flexget.validator.Validator(parent=None, message=None, **kwargs)

Bases: object

accept(value, **kwargs)
add_parent(parent)
add_root_parent()
errors

Recursively return the Errors class from the root of the validator tree.

get_validator(value, **kwargs)

Returns a child validator of this one.

Parameters:
  • value – Can be a validator type string, an already created Validator instance, or a function that returns a validator instance.
  • kwargs – Keyword arguments are passed on to validator init if a new validator is created.
name = 'validator'
schema()

Return schema for validator

validate(data)

Validate given data and log errors, return True if passed and False if not.

validate_item(item, rules)

Helper method. Validate item against list of rules (validators). Return True if item passed any of the rules, False if none of the rules pass item.

validateable(data)

Return True if validator can be used to validate given data, False otherwise.

flexget.validator.build_options_validator(options)
flexget.validator.complex_test()
flexget.validator.factory(name='root', **kwargs)

Factory method, returns validator instance.