1
0
mirror of https://github.com/SuperBFG7/ympd synced 2025-04-10 04:36:46 +00:00

Central mympd_get_tag function

This commit is contained in:
jcorporation 2018-07-09 18:49:55 +01:00
parent ff2b40baf8
commit 44d0c1d56e

View File

@ -511,73 +511,15 @@ void mympd_poll(struct mg_mgr *s)
}
}
char* mympd_get_title(struct mpd_song const *song)
char* mympd_get_tag(struct mpd_song const *song, enum mpd_tag_type tag)
{
char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
if(str == NULL){
str = basename((char *)mpd_song_get_uri(song));
}
return str;
}
char* mympd_get_genre(struct mpd_song const *song)
{
char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_GENRE, 0);
if(str == NULL){
str = "-";
}
return str;
}
char* mympd_get_track(struct mpd_song const *song)
{
char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_TRACK, 0);
if(str == NULL){
str = "-";
}
return str;
}
char* mympd_get_album(struct mpd_song const *song)
{
char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
if(str == NULL){
str = "-";
}
return str;
}
char* mympd_get_artist(struct mpd_song const *song)
{
char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
if(str == NULL){
str = "-";
}
return str;
}
char* mympd_get_album_artist(struct mpd_song const *song)
{
char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM_ARTIST, 0);
if(str == NULL){
str = "-";
}
return str;
}
char* mympd_get_year(struct mpd_song const *song)
{
char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_DATE, 0);
if(str == NULL){
str = "-";
str = (char *)mpd_song_get_tag(song, tag, 0);
if (str == NULL){
if (tag == MPD_TAG_TITLE)
str = basename((char *)mpd_song_get_uri(song));
else
str = "-";
}
return str;
}
@ -791,12 +733,12 @@ int mympd_put_current_song(char *buffer)
"artist: %Q, album: %Q, uri: %Q, currentsongid: %d, albumartist: %Q, "
"duration: %d, cover: %Q }}",
mpd_song_get_pos(song),
mympd_get_title(song),
mympd_get_artist(song),
mympd_get_album(song),
mympd_get_tag(song, MPD_TAG_TITLE),
mympd_get_tag(song, MPD_TAG_ARTIST),
mympd_get_tag(song, MPD_TAG_ALBUM),
mpd_song_get_uri(song),
mpd.song_id,
mympd_get_album_artist(song),
mympd_get_tag(song, MPD_TAG_ALBUM_ARTIST),
mpd_song_get_duration(song),
cover
);
@ -821,15 +763,17 @@ int mympd_put_songdetails(char *buffer, char *uri)
while ((entity = mpd_recv_entity(mpd.conn)) != NULL) {
song = mpd_entity_get_song(entity);
mympd_get_cover(mpd_song_get_uri(song),cover,500);
len += json_printf(&out, "duration: %d, artist: %Q, album: %Q, title: %Q, albumartist: %Q, cover: %Q, uri: %Q, genre: %Q",
len += json_printf(&out, "duration: %d, artist: %Q, album: %Q, title: %Q, albumartist: %Q, cover: %Q, uri: %Q, genre: %Q, track: %Q, date: %Q",
mpd_song_get_duration(song),
mympd_get_artist(song),
mympd_get_album(song),
mympd_get_title(song),
mympd_get_album_artist(song),
mympd_get_tag(song, MPD_TAG_ARTIST),
mympd_get_tag(song, MPD_TAG_ALBUM),
mympd_get_tag(song, MPD_TAG_TITLE),
mympd_get_tag(song, MPD_TAG_ALBUM_ARTIST),
cover,
uri,
mympd_get_genre(song)
mympd_get_tag(song, MPD_TAG_GENRE),
mympd_get_tag(song, MPD_TAG_TRACK),
mympd_get_tag(song, MPD_TAG_DATE)
);
mpd_entity_free(entity);
}
@ -867,9 +811,9 @@ int mympd_put_queue(char *buffer, unsigned int offset)
mpd_song_get_id(song),
mpd_song_get_pos(song),
mpd_song_get_duration(song),
mympd_get_artist(song),
mympd_get_album(song),
mympd_get_title(song),
mympd_get_tag(song, MPD_TAG_ARTIST),
mympd_get_tag(song, MPD_TAG_ALBUM),
mympd_get_tag(song, MPD_TAG_TITLE),
mpd_song_get_uri(song)
);
}
@ -914,15 +858,15 @@ int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter
break;
case MPD_ENTITY_TYPE_SONG:
song = mpd_entity_get_song(entity);
entityName = mympd_get_title(song);
entityName = mympd_get_tag(song, MPD_TAG_TITLE);
if (strncmp(filter,"-",1) == 0 || strncasecmp(filter,entityName,1) == 0 ||
( strncmp(filter,"0",1) == 0 && isalpha(*entityName) == 0 )
) {
if (entities_returned ++) len += json_printf(&out,",");
len += json_printf(&out, "{type: song, uri: %Q, album: %Q, artist: %Q, duration: %d, title: %Q, name: %Q }",
mpd_song_get_uri(song),
mympd_get_album(song),
mympd_get_artist(song),
mympd_get_tag(song, MPD_TAG_ALBUM),
mympd_get_tag(song, MPD_TAG_ARTIST),
mpd_song_get_duration(song),
entityName,
entityName
@ -1082,8 +1026,8 @@ int mympd_put_songs_in_album(char *buffer, char *albumartist, char *album)
len += json_printf(&out, "{ type: song, uri: %Q, duration: %d, title: %Q, track: %Q }",
mpd_song_get_uri(song),
mpd_song_get_duration(song),
mympd_get_title(song),
mympd_get_track(song)
mympd_get_tag(song, MPD_TAG_TITLE),
mympd_get_tag(song, MPD_TAG_TRACK)
);
}
mpd_song_free(song);
@ -1181,11 +1125,11 @@ int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *sear
if (entities_returned ++) len += json_printf(&out, ", ");
len += json_printf(&out, "{ type: song, uri: %Q, album: %Q, artist: %Q, duration: %d, title: %Q, name: %Q }",
mpd_song_get_uri(song),
mympd_get_album(song),
mympd_get_artist(song),
mympd_get_tag(song, MPD_TAG_ALBUM),
mympd_get_tag(song, MPD_TAG_ARTIST),
mpd_song_get_duration(song),
mympd_get_title(song),
mympd_get_title(song)
mympd_get_tag(song, MPD_TAG_TITLE),
mympd_get_tag(song, MPD_TAG_TITLE)
);
}
mpd_song_free(song);
@ -1267,10 +1211,10 @@ int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char
len += json_printf(&out, "{ type: song, id: %d, pos: %d, album: %Q, artist: %Q, duration: %d, title: %Q }",
mpd_song_get_id(song),
mpd_song_get_pos(song),
mympd_get_album(song),
mympd_get_artist(song),
mympd_get_tag(song, MPD_TAG_ALBUM),
mympd_get_tag(song, MPD_TAG_ARTIST),
mpd_song_get_duration(song),
mympd_get_title(song)
mympd_get_tag(song, MPD_TAG_TITLE)
);
mpd_song_free(song);
}