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

myMPD playlists API More...

#include "compile_time.h"
#include "src/mympd_api/playlists.h"
#include "dist/utf8/utf8.h"
#include "src/lib/api.h"
#include "src/lib/cache/cache_rax_album.h"
#include "src/lib/filehandler.h"
#include "src/lib/json/json_print.h"
#include "src/lib/json/json_rpc.h"
#include "src/lib/list.h"
#include "src/lib/log.h"
#include "src/lib/mem.h"
#include "src/lib/rax_extras.h"
#include "src/lib/sds_extras.h"
#include "src/lib/search.h"
#include "src/lib/smartpls.h"
#include "src/lib/utility.h"
#include "src/mympd_api/sticker.h"
#include "src/mympd_client/errorhandler.h"
#include "src/mympd_client/playlists.h"
#include "src/mympd_client/search.h"
#include "src/mympd_client/shortcuts.h"
#include "src/mympd_client/stickerdb.h"
#include "src/mympd_client/tags.h"
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for playlists.c:

Data Structures

struct  t_pl_data
 

Functions

static void free_t_pl_data (void *data)
 
bool mympd_api_playlist_content_move_to_playlist (struct t_partition_state *partition_state, sds src_plist, sds dst_plist, struct t_list *positions, unsigned mode, sds *error)
 
bool mympd_api_playlist_copy (struct t_partition_state *partition_state, struct t_list *src_plists, sds dst_plist, enum plist_copy_modes mode, sds *error)
 
bool mympd_api_playlist_content_insert (struct t_partition_state *partition_state, sds plist, struct t_list *uris, unsigned to, sds *error)
 
bool mympd_api_playlist_content_append (struct t_partition_state *partition_state, sds plist, struct t_list *uris, sds *error)
 
bool mympd_api_playlist_content_replace (struct t_partition_state *partition_state, sds plist, struct t_list *uris, sds *error)
 
bool mympd_api_playlist_content_insert_search (struct t_partition_state *partition_state, sds expression, sds plist, unsigned to, const char *sort, bool sort_desc, sds *error)
 
bool mympd_api_playlist_content_append_search (struct t_partition_state *partition_state, sds expression, sds plist, const char *sort, bool sort_desc, sds *error)
 
bool mympd_api_playlist_content_replace_search (struct t_partition_state *partition_state, sds expression, sds plist, const char *sort, bool sort_desc, sds *error)
 
bool mympd_api_playlist_content_insert_albums (struct t_partition_state *partition_state, struct t_cache *album_cache, sds plist, struct t_list *albumids, unsigned to, sds *error)
 
bool mympd_api_playlist_content_append_albums (struct t_partition_state *partition_state, struct t_cache *album_cache, sds plist, struct t_list *albumids, sds *error)
 
bool mympd_api_playlist_content_replace_albums (struct t_partition_state *partition_state, struct t_cache *album_cache, sds plist, struct t_list *albumids, sds *error)
 
bool mympd_api_playlist_content_insert_album_tag (struct t_partition_state *partition_state, struct t_cache *album_cache, sds plist, sds albumid, enum mpd_tag_type tag, sds value, unsigned to, sds *error)
 
bool mympd_api_playlist_content_append_album_tag (struct t_partition_state *partition_state, struct t_cache *album_cache, sds plist, sds albumid, enum mpd_tag_type tag, sds value, sds *error)
 
bool mympd_api_playlist_content_replace_album_tag (struct t_partition_state *partition_state, struct t_cache *album_cache, sds plist, sds albumid, enum mpd_tag_type tag, sds value, sds *error)
 
bool mympd_api_playlist_content_move (struct t_partition_state *partition_state, sds plist, unsigned from, unsigned to, sds *error)
 
bool mympd_api_playlist_content_rm_range (struct t_partition_state *partition_state, sds plist, unsigned start, int end, sds *error)
 
bool mympd_api_playlist_content_rm_positions (struct t_partition_state *partition_state, sds plist, struct t_list *positions, sds *error)
 
