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=[])

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

Parameters:
  • name (string) – the initial name of the playlist
  • initial_tracks (list of xl.trax.Track) – the tracks which shall populate the playlist initially
append(other)

Appends a single track to the playlist

Parameters:other – list of xl.trax.Track
clear()

Removes all contained tracks

clear_shuffle_history()

Clear the history of played tracks from a shuffle run

count(other)

Returns the count of contained tracks

Returns:the count
Return type:int
extend(other)

Extends the playlist by another playlist

Parameters:other – list of xl.trax.Track
get_current()

Retrieves the track at the current position

Returns:the track
Return type:xl.trax.Track or None
get_current_position()

Retrieves the current position within the playlist

Returns:the position
Return type:int
get_dynamic_mode()

Retrieves the current dynamic mode

Returns:the dynamic mode
Return type:string
get_repeat_mode()

Retrieves the current repeat mode

Returns:the repeat mode
Return type:string
get_shuffle_history()

Retrieves the history of played tracks from a shuffle run

Returns:the tracks
Return type:list
get_shuffle_mode()

Retrieves the current shuffle mode

Returns:the shuffle mode
Return type:string
get_spat_position()

Retrieves the current position within the playlist after which progressing shall be stopped

Returns:the position
Return type:int
index(item, start=0, end=None)

Retrieves the index of a track within the playlist

Returns:the index
Return type:int
load_from_location(location)

Loads the content of the playlist from a given location

Parameters:location (string) – the location to load from
next()

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.Track or None
pop(i=-1)

Pops a track from the playlist

Parameters:i (int) – the index
Returns:the track
Return type:xl.trax.Track
prev()

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.Track or None
randomize(positions=None)

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
save_to_location(location)

Writes the content of the playlist to a given location

Parameters:location (string) – the location to save to
set_current_position(position)

Sets the current position within the playlist

Parameters:position (int) – the new position
set_dynamic_mode(mode)

Sets the current dynamic mode

Parameters:mode (string) – the new dynamic mode
set_repeat_mode(mode)

Sets the current repeat mode

Parameters:mode (string) – the new repeat mode
set_shuffle_mode(mode)

Sets the current shuffle mode

Parameters:mode (string) – the new shuffle mode
set_spat_position(position)

Sets the current position within the playlist after which progressing shall be stopped

Parameters:position (int) – the new position
sort(tags, reverse=False)

Sorts the content of the playlist

Parameters:
  • tags (list of strings) – tags to sort by
  • reverse (boolean) – whether the sorting shall be reversed
current_position

The position within the playlist (int)

dirty

Whether the playlist was changed or not (boolean)

dynamic_mode

The current dynamic mode (string)

name

The playlist name (string)

repeat_mode

The current repeat mode (string)

shuffle_mode

The current shuffle mode (string)

shuffle_mode_names = [u'Shuffle _Off', u'Shuffle _Tracks', u'Shuffle _Albums']

Titles of the valid shuffle modes (list of string)

shuffle_modes = ['disabled', 'track', 'album']

Valid shuffle modes (list of string)

spat_position

The position within the playlist after which to stop progressing (int)

Playlist Converters

class xl.playlist.FormatConverter(name)

Base class for all converters allowing to import from and export to a specific format

export_to_file(playlist, path, options=None)

Export a playlist to a given path

Parameters:
  • playlist (Playlist) – the playlist
  • path (string) – the target path
  • options (PlaylistExportOptions) – exporting options
import_from_file(path)

Import a playlist from a given path

Parameters:path (string) – the source path
Returns:the playlist
Return type:Playlist
name_from_path(path)

Convenience method to retrieve a sane name from a path

Parameters:path (string) – the source path
Returns:a name
Return type:string
class xl.playlist.M3UConverter

Bases: xl.playlist.FormatConverter

Import from and export to M3U format

class xl.playlist.PLSConverter

Bases: xl.playlist.FormatConverter

Import from and export to PLS format

class xl.playlist.ASXConverter

Bases: xl.playlist.FormatConverter

Import from and export to ASX format

class xl.playlist.XSPFConverter

Bases: xl.playlist.FormatConverter

Import from and export to XSPF format