Advanced use. Not required for most things.
Some options can have dynamically formatted values based on other entry fields. This is done using the powerful jinja2 template system to create or modify entry fields.
NOTES:
now
is also available, which is a python datetime object representing the current time.This example sets the content_filename
using the information parsed by the series plugin. The deluge plugin uses the content_filename
field to rename a file inside the torrent.
set:
content_filename: "{{ series_name|replace(' ','.') }}.{{ series_id }}.{{ quality|upper }}{% if proper %}-proper{% endif %}"
This will result in filenames like: The.Show.S02E03.HDTV.avi and Other.Show.S02E04.720P-proper.mkv
Note: To get up-to-date information about all available Jinja filters, use the following CLI command:
flexget jinja-filters
When using Jinja2 templates, you can use the following custom filters in addition to the built-in ones.
Name | Description |
---|---|
asciify |
Simplify a string replacing for example à with a , õ with o and ç with c |
format_number |
Formats a number according to the user's locale. |
format_size(si=false) |
Formats a number of bytes into an appropriate unit. (biggest unit where the value is still over 1) e.g. 1.3 GiB |
formatdate(format) |
Do string formatting on datetime objects according to strftime. |
get_year |
Get year from end of string (for example: get year from the end of movie name) |
pad(length) |
Pad a number with 0s to the specified length |
parse_size(si=false) |
Tries to parse a size from a human readable format. e.g. 3GB, 32 kb. Result will be in bytes. If si is true , sizes will be assumed to be with metric prefixes. e.g. 1KB = 1000B (rather than 1024B) |
parsedate |
Attempts to parse a date according to the rules in RFC 2822 |
pathbase |
Base name of a path. |
pathdir |
Directory containing the given path. |
pathext |
Extension of a path (including the '.'). |
pathname |
Base name of a path, without its extension. |
pathscrub(os) |
Replace problematic characters in a path. If os parameter is omitted, the current os, or os defined by pathscrub plugin will be used. NOTE: This should rarely be needed due to the builtin pathscrub plugin. |
re_replace(pattern, replacement) |
Do regexp substitution on the string. NOTE 1: Case-sensitive. You can change this behaviour by starting your pattern with (?i) - 'This MIGHT Match'|re_replace('might', 'WON’T') - 'This MIGHT Match'|re_replace('(?i)might', 'WILL') NOTE 2: Captured groups can be accessed in the replacement string by using backreferences: - \\1 when enclosed with apostrophes or \\\\1 when enclosed with quotes- \g<1> when enclosed with either apostrophes or quotes |
re_search(pattern) |
Perform a search for given regexp pattern, return the matching portion of the text. |
strip_symbols |
Removes all special chars from a string, keeps accent words. The symbols are removed, only ()-_[]. and replaced by a space . Double space are also replaced by a single space |
strip_year |
Removes year from end of string (for example: remove year from the end of movie name) |
to_date |
Formats date |
set:
# Replace filename by title and keep the extension
filename: '{{title}}{{filename | pathext}}'
# Create a simple title
id_name: '{{title|asciify|strip_symbols}}'
When using Jinja2 tests, you can use the following custom tests in addition to the built-in tests.
Name | Description |
---|---|
is fs_file |
Check whether object is existing file (or symlink) in filesystem. |
is fs_dir |
Check whether object is existing directory (or symlink) in filesystem. |
is fs_link |
Check whether object is existing symlink in filesystem. |
if:
# check whether torrent file is in incomplete directory
- ('/path/torrents/incomplete' ~ title) is fs_file: reject