sds mympd_api_playlist_list (struct t_partition_state *partition_state, struct t_stickerdb_state *stickerdb, sds buffer, unsigned request_id, unsigned offset, unsigned limit, sds searchstr, enum playlist_types type, enum playlist_sort_types sort, bool sortdesc, const struct t_fields *tagcols)
 
static sds print_plist_entry (sds buffer, struct mpd_song *song, unsigned pos, bool stickers, struct t_partition_state *partition_state, struct t_stickerdb_state *stickerdb, const struct t_fields *tagcols, time_t *last_played_max, sds *last_played_song_uri, unsigned *last_played_pos, sds *last_played_song_title)
 
sds mympd_api_playlist_content_search (struct t_partition_state *partition_state, struct t_stickerdb_state *stickerdb, sds buffer, unsigned request_id, sds plist, unsigned offset, unsigned limit, sds expression, const struct t_fields *tagcols)
 
sds mympd_api_playlist_rename (struct t_partition_state *partition_state, sds buffer, unsigned request_id, const char *old_playlist, const char *new_playlist)
 
bool mympd_api_playlist_delete (struct t_partition_state *partition_state, struct t_list *playlists, sds *error)
 
enum plist_delete_criterias parse_plist_delete_criteria (const char *str)
 
sds mympd_api_playlist_delete_all (struct t_partition_state *partition_state, sds buffer, unsigned request_id, enum plist_delete_criterias criteria)
 

Detailed Description

myMPD playlists API

Function Documentation

◆ free_t_pl_data()

static void free_t_pl_data ( void *  data)
static

Frees the t_pl_data struct used as callback for rax_free_data

Parameters
datavoid pointer to a t_sticker_value struct

◆ mympd_api_playlist_content_append()

bool mympd_api_playlist_content_append ( struct t_partition_state partition_state,
sds  plist,
struct t_list uris,
sds *  error 
)

Appends uris to the stored playlist

Parameters
partition_statepointer to partition state
pliststored playlist name
urislist of positions to remove
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_append_album_tag()

bool mympd_api_playlist_content_append_album_tag ( struct t_partition_state partition_state,
struct t_cache album_cache,
sds  plist,
sds  albumid,
enum mpd_tag_type  tag,
sds  value,
sds *  error 
)

Appends songs of an album filted by tag to a playlist

Parameters
partition_statepointer to partition state
album_cachepointer to album cache
pliststored playlist name
albumidalbum id to append
tagMPD tag
valueMPD tag value
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_append_albums()

bool mympd_api_playlist_content_append_albums ( struct t_partition_state partition_state,
struct t_cache album_cache,
sds  plist,
struct t_list albumids,
sds *  error 
)

Appends albums to a playlist

Parameters
partition_statepointer to partition state
album_cachepointer to album cache
pliststored playlist name
albumidsalbum ids to append
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_append_search()

bool mympd_api_playlist_content_append_search ( struct t_partition_state partition_state,
sds  expression,
sds  plist,
const char *  sort,
bool  sort_desc,
sds *  error 
)

Appends the search results to the queue

Parameters
partition_statepointer to partition state
expressionmpd search expression
pliststored playlist name
sortsort by tag
sort_descsort descending?
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_insert()

bool mympd_api_playlist_content_insert ( struct t_partition_state partition_state,
sds  plist,
struct t_list uris,
unsigned  to,
sds *  error 
)

Inserts uris at defined position to the stored playlist

Parameters
partition_statepointer to partition state
pliststored playlist name
toposition to insert after
urislist of positions to remove
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_insert_album_tag()

bool mympd_api_playlist_content_insert_album_tag ( struct t_partition_state partition_state,
struct t_cache album_cache,
sds  plist,
sds  albumid,
enum mpd_tag_type  tag,
sds  value,
unsigned  to,
sds *  error 
)

Insert songs of an album filtered by tag into a playlist

Parameters
partition_statepointer to partition state
album_cachepointer to album cache
pliststored playlist name
albumidalbum id to insert
tagMPD tag
valueMPD tag value
toposition to insert
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_insert_albums()

bool mympd_api_playlist_content_insert_albums ( struct t_partition_state partition_state,
struct t_cache album_cache,
sds  plist,
struct t_list albumids,
unsigned  to,
sds *  error 
)

Insert albums into a playlist

Parameters
partition_statepointer to partition state
album_cachepointer to album cache
pliststored playlist name
albumidsalbum ids to insert
toposition to insert
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_insert_search()

bool mympd_api_playlist_content_insert_search ( struct t_partition_state partition_state,
sds  expression,
sds  plist,
unsigned  to,
const char *  sort,
bool  sort_desc,
sds *  error 
)

Inserts search results into a playlist

Parameters
partition_statepointer to partition state
expressionmpd search expression
pliststored playlist name
toposition to insert
sortsort by tag
sort_descsort descending?
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_move()

bool mympd_api_playlist_content_move ( struct t_partition_state partition_state,
sds  plist,
unsigned  from,
unsigned  to,
sds *  error 
)

Moves a song inside a playlist

Parameters
partition_statepointer to partition state
pliststored playlist name
fromfrom position
toto position
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_move_to_playlist()

bool mympd_api_playlist_content_move_to_playlist ( struct t_partition_state partition_state,
sds  src_plist,
sds  dst_plist,
struct t_list positions,
unsigned  mode,
sds *  error 
)

Moves entries from one playlist to another.

Parameters
partition_statepointer to partition state
src_plistsource playlist
dst_plistdestination playlist
positionssource playlist positions to move
mode0=append, 1=insert to destination playlist
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_replace()

bool mympd_api_playlist_content_replace ( struct t_partition_state partition_state,
sds  plist,
struct t_list uris,
sds *  error 
)

Replaces the stored playlist with uris

Parameters
partition_statepointer to partition state
pliststored playlist name
urislist of positions to remove
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_replace_album_tag()

bool mympd_api_playlist_content_replace_album_tag ( struct t_partition_state partition_state,
struct t_cache album_cache,
sds  plist,
sds  albumid,
enum mpd_tag_type  tag,
sds  value,
sds *  error 
)

Replaces the playlist with songs of an album filtered by tag

Parameters
partition_statepointer to partition state
album_cachepointer to album cache
pliststored playlist name
albumidalbum id to insert
tagMPD tag
valueMPD tag value
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_replace_albums()

bool mympd_api_playlist_content_replace_albums ( struct t_partition_state partition_state,
struct t_cache album_cache,
sds  plist,
struct t_list albumids,
sds *  error 
)

Replaces the playlist with albums

Parameters
partition_statepointer to partition state
album_cachepointer to album cache
pliststored playlist name
albumidsalbum ids to insert
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_replace_search()

bool mympd_api_playlist_content_replace_search ( struct t_partition_state partition_state,
sds  expression,
sds  plist,
const char *  sort,
bool  sort_desc,
sds *  error 
)

Replaces the queue with the search result

Parameters
partition_statepointer to partition state
expressionmpd search expression
pliststored playlist name
sortsort by tag
sort_descsort descending?
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_rm_positions()

bool mympd_api_playlist_content_rm_positions ( struct t_partition_state partition_state,
sds  plist,
struct t_list positions,
sds *  error 
)

Removes entries defined by positions from the stored playlist

Parameters
partition_statepointer to partition state
pliststored playlist name
positionslist of positions to remove
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_rm_range()

bool mympd_api_playlist_content_rm_range ( struct t_partition_state partition_state,
sds  plist,
unsigned  start,
int  end,
sds *  error 
)

Removes a range of songs in a playlist

Parameters
partition_statepointer to partition state
pliststored playlist name
startstart position (including)
endend position (excluded), -1 for open ended range
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_content_search()

sds mympd_api_playlist_content_search ( struct t_partition_state partition_state,
struct t_stickerdb_state stickerdb,
sds  buffer,
unsigned  request_id,
sds  plist,
unsigned  offset,
unsigned  limit,
sds  expression,
const struct t_fields tagcols 
)

Lists the content of a mpd playlist

Parameters
partition_statepointer to partition state
stickerdbpointer to stickerdb state
bufferalready allocated sds string to append the response
request_idjsonrpc request id
plistplaylist name to list contents
offsetlist offset
limitmaximum number of entries to print
expressionmpd search expression
tagcolscolumns to print
Returns
pointer to buffer

◆ mympd_api_playlist_copy()

bool mympd_api_playlist_copy ( struct t_partition_state partition_state,
struct t_list src_plists,
sds  dst_plist,
enum plist_copy_modes  mode,
sds *  error 
)

Copies or moves source playlists to a destination playlist.

Parameters
partition_statepointer to partition state
src_plistsplaylists to copy
dst_plistdestination playlist
modecopy mode enum
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_delete()

bool mympd_api_playlist_delete ( struct t_partition_state partition_state,
struct t_list playlists,
sds *  error 
)

Deletes the mpd playlists and the myMPD smart playlists

Parameters
partition_statepointer to partition state
playlistsplaylist to delete
errorpointer to an already allocated sds string for the error message
Returns
true on success, else false

◆ mympd_api_playlist_delete_all()

sds mympd_api_playlist_delete_all ( struct t_partition_state partition_state,
sds  buffer,
unsigned  request_id,
enum plist_delete_criterias  criteria 
)

Deletes the mpd playlists and the myMPD smart playlist

Parameters
partition_statepointer to partition state
bufferalready allocated sds string to append the response
request_idjsonrpc request id
criteriadeletion criteria
Returns
pointer to buffer

◆ mympd_api_playlist_list()

sds mympd_api_playlist_list ( struct t_partition_state partition_state,
struct t_stickerdb_state stickerdb,
sds  buffer,
unsigned  request_id,
unsigned  offset,
unsigned  limit,
sds  searchstr,
enum playlist_types  type,
enum playlist_sort_types  sort,
bool  sortdesc,
const struct t_fields tagcols 
)

Lists mpd playlists and myMPD smart playlists

Parameters
partition_statepointer to partition state
stickerdbpointer to stickerdb state
bufferalready allocated sds string to append the response
request_idjsonrpc request id
offsetlist offset
limitmaximum number of entries to print
searchstrstring to search in the playlist name
typeplaylist type to list
sortSort playlists by name or Last-Modified
sortdescSort descending?
tagcolscolumns to print
Returns
pointer to buffer

◆ mympd_api_playlist_rename()

sds mympd_api_playlist_rename ( struct t_partition_state partition_state,
sds  buffer,
unsigned  request_id,
const char *  old_playlist,
const char *  new_playlist 
)

Rename the mpd playlists and the corresponding myMPD smart playlist

Parameters
partition_statepointer to partition state
bufferalready allocated sds string to append the response
request_idjsonrpc request id
old_playlistold playlist name
new_playlistnew playlist name
Returns
pointer to buffer

◆ parse_plist_delete_criteria()

enum plist_delete_criterias parse_plist_delete_criteria ( const char *  str)

Parses the playlist delete criteria from string to enum

Parameters
strstring to parse
Returns
parsed criteria as enum

◆ print_plist_entry()

static sds print_plist_entry ( sds  buffer,
struct mpd_song *  song,
unsigned  pos,
bool  stickers,
struct t_partition_state partition_state,
struct t_stickerdb_state stickerdb,
const struct t_fields tagcols,
time_t *  last_played_max,
sds *  last_played_song_uri,
unsigned *  last_played_pos,
sds *  last_played_song_title 
)
static

Appends a playlist entry to buffer

Parameters
bufferalready allocated sds string to append the response
songmpd song to print
posposition in playlist
stickersprint stickers?
partition_statepointer to partition state
stickerdbpointer to stickerdb state
tagcolscolumns to print
last_played_maxplayed time from last played song
last_played_song_urilast played song uri
last_played_poslast played position in playlist
last_played_song_titlelast played song title tag
Returns
pointer to buffer