Skip to content

Commit 10b4b5b

Browse files
committed
Add real_uri into mpd_song
1 parent d88ba47 commit 10b4b5b

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

include/mpd/song.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ const char *
100100
mpd_song_get_tag(const struct mpd_song *song,
101101
enum mpd_tag_type type, unsigned idx);
102102

103+
/**
104+
* Returns the "real" URI of the song, the one to be used for opening
105+
* the resource. If this attribute is nullptr, then #mpd_song_get_uri
106+
* shall be used.
107+
*/
108+
mpd_pure
109+
const char *
110+
mpd_song_get_real_uri(const struct mpd_song *song);
111+
103112
/**
104113
* Returns the duration of this song in seconds. 0 means the duration
105114
* is unknown.

libmpdclient.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ global:
362362
mpd_song_dup;
363363
mpd_song_get_uri;
364364
mpd_song_get_tag;
365+
mpd_song_get_real_uri;
365366
mpd_song_get_duration;
366367
mpd_song_get_duration_ms;
367368
mpd_song_get_start;

src/song.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ struct mpd_song {
5555

5656
struct mpd_tag_value tags[MPD_TAG_COUNT];
5757

58+
/**
59+
* The "real" URI, the one to be used for opening the
60+
* resource. If this attribute is nullptr, then #uri
61+
* shall be used.
62+
*/
63+
char *real_uri;
64+
5865
/**
5966
* Duration of the song in seconds, or 0 for unknown.
6067
*/
@@ -136,6 +143,7 @@ mpd_song_new(const char *uri)
136143
for (unsigned i = 0; i < MPD_TAG_COUNT; ++i)
137144
song->tags[i].value = NULL;
138145

146+
song->real_uri = NULL;
139147
song->duration = 0;
140148
song->duration_ms = 0;
141149
song->start = 0;
@@ -179,6 +187,8 @@ void mpd_song_free(struct mpd_song *song) {
179187
}
180188
}
181189

190+
free(song->real_uri);
191+
182192
free(song);
183193
}
184194

@@ -216,6 +226,7 @@ mpd_song_dup(const struct mpd_song *song)
216226
} while (src_tag != NULL);
217227
}
218228

229+
ret->real_uri = strdup(song->real_uri);
219230
ret->duration = song->duration;
220231
ret->duration_ms = song->duration_ms;
221232
ret->start = song->start;
@@ -331,6 +342,20 @@ mpd_song_get_tag(const struct mpd_song *song,
331342
return tag->value;
332343
}
333344

345+
static void
346+
mpd_song_set_real_uri(struct mpd_song *song, char *real_uri)
347+
{
348+
song->real_uri = real_uri;
349+
}
350+
351+
const char *
352+
mpd_song_get_real_uri(const struct mpd_song *song)
353+
{
354+
assert(song != NULL);
355+
356+
return song->real_uri;
357+
}
358+
334359
static void
335360
mpd_song_set_duration(struct mpd_song *song, unsigned duration)
336361
{
@@ -546,6 +571,8 @@ mpd_song_feed(struct mpd_song *song, const struct mpd_pair *pair)
546571
mpd_song_set_prio(song, strtoul(pair->value, NULL, 10));
547572
else if (strcmp(pair->name, "Format") == 0)
548573
mpd_song_parse_audio_format(song, pair->value);
574+
else if (strcmp(pair->name, "RealUri") == 0)
575+
mpd_song_set_real_uri(song, strdup(pair->value));
549576

550577
return true;
551578
}

0 commit comments

Comments
 (0)