Skip to content

Commit

Permalink
Metadata cannot be trusted to always exist
Browse files Browse the repository at this point in the history
Also switch to using titleformatting for media name
  • Loading branch information
saivert committed Jul 7, 2018
1 parent 8f627e5 commit a96eaeb
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static int state=OUTPUT_STATE_STOPPED;
static uintptr_t mutex;
static int buffer_size;
static int cork_requested;
static char *tfbytecode;

static int pulse_init();

Expand Down Expand Up @@ -129,6 +130,11 @@ static pa_proplist* get_stream_prop_song(DB_playItem_t *track)
{
pa_proplist *pl;
int rc, notrackgiven=0;
ddb_tf_context_t ctx = {
._size = sizeof(ddb_tf_context_t),
.flags = DDB_TF_CONTEXT_NO_DYNAMIC,
.plt = NULL,
.iter = PL_MAIN};

pl = pa_proplist_new();
BUG_ON(!pl);
Expand All @@ -141,19 +147,26 @@ static pa_proplist* get_stream_prop_song(DB_playItem_t *track)

char buf[1000];
const char *artist, *title;

ctx.it = track;
if (deadbeef->tf_eval(&ctx, tfbytecode, buf, sizeof(buf)) > 0) {
rc = pa_proplist_sets(pl, PA_PROP_MEDIA_NAME, buf);
BUG_ON(rc);
}

deadbeef->pl_lock();
artist = deadbeef->pl_find_meta(track, "artist");
title = deadbeef->pl_find_meta(track, "title");
snprintf (buf, sizeof(buf), "%s - %s", artist, title);

rc = pa_proplist_sets(pl, PA_PROP_MEDIA_NAME, buf);
BUG_ON(rc);

rc = pa_proplist_sets(pl, PA_PROP_MEDIA_ARTIST, artist);
BUG_ON(rc);
if (artist) {
rc = pa_proplist_sets(pl, PA_PROP_MEDIA_ARTIST, artist);
BUG_ON(rc);
}

rc = pa_proplist_sets(pl, PA_PROP_MEDIA_TITLE, title);
BUG_ON(rc);
if (title) {
rc = pa_proplist_sets(pl, PA_PROP_MEDIA_TITLE, title);
BUG_ON(rc);
}

rc = pa_proplist_sets(pl, PA_PROP_MEDIA_FILENAME, deadbeef->pl_find_meta(track, ":URI"));
BUG_ON(rc);
Expand Down Expand Up @@ -742,12 +755,14 @@ static int pulse_get_state(void)
static int pulse_plugin_start(void)
{
mutex = deadbeef->mutex_create();
tfbytecode = deadbeef->tf_compile("[%artist% - ]%title%");
return 0;
}

static int pulse_plugin_stop(void)
{
deadbeef->mutex_free(mutex);
deadbeef->tf_free(tfbytecode);
return 0;
}

Expand Down

0 comments on commit a96eaeb

Please sign in to comment.