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

Album implementation. More...

#include "compile_time.h"
#include "src/lib/album.h"
#include "src/lib/cache/cache_rax_album.h"
#include "src/lib/convert.h"
#include "src/lib/json/json_print.h"
#include "src/lib/mem.h"
#include "src/lib/sds_extras.h"
#include "src/lib/utility.h"
#include "src/mympd_client/tags.h"
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for album.c:

Data Structures

struct  t_album_tag_value
 
struct  t_album
 

Functions

static sds get_tag_value_string (const struct t_album *album, enum mpd_tag_type tag, sds tag_values, unsigned *value_count)
 
static sds get_tag_values (const struct t_album *album, enum mpd_tag_type tag, sds tag_values, bool multi, unsigned *value_count)
 
struct t_albumalbum_new (void)
 
struct t_albumalbum_new_uri (const char *uri)
 
struct t_albumalbum_new_from_song (const struct mpd_song *song, const struct t_mympd_mpd_tags *album_tags)
 
void album_free (struct t_album *album)
 
const char * album_get_uri (const struct t_album *album)
 
unsigned album_get_total_time (const struct t_album *album)
 
time_t album_get_last_modified (const struct t_album *album)
 
time_t album_get_added (const struct t_album *album)
 
unsigned album_get_song_count (const struct t_album *album)
 
unsigned album_get_disc_count (const struct t_album *album)
 
const char * album_get_tag (const struct t_album *album, enum mpd_tag_type type, unsigned idx)
 
bool album_get_unknown (const struct t_album *album)
 
void album_set_unknown (struct t_album *album, bool unknown)
 
void album_set_discs (struct t_album *album, const char *disc)
 
void album_set_disc_count (struct t_album *album, unsigned count)
 
void album_set_last_modified (struct t_album *album, time_t last_modified)
 
void album_set_added (struct t_album *album, time_t added)
 
void album_set_total_time (struct t_album *album, unsigned duration)
 
void album_inc_total_time (struct t_album *album, unsigned duration)
 
void album_set_song_count (struct t_album *album, unsigned count)
 
void album_inc_song_count (struct t_album *album)
 
bool album_append_tags (struct t_album *album, const struct mpd_song *song, const struct t_mympd_mpd_tags *tags)
 
bool album_append_tag (struct t_album *album, enum mpd_tag_type type, const char *value)
 
bool album_copy_tags (struct t_album *album, enum mpd_tag_type src, enum mpd_tag_type dst)
 
void album_set_uri (struct t_album *album, const char *uri)
 
sds album_get_tag_value_string (const struct t_album *album, enum mpd_tag_type tag, sds tag_values)
 
sds album_get_tag_values (const struct t_album *album, enum mpd_tag_type tag, sds tag_values)
 
sds album_get_tag_value_padded (const struct t_album *album, enum mpd_tag_type tag, char pad, size_t len, sds tag_values)
 
sds print_album_tags (sds buffer, const struct t_albums_config *album_config, const struct t_mympd_mpd_tags *tagcols, const struct t_album *album)
 

Detailed Description

Album implementation.

Function Documentation

◆ album_append_tag()

bool album_append_tag ( struct t_album album,
enum mpd_tag_type  type,
const char *  value 
)

Adds a tag value to the album if value does not already exists

Parameters
albumpointer to a t_album struct
typempd tag type
valuetag value to add
Returns
true if tag is added or already there, false if the tag could not be added

◆ album_append_tags()

bool album_append_tags ( struct t_album album,
const struct mpd_song *  song,
const struct t_mympd_mpd_tags tags 
)

Appends tag values from a song to the album

Parameters
albumpointer to a t_album struct representing the album
songsong to add tag values from
tagstags to append
Returns
true on success else false

◆ album_copy_tags()

bool album_copy_tags ( struct t_album album,
enum mpd_tag_type  src,
enum mpd_tag_type  dst 
)

Copies all values from a tag to another tag

Parameters
albumpointer to a t_album struct
srcsource tag
dstdestination tag
Returns
true on success, else false

◆ album_free()

void album_free ( struct t_album album)

Frees an album struct

Parameters
albumPointer to album struct

◆ album_get_added()

time_t album_get_added ( const struct t_album album)

Gets the added timestamp for the album

Parameters
albumt_album struct representing the album
Returns
time_t added timestamp

◆ album_get_disc_count()

unsigned album_get_disc_count ( const struct t_album album)

Gets the number of discs

Parameters
albumt_album struct representing the album
Returns
number of discs

◆ album_get_last_modified()

time_t album_get_last_modified ( const struct t_album album)

Gets the last-modified timestamp for the album

Parameters
albumt_album struct representing the album
Returns
time_t last-modified timestamp

◆ album_get_song_count()

unsigned album_get_song_count ( const struct t_album album)

Gets the number of songs

Parameters
albumt_album struct representing the album
Returns
number of songs

◆ album_get_tag()

const char * album_get_tag ( const struct t_album album,
enum mpd_tag_type  type,
unsigned  idx 
)

Gets the album tag value at position idx

Parameters
albumt_album struct representing the album
typempd tag type
idxindex of tag value to get
Returns
const char* tag value or NULL

◆ album_get_tag_value_padded()

sds album_get_tag_value_padded ( const struct t_album album,
enum mpd_tag_type  tag,
char  pad,
size_t  len,
sds  tag_values 
)

Get's a tag value from an album and pads it

Parameters
albumAlbum struct
tagmpd tag type
padpadding char
lenlength to pad
tag_valuesalready allocated sds string to append
Returns
sds new sds pointer to tag_values

◆ album_get_tag_value_string()

sds album_get_tag_value_string ( const struct t_album album,
enum mpd_tag_type  tag,
sds  tag_values 
)

Appends a comma separated list of tag values

Parameters
albumpointer to album struct
tagmpd tag type to get values for
tag_valuesalready allocated sds string to append the values
Returns
new sds pointer to tag_values

◆ album_get_tag_values()

sds album_get_tag_values ( const struct t_album album,
enum mpd_tag_type  tag,
sds  tag_values 
)

Appends a a json string/array of tag values

Parameters
albumpointer to album struct
tagmpd tag type to get values for
tag_valuesalready allocated sds string to append the values
Returns
new sds pointer to tag_values

◆ album_get_total_time()

unsigned album_get_total_time ( const struct t_album album)

Gets the album duration

Parameters
albumt_album struct representing the album
Returns
unsigned album duration

◆ album_get_unknown()

bool album_get_unknown ( const struct t_album album)

Gets the unknown marker for an album

Parameters
albumt_album struct representing the album
Returns
bool true if it is a unknown album, else false

◆ album_get_uri()

const char * album_get_uri ( const struct t_album album)

Gets the album uri (uri of first song)

Parameters
albumt_album struct representing the album
Returns
const char* first song uri

◆ album_inc_song_count()

void album_inc_song_count ( struct t_album album)

Increments the song count

Parameters
albumpointer to a t_album struct

◆ album_inc_total_time()

void album_inc_total_time ( struct t_album album,
unsigned  duration 
)

Increments the albums duration

Parameters
albumt_album struct representing the album
durationseconds to increment

◆ album_new()

struct t_album * album_new ( void  )

Creates and initializes a new struct for an album.

Returns
struct t_album* or NULL on error

◆ album_new_from_song()

struct t_album * album_new_from_song ( const struct mpd_song *  song,
const struct t_mympd_mpd_tags album_tags 
)

Creates and initializes a new struct for an album with values copied from song

Parameters
songSong to create album from
album_tagsTags to use
Returns
struct t_album* or NULL on error

◆ album_new_uri()

struct t_album * album_new_uri ( const char *  uri)

Creates and initializes a new struct for an album with defined first song uri

Parameters
uriFirst song uri
Returns
struct t_album* or NULL on error

◆ album_set_added()

void album_set_added ( struct t_album album,
time_t  added 
)

Sets the albums added timestamp if it is older as current album added timestamp

Parameters
albumt_album struct representing the album
addedadded timestamp to set

◆ album_set_disc_count()

void album_set_disc_count ( struct t_album album,
unsigned  count 
)

Sets a fixed disc count

Parameters
albumt_album struct representing the album
countdisc count

◆ album_set_discs()

void album_set_discs ( struct t_album album,
const char *  disc 
)

Sets the albums disc count from disc song tag

Parameters
albumt_album struct representing the album
discmpd song disc tag value

◆ album_set_last_modified()

void album_set_last_modified ( struct t_album album,
time_t  last_modified 
)

Sets the albums last modified timestamp if it is newer as current album last-modified timestamp

Parameters
albumt_album struct representing the album
last_modifiedlast-modified timestamp to set

◆ album_set_song_count()

void album_set_song_count ( struct t_album album,
unsigned  count 
)

Set the song count

Parameters
albumt_album struct representing the album
countsong count

◆ album_set_total_time()

void album_set_total_time ( struct t_album album,
unsigned  duration 
)

Sets the albums duration

Parameters
albumt_album struct representing the album
durationtotal time to set

◆ album_set_unknown()

void album_set_unknown ( struct t_album album,
bool  unknown 
)

Sets the unknown marker for an album

Parameters
albumt_album struct representing the album
unknowntrue if it is a unknown album, else false

◆ album_set_uri()

void album_set_uri ( struct t_album album,
const char *  uri 
)

Replaces the uri

Parameters
albumpointer to album struct
urinew uri to set

◆ get_tag_value_string()

static sds get_tag_value_string ( const struct t_album album,
enum mpd_tag_type  tag,
sds  tag_values,
unsigned *  value_count 
)
static

Appends a comma separated list of tag values

Parameters
albumpointer to album struct
tagmpd tag type to get values for
tag_valuesalready allocated sds string to append the values
value_countthe number of values retrieved
Returns
new sds pointer to tag_values

◆ get_tag_values()

static sds get_tag_values ( const struct t_album album,
enum mpd_tag_type  tag,
sds  tag_values,
bool  multi,
unsigned *  value_count 
)
static

Appends a json string or array to tag_values. Nothing is append if value is empty.

Parameters
albumpointer to album struct
tagmpd tag type to get values for
tag_valuesalready allocated sds string to append the values
value_countthe number of values retrieved
multitrue if it is a multi value string
Returns
new sds pointer to tag_values

◆ print_album_tags()

sds print_album_tags ( sds  buffer,
const struct t_albums_config album_config,
const struct t_mympd_mpd_tags tagcols,
const struct t_album album 
)

Prints the tag values for an album as json string

Parameters
bufferalready allocated sds string to append the values
album_configAlbum configuration
tagcolspointer to t_tags struct (tags to retrieve)
albumpointer to album
Returns
new sds pointer to buffer