myMPD
Internal API documentation
Loading...
Searching...
No Matches
playlists.c File Reference

Playlist helper functions. More...

#include "compile_time.h"
#include "src/mympd_client/playlists.h"
#include "dist/rax/rax.h"
#include "src/lib/convert.h"
#include "src/lib/fields.h"
#include "src/lib/list/shuffle.h"
#include "src/lib/log.h"
#include "src/lib/random.h"
#include "src/lib/rax_extras.h"
#include "src/lib/sds/sds_extras.h"
#include "src/lib/smartpls.h"
#include "src/mympd_client/database.h"
#include "src/mympd_client/errorhandler.h"
#include "src/mympd_client/shortcuts.h"
#include "src/mympd_client/tags.h"
#include <stdbool.h>
#include <string.h>
Include dependency graph for playlists.c:

Functions

static bool playlist_sort (struct t_partition_state *partition_state, const char *playlist, const char *tagstr, bool sortdesc, sds *error)
static bool playlist_replace (struct t_partition_state *partition_state, const char *new_pl, const char *to_replace_pl, sds *error)
static bool playlist_content_enumerate_mpd (struct t_partition_state *partition_state, const char *plist, unsigned *count, unsigned *duration, sds *error)
static bool playlist_content_enumerate_manual (struct t_partition_state *partition_state, const char *plist, unsigned *count, unsigned *duration, sds *error)
bool mympd_client_playlist_exists (struct t_partition_state *partition_state, const char *plist)
bool mympd_client_playlist_delete_if_exists (struct t_partition_state *partition_state, const char *plist)
bool mympd_client_get_all_playlists (struct t_partition_state *partition_state, struct t_list *l, bool smartpls, sds *error)
time_t mympd_client_get_playlist_mtime (struct t_partition_state *partition_state, const char *playlist)
int64_t mympd_client_playlist_dedup_all (struct t_partition_state *partition_state, bool remove, sds *error)
int64_t mympd_client_playlist_dedup (struct t_partition_state *partition_state, const char *playlist, bool remove, sds *error)
int mympd_client_playlist_validate_all (struct t_partition_state *partition_state, bool remove, sds *error)
int mympd_client_playlist_validate (struct t_partition_state *partition_state, const char *playlist, bool remove, sds *error)
bool mympd_client_playlist_shuffle (struct t_partition_state *partition_state, const char *playlist, sds *error)
bool mympd_client_playlist_sort (struct t_partition_state *partition_state, const char *playlist, const char *tagstr, bool sortdesc, sds *error)
bool mympd_client_enum_playlist (struct t_partition_state *partition_state, const char *plist, unsigned *count, unsigned *duration, sds *error)
bool mympd_client_playlist_crop (struct t_partition_state *partition_state, const char *plist, unsigned num_entries)
bool mympd_client_playlist_clear (struct t_partition_state *partition_state, const char *plist, sds *error)
bool mympd_send_list_playlist_range (struct t_partition_state *partition_state, const char *plist, unsigned start, unsigned end)
bool mympd_send_list_playlist_range_meta (struct t_partition_state *partition_state, const char *plist, unsigned start, unsigned end)
bool mympd_client_playlist_get (struct t_partition_state *partition_state, const char *plist, bool reverse, struct t_list *l, sds *error)
enum playlist_sort_types playlist_parse_sort (const char *str)

Detailed Description

Playlist helper functions.

Function Documentation

◆ mympd_client_enum_playlist()

bool mympd_client_enum_playlist ( struct t_partition_state * partition_state,
const char * plist,
unsigned * count,
unsigned * duration,
sds * error )

Counts the number of songs in the playlist

Parameters
partition_statepointer to partition specific states
plistplaylist to enumerate
countpointer to unsigned for entity count
durationpointer to unsigned for total playtime
errorpointer to an already allocated sds string for the error message
Returns
number of songs or -1 on error

◆ mympd_client_get_all_playlists()

bool mympd_client_get_all_playlists ( struct t_partition_state * partition_state,
struct t_list * l,
bool smartpls,
sds * error )

Gets all playlists.

Parameters
partition_statepointer to partition state
lpointer to list to populate
smartplstrue = integrate smart playlists, false = ignore smart playlists
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_client_get_playlist_mtime()

time_t mympd_client_get_playlist_mtime ( struct t_partition_state * partition_state,
const char * playlist )

Returns the playlists last modification time

Parameters
partition_statepointer to partition specific states
playlistname of the playlist to check
Returns
last modification time or 0 on error

◆ mympd_client_playlist_clear()

bool mympd_client_playlist_clear ( struct t_partition_state * partition_state,
const char * plist,
sds * error )

Clears a playlist

Parameters
partition_statepointer to partition specific states
plistplaylist name
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_client_playlist_crop()

bool mympd_client_playlist_crop ( struct t_partition_state * partition_state,
const char * plist,
unsigned num_entries )

Crops a playlist

Parameters
partition_statePointer to partition specific states
plistPlaylist name
num_entriesMay number of songs
Returns
true on success, else false

◆ mympd_client_playlist_dedup()

int64_t mympd_client_playlist_dedup ( struct t_partition_state * partition_state,
const char * playlist,
bool remove,
sds * error )

Deduplicates the playlist content

Parameters
partition_statepointer to partition state
playlistplaylist to check
removetrue = remove duplicate songs, else count duplicate songs
errorpointer to an already allocated sds string for the error message
Returns
-1 on error, else number of duplicate songs

◆ mympd_client_playlist_dedup_all()

int64_t mympd_client_playlist_dedup_all ( struct t_partition_state * partition_state,
bool remove,
sds * error )

Deduplicates all static playlists

Parameters
partition_statepointer to partition state
removetrue = remove duplicate songs, else count duplicate songs
errorpointer to an already allocated sds string for the error message
Returns
-1 on error, else number of removed songs

◆ mympd_client_playlist_delete_if_exists()

bool mympd_client_playlist_delete_if_exists ( struct t_partition_state * partition_state,
const char * plist )

Deletes playlists if it exists

Parameters
partition_statePointer to partition state
plistPlaylist to delete
Returns
true on success, else false

◆ mympd_client_playlist_exists()

bool mympd_client_playlist_exists ( struct t_partition_state * partition_state,
const char * plist )

Public functions Check if playlist exists

Parameters
partition_statePointer to partition state
plistPlaylist name
Returns
true if exists, else false

◆ mympd_client_playlist_get()

bool mympd_client_playlist_get ( struct t_partition_state * partition_state,
const char * plist,
bool reverse,
struct t_list * l,
sds * error )

Gets the contents of a playlist. Uses the range feature for MPD 0.24+

Parameters
partition_statePointer to partition specific states
plistPlaylist name
reverseList in reverse order?
lAlready allocated list
errorPointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_client_playlist_shuffle()

bool mympd_client_playlist_shuffle ( struct t_partition_state * partition_state,
const char * playlist,
sds * error )

Shuffles a playlist

Parameters
partition_statepointer to partition specific states
playlistplaylist to shuffle
errorpointer to an already allocated sds string for the error message
Returns
true on success else false

◆ mympd_client_playlist_sort()

bool mympd_client_playlist_sort ( struct t_partition_state * partition_state,
const char * playlist,
const char * tagstr,
bool sortdesc,
sds * error )

Sorts a playlist. Wrapper for playlist_sort that enables the mympd tags afterwards

Parameters
partition_statepointer to partition specific states
playlistplaylist to shuffle
tagstrmpd tag to sort by
sortdescsort descending?
errorpointer to an already allocated sds string for the error message
Returns
true on success else false

◆ mympd_client_playlist_validate()

int mympd_client_playlist_validate ( struct t_partition_state * partition_state,
const char * playlist,
bool remove,
sds * error )

Validates the playlist entries

Parameters
partition_statepointer to partition state
playlistplaylist to check
removetrue = remove invalid songs, else count invalid songs
errorpointer to an already allocated sds string for the error message
Returns
-1 on error, else number of removed songs

◆ mympd_client_playlist_validate_all()

int mympd_client_playlist_validate_all ( struct t_partition_state * partition_state,
bool remove,
sds * error )

Validates all entries from all static playlists

Parameters
partition_statepointer to partition state
removetrue = remove invalid songs, else count invalid songs
errorpointer to an already allocated sds string for the error message
Returns
-1 on error, else number of removed songs

◆ mympd_send_list_playlist_range()

bool mympd_send_list_playlist_range ( struct t_partition_state * partition_state,
const char * plist,
unsigned start,
unsigned end )

Wrapper for mpd_send_list_playlist_range that falls back to mpd_send_list_playlist if not supported by MPD.

Parameters
partition_statePointer to partition specific states
plistPlaylist name
startStart position (including)
endEnd position (excluding)
Returns
true on success, else false

◆ mympd_send_list_playlist_range_meta()

bool mympd_send_list_playlist_range_meta ( struct t_partition_state * partition_state,
const char * plist,
unsigned start,
unsigned end )

Wrapper for mpd_send_list_playlist_range_meta that falls back to mpd_send_list_playlist_meta if not supported by MPD.

Parameters
partition_statePointer to partition specific states
plistPlaylist name
startStart position (including)
endEnd position (excluding)
Returns
true on success, else false

◆ playlist_content_enumerate_manual()

bool playlist_content_enumerate_manual ( struct t_partition_state * partition_state,
const char * plist,
unsigned * count,
unsigned * duration,
sds * error )
static

Enumerates the playlist and returns the count and total length. For MPD versions < 0.24. This functions retrieves the complete playlist.

Parameters
partition_statepointer to partition state
plistplaylist name to enumerate
countpointer to unsigned for entity count
durationpointer to unsigned for total playtime
errorpointer to an already allocated sds string for the error message
Returns
pointer to buffer

◆ playlist_content_enumerate_mpd()

bool playlist_content_enumerate_mpd ( struct t_partition_state * partition_state,
const char * plist,
unsigned * count,
unsigned * duration,
sds * error )
static

Enumerates the playlist and returns the count and total length This functions uses the playlistlength command of MPD 0.24

Parameters
partition_statepointer to partition state
plistplaylist name to enumerate
countpointer to unsigned for entity count
durationpointer to unsigned for total playtime
errorpointer to an already allocated sds string for the error message
Returns
pointer to buffer

◆ playlist_parse_sort()

enum playlist_sort_types playlist_parse_sort ( const char * str)

Parses the provided string to the playlist_sort_type

Parameters
strString to parse
Returns
enum playlist_sort_types or PLSORT_UNKNOWN on error

◆ playlist_replace()

bool playlist_replace ( struct t_partition_state * partition_state,
const char * new_pl,
const char * to_replace_pl,
sds * error )
static

Safely replaces a playlist with a new one

Parameters
partition_statepointer to partition specific states
new_plname of the new playlist to bring in place
to_replace_plname of the playlist to replace
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ playlist_sort()

bool playlist_sort ( struct t_partition_state * partition_state,
const char * playlist,
const char * tagstr,
bool sortdesc,
sds * error )
static

Private definitions

Private functions Sorts a playlist.

Parameters
partition_statepointer to partition specific states
playlistplaylist to shuffle
tagstrmpd tag to sort by
sortdescsort descending?
errorpointer to an already allocated sds string for the error message
Returns
true on success else false