Playlist
Provides the fundamental objects for handling a list of tracks contained in playlists as well as methods to import and export from various file formats.
Playlists
- class xl.playlist.Playlist(name, initial_tracks=[])[source]
Basic class for handling a list of tracks
- EVENTS: (all events are synchronous)
- playlist_tracks_added
fired: after tracks are added
data: list of tuples of (index, track)
- playlist_tracks_removed
fired: after tracks are removed
data: list of tuples of (index, track)
playlist_current_position_changed
playlist_shuffle_mode_changed
playlist_random_mode_changed
playlist_dynamic_mode_changed
- append(other)[source]
Appends a single track to the playlist
Prefer extend() for batch updates, so that playlist_tracks_added is not emitted excessively.
- Parameters:
other – a
xl.trax.Track
- property current_position
The position within the playlist (int)
- property dirty
Whether the playlist was changed or not (boolean)
- property dynamic_mode
The current dynamic mode (string)
- extend(other)[source]
Extends the playlist by another playlist
- Parameters:
other – list of
xl.trax.Track
- get_current()[source]
Retrieves the track at the current position
- Returns:
the track
- Return type:
xl.trax.Trackor None
- get_current_position()[source]
Retrieves the current position within the playlist
- Returns:
the position
- Return type:
- get_dynamic_mode()[source]
Retrieves the current dynamic mode
- Returns:
the dynamic mode
- Return type:
string
- get_repeat_mode()[source]
Retrieves the current repeat mode
- Returns:
the repeat mode
- Return type:
string
- get_shuffle_history()[source]
Retrieves the history of played tracks from a shuffle run
- Returns:
the tracks
- Return type:
- get_shuffle_mode()[source]
Retrieves the current shuffle mode
- Returns:
the shuffle mode
- Return type:
string
- get_spat_position()[source]
Retrieves the current position within the playlist after which progressing shall be stopped
- Returns:
the position
- Return type:
- index(item, start=0, end=None)[source]
Retrieves the index of a track within the playlist
- Returns:
the index
- Return type:
- load_from_location(location)[source]
Loads the content of the playlist from a given location
- Parameters:
location (string) – the location to load from
- property name
The playlist name (string)
- next()[source]
Progresses to the next track within the playlist and takes shuffle and repeat modes into account
- Returns:
the new current track
- Return type:
xl.trax.Trackor None
- pop(i=-1)[source]
Pops a track from the playlist
- Parameters:
i (int) – the index
- Returns:
the track
- Return type:
- prev()[source]
Progresses to the previous track within the playlist and takes shuffle and repeat modes into account
- Returns:
the new current track
- Return type:
xl.trax.Trackor None
- randomize(positions=None)[source]
Randomizes the content of the playlist contrary to shuffle which affects only the progressing order
By default all tracks in the playlist are randomized, but a list of positions can be passed. The tracks on these positions will be randomized, all other tracks will keep their positions.
- Parameters:
positions (iterable) – list of track positions to randomize
- property repeat_mode
The current repeat mode (string)
- save_to_location(location)[source]
Writes the content of the playlist to a given location
- Parameters:
location (string) – the location to save to
- set_current_position(position)[source]
Sets the current position within the playlist
- Parameters:
position (int) – the new position
- set_dynamic_mode(mode)[source]
Sets the current dynamic mode
- Parameters:
mode (string) – the new dynamic mode
- set_repeat_mode(mode)[source]
Sets the current repeat mode
- Parameters:
mode (string) – the new repeat mode
- set_shuffle_mode(mode)[source]
Sets the current shuffle mode
- Parameters:
mode (string) – the new shuffle mode
- set_spat_position(position)[source]
Sets the current position within the playlist after which progressing shall be stopped
- Parameters:
position (int) – the new position
- property shuffle_mode
The current shuffle mode (string)
- shuffle_mode_names = ['Shuffle _Off', 'Shuffle _Tracks', 'Shuffle _Albums', '_Random']
Titles of the valid shuffle modes (list of string)
- shuffle_modes = ['disabled', 'track', 'album', 'random']
Valid shuffle modes (list of string)
- sort(tags, reverse=False)[source]
Sorts the content of the playlist
- Parameters:
tags (list of strings) – tags to sort by
reverse (boolean) – whether the sorting shall be reversed
- property spat_position
The position within the playlist after which to stop progressing (int)
Playlist Converters
- class xl.playlist.FormatConverter(name)[source]
Base class for all converters allowing to import from and export to a specific format
- export_to_file(playlist, path, options=None)[source]
Export a playlist to a given path
- Parameters:
playlist (
Playlist) – the playlistpath (string) – the target path
options (
PlaylistExportOptions) – exporting options
- class xl.playlist.M3UConverter[source]
Bases:
FormatConverterImport from and export to M3U format
- class xl.playlist.PLSConverter[source]
Bases:
FormatConverterImport from and export to PLS format
- class xl.playlist.ASXConverter[source]
Bases:
FormatConverterImport from and export to ASX format
- class xl.playlist.XSPFConverter[source]
Bases:
FormatConverterImport from and export to XSPF format