Formatter

Provides an extensible framework for processing and preparation of data for display in various contexts.

Formatters

xl.formatter.Formatter

alias of mocks.

xl.formatter.ProgressTextFormatter

alias of mocks.

xl.formatter.TrackFormatter

alias of mocks.

class xl.formatter.TagFormatter(name)[source]

A formatter provider for a tag of a track

format(track, parameters)[source]

Formats a raw tag value. Accepts optional parameters to manipulate the formatting process.

Parameters:
  • track (xl.trax.Track) – the track to get the tag from
  • parameters (dictionary) – optionally passed parameters
Returns:

the formatted value

Return type:

string

class xl.formatter.TrackNumberTagFormatter[source]

Bases: xl.formatter.NumberTagFormatter

A formatter for the tracknumber of a track

class xl.formatter.DiscNumberTagFormatter[source]

Bases: xl.formatter.NumberTagFormatter

A formatter for the discnumber of a track

class xl.formatter.ArtistTagFormatter[source]

Bases: xl.formatter.TagFormatter

A formatter for the artist of a track

format(track, parameters)[source]

Formats a raw tag value

Parameters:
  • track (xl.trax.Track) – the track to get the tag from
  • parameters

    optionally passed parameters Possible values are:

    • compilate: Allows for proper handling of compilations, either via albumartist tag, a fallback value, or simply all artists
Returns:

the formatted value

Return type:

string

class xl.formatter.LengthTagFormatter[source]

Bases: xl.formatter.TimeTagFormatter

A formatter for the length of a track

format(track, parameters)

Formats a raw tag value

Parameters:
  • track (xl.trax.Track) – the track to get the tag from
  • parameters (dictionary) –

    Verbosity of the output, possible values for “format” are:

    • short: “1:02:42”
    • long: “1h, 2m, 42s”
    • verbose: “1 hour, 2 minutes, 42 seconds”
Returns:

the formatted value

Return type:

string

static format_value(value, format='short')

Formats a length value

Parameters:
  • value (float) – the length in seconds
  • format (string) –

    verbosity of the output, possible values are:

    • short: “1:02:42”
    • long: “1h, 2m, 42s”
    • verbose: “1 hour, 2 minutes, 42 seconds”
Returns:

the formatted value

Return type:

string

class xl.formatter.RatingTagFormatter[source]

Bases: xl.formatter.TagFormatter

A formatter for the rating of a track

Will return glyphs representing the rating like ★★★☆☆

class xl.formatter.LastPlayedTagFormatter[source]

Bases: xl.formatter.DateTagFormatter

A formatter for the last time a track was played

Templates

class xl.formatter.ParameterTemplate(template)[source]

An extended template class which additionally accepts parameters assigned to identifiers.

This introduces another pattern group named “parameters” in addition to the groups created by string.Template

Examples:

  • ${foo:parameter1}
  • ${bar:parameter1, parameter2}
  • ${qux:parameter1=argument1, parameter2}