flexget.utils.tools module#

Contains miscellaneous helpers.

exception flexget.utils.tools.MergeException(value)[source]#

Bases: Exception

Parameters:

value (str)

class flexget.utils.tools.BufferQueue(maxsize=0)[source]#

Bases: Queue

Used in place of a file-like object to capture text and access it safely from another thread.

exception Empty#

Bases: Exception

Exception raised by Queue.get(block=0)/get_nowait().

write(line)[source]#
class flexget.utils.tools.ReList(*args, **kwargs)[source]#

Bases: list

A list that stores regexps.

You can add compiled or uncompiled regexps to the list. It will always return the compiled version. It will compile the text regexps on demand when first accessed.

flags = 2#
class flexget.utils.tools.TimedDict(cache_time='5 minutes')[source]#

Bases: MutableMapping

Acts like a normal dict, but keys will only remain in the dictionary for a specified time span.

Parameters:

cache_time (timedelta | str)

classmethod clear_all()[source]#

Clear all instantiated TimedDicts.

Used by tests to make sure artifacts don’t leak between tests.

_prune()[source]#

Prune all expired keys.

_abc_impl = <_abc._abc_data object>#
_instances: dict[int, TimedDict] = <WeakValueDictionary>#
_store: dict#
class flexget.utils.tools.TitleYear(title, year)[source]#

Bases: NamedTuple

Parameters:
  • title (str)

  • year (int | None)

classmethod _make(iterable)#

Make a new TitleYear object from a sequence or iterable

_asdict()#

Return a new dict which maps field names to their values.

_replace(**kwds)#

Return a new TitleYear object replacing specified fields with new values

_field_defaults = {}#
_fields = ('title', 'year')#
title: str#

Alias for field number 0

year: int | None#

Alias for field number 1

flexget.utils.tools._htmldecode(text)[source]#

Decode HTML entities in the given text.

Parameters:

text (str)

Return type:

str

flexget.utils.tools.aggregate_inputs(task, inputs)[source]#
Parameters:
Return type:

list[Entry]

flexget.utils.tools.chunked(seq, limit=900)[source]#

Divide our expired lists into sizes sqlite can handle in a query. (<1000).

Parameters:
  • seq (Sequence)

  • limit (int)

Return type:

Iterator[Sequence]

flexget.utils.tools.decode_html(value)[source]#

Return Html decoded string.

Parameters:

value (string) – String to be html-decoded

Return type:

str

flexget.utils.tools.encode_html(unicode_data, encoding='ascii')[source]#

Encode unicode_data for use as XML or HTML, with characters outside of the encoding converted to XML numeric character references.

Parameters:
  • unicode_data (str)

  • encoding (str)

Return type:

bytes

flexget.utils.tools.format_filesize(num_bytes, si=False, unit=None)[source]#

Return given bytes as prettified string.

Parameters:
  • si (bool) – If true, decimal based units will be used rather than binary.

  • unit (str) – If a specific unit is specified it will be used. Otherwise, an appropriate unit will be picked automatically based on size.

  • num_bytes (float)

Return type:

str

flexget.utils.tools.get_config_as_array(config, key)[source]#

Return configuration key as array, even if given as a single string.

Parameters:
  • config (dict) – Configuration

  • key (string) – Configuration

Returns:

Array

Return type:

list

flexget.utils.tools.get_config_hash(config)[source]#

Return MD5 hash for config.

Parameters:

config (dict) – Configuration

Return type:

str

flexget.utils.tools.get_current_flexget_version()[source]#
Return type:

str

flexget.utils.tools.get_latest_flexget_version_number()[source]#

Return latest Flexget version from https://pypi.python.org/pypi/FlexGet/json.

Return type:

str | None

flexget.utils.tools.group_entries(entries, identifier)[source]#
Parameters:
  • entries (Iterable[Entry])

  • identifier (str)

Return type:

dict[str, list[Entry]]

flexget.utils.tools.merge_dict_from_to(d1, d2)[source]#

Merge dictionary d1 into dictionary d2. d1 will remain in original form.

Parameters:
Return type:

None

flexget.utils.tools.multiply_timedelta(interval, number)[source]#

timedelta cannot normally be multiplied by floating points. This does that.

Parameters:
Return type:

timedelta

flexget.utils.tools.parse_episode_identifier(ep_id, identify_season=False)[source]#

Parse series episode identifier, raise ValueError if it fails.

Parameters:
  • ep_id (str | int) – Value to parse

  • identify_season (bool)

Returns:

Return identifier type: sequence, ep or date

Raises:

ValueError – If ep_id does not match any valid types

Return type:

tuple[str, str]

flexget.utils.tools.parse_filesize(text_size, si=True, match_re=None)[source]#

Parse a data size and returns its value in bytes.

Parameters:
  • text_size (string) – string containing the data size to parse i.e. “5 GB”

  • si (bool) – If True, possibly ambiguous units like KB, MB, GB will be assumed to be base 10 units, rather than base 2. i.e. if si then 1 KB = 1000 B else 1 KB = 1024 B

  • match_re (str | Pattern[str] | None) – A custom regex can be defined to match the size. The first capture group should match the number, and the second should match the unit.

Returns:

an int with the data size in bytes

Return type:

int

flexget.utils.tools.parse_timedelta(value)[source]#

Parse a string like ‘5 days’ into a timedelta object. Also allows timedeltas to pass through.

Parameters:

value (timedelta | str | None)

Return type:

timedelta

flexget.utils.tools.pid_exists(pid)[source]#
Parameters:

pid (int)

flexget.utils.tools.split_title_year(title)[source]#

Split title containing a year into a title, year pair.

Parameters:

title (str)

Return type:

TitleYear

flexget.utils.tools.str_to_boolean(string)[source]#
Parameters:

string (str)

Return type:

bool

flexget.utils.tools.str_to_int(string)[source]#
Parameters:

string (str)

Return type:

int | None

flexget.utils.tools.strip_html(text)[source]#

Try to strip all HTML tags from text. If unsuccessful returns original text.

Parameters:

text (str)

Return type:

str