1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-27 03:10:26 +00:00

Return coverimage in backend to client, dont guess it.

This commit is contained in:
jcorporation 2018-06-22 01:01:15 +01:00
parent 9996c33adf
commit f5f5b23312
3 changed files with 36 additions and 31 deletions

View File

@ -194,8 +194,7 @@ main {
.card-img-top { .card-img-top {
min-height:250px; min-height:250px;
background-image:url('/assets/coverimage-notavailable.png');
background-repeat:no-repeat; background-repeat:no-repeat;
background-color:#d45500; background-color:#eee;
cursor:pointer; cursor:pointer;
} }

View File

@ -839,7 +839,7 @@ function parseListTitles(obj) {
if(app.current.app !== 'Browse' && app.current.tab !== 'Database' && app.current.view !== 'Album') return; if(app.current.app !== 'Browse' && app.current.tab !== 'Database' && app.current.view !== 'Album') return;
var id=genId(obj.album); var id=genId(obj.album);
var album=$('#card'+id+' > div > table > tbody'); var album=$('#card'+id+' > div > table > tbody');
$('#card'+id+' > img').attr('src','/library/'+obj.data[0].uri.replace(/\/[^\/]+$/,'\/')+settings.coverimage) $('#card'+id+' > img').attr('src',obj.cover)
.attr('uri',obj.data[0].uri.replace(/\/[^\/]+$/,'')) .attr('uri',obj.data[0].uri.replace(/\/[^\/]+$/,''))
.attr('data-album',encodeURI(obj.album)); .attr('data-album',encodeURI(obj.album));
var titleList=''; var titleList='';
@ -1270,17 +1270,8 @@ function songChange(obj) {
var htmlNotification = ''; var htmlNotification = '';
var pageTitle = 'myMPD: '; var pageTitle = 'myMPD: ';
if (typeof obj.data.uri != 'undefined' && obj.data.uri.length > 0) { $('#album-cover').css('backgroundImage','url("'+obj.data.cover+'")');
var coverImg='';
if (obj.data.uri.indexOf('http://') == 0 || obj.data.uri.indexOf('https://') == 0 ) {
coverImg='/assets/coverimage-httpstream.png';
} else if (settings.coverimage != '') {
coverImg='/library/'+obj.data.uri.replace(/\/[^\/]+$/,'\/'+settings.coverimage);
} else {
coverImg='/assets/coverimage-notavailable.png';
}
$('#album-cover').css('backgroundImage','url("'+coverImg+'"),url("/assets/coverimage-notavailable.png")');
}
if(typeof obj.data.artist != 'undefined' && obj.data.artist.length > 0 && obj.data.artist != '-') { if(typeof obj.data.artist != 'undefined' && obj.data.artist.length > 0 && obj.data.artist != '-') {
textNotification += obj.data.artist; textNotification += obj.data.artist;
htmlNotification += '<br/>' + obj.data.artist; htmlNotification += '<br/>' + obj.data.artist;

View File

@ -28,6 +28,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <libgen.h> #include <libgen.h>
#include <ctype.h> #include <ctype.h>
#include <libgen.h>
#include <mpd/client.h> #include <mpd/client.h>
#include <mpd/message.h> #include <mpd/message.h>
@ -461,24 +462,20 @@ void mympd_poll(struct mg_mgr *s)
char* mympd_get_title(struct mpd_song const *song) char* mympd_get_title(struct mpd_song const *song)
{ {
char *str; char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_TITLE, 0); str = (char *)mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
if(str == NULL){ if(str == NULL){
str = basename((char *)mpd_song_get_uri(song)); str = basename((char *)mpd_song_get_uri(song));
} }
return str; return str;
} }
char* mympd_get_track(struct mpd_song const *song) char* mympd_get_track(struct mpd_song const *song)
{ {
char *str; char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_TRACK, 0); str = (char *)mpd_song_get_tag(song, MPD_TAG_TRACK, 0);
if(str == NULL){ if(str == NULL){
str = "-"; str = "-";
} }
return str; return str;
} }
@ -486,48 +483,40 @@ char* mympd_get_track(struct mpd_song const *song)
char* mympd_get_album(struct mpd_song const *song) char* mympd_get_album(struct mpd_song const *song)
{ {
char *str; char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM, 0); str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
if(str == NULL){ if(str == NULL){
str = "-"; str = "-";
} }
return str; return str;
} }
char* mympd_get_artist(struct mpd_song const *song) char* mympd_get_artist(struct mpd_song const *song)
{ {
char *str; char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); str = (char *)mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
if(str == NULL){ if(str == NULL){
str = "-"; str = "-";
} }
return str; return str;
} }
char* mympd_get_album_artist(struct mpd_song const *song) char* mympd_get_album_artist(struct mpd_song const *song)
{ {
char *str; char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM_ARTIST, 0); str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM_ARTIST, 0);
if(str == NULL){ if(str == NULL){
str = "-"; str = "-";
} }
return str; return str;
} }
char* mympd_get_year(struct mpd_song const *song) char* mympd_get_year(struct mpd_song const *song)
{ {
char *str; char *str;
str = (char *)mpd_song_get_tag(song, MPD_TAG_DATE, 0); str = (char *)mpd_song_get_tag(song, MPD_TAG_DATE, 0);
if(str == NULL){ if(str == NULL){
str = "-"; str = "-";
} }
return str; return str;
} }
@ -704,19 +693,41 @@ int mympd_put_outputnames(char *buffer)
return len; return len;
} }
int mympd_get_cover(const char *uri, char *cover, int cover_len)
{
char *path=strdup(uri);
int len;
if (strncasecmp("http:",path,5) == 0 ) {
len=snprintf(cover,cover_len,"/assets/coverimage-httpstream.png");
}
else {
dirname(path);
snprintf(cover,cover_len,"%s/library/%s/%s",SRC_PATH,path,coverimage);
if ( access(cover, F_OK ) == -1 ) {
len = snprintf(cover,cover_len,"/assets/coverimage-notavailable.png");
} else {
len = snprintf(cover,cover_len,"/library/%s/%s",path,coverimage);
}
}
return len;
}
int mympd_put_current_song(char *buffer) int mympd_put_current_song(char *buffer)
{ {
struct mpd_song *song; struct mpd_song *song;
int len; int len;
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE); struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
char cover[500];
song = mpd_run_current_song(mpd.conn); song = mpd_run_current_song(mpd.conn);
if(song == NULL) if(song == NULL)
return 0; return 0;
mympd_get_cover(mpd_song_get_uri(song),cover,500);
len = json_printf(&out,"{type: song_change, data: { pos: %d, title: %Q, " len = json_printf(&out,"{type: song_change, data: { pos: %d, title: %Q, "
"artist: %Q, album: %Q, uri: %Q, currentsongid: %d, albumartist: %Q, " "artist: %Q, album: %Q, uri: %Q, currentsongid: %d, albumartist: %Q, "
"duration: %d }}", "duration: %d, cover: %Q }}",
mpd_song_get_pos(song), mpd_song_get_pos(song),
mympd_get_title(song), mympd_get_title(song),
mympd_get_artist(song), mympd_get_artist(song),
@ -724,7 +735,8 @@ int mympd_put_current_song(char *buffer)
mpd_song_get_uri(song), mpd_song_get_uri(song),
mpd.song_id, mpd.song_id,
mympd_get_album_artist(song), mympd_get_album_artist(song),
mpd_song_get_duration(song) mpd_song_get_duration(song),
cover
); );
mpd_song_free(song); mpd_song_free(song);
@ -947,6 +959,7 @@ int mympd_put_songs_in_album(char *buffer, char *albumartist, char *album)
unsigned long entity_count = 0; unsigned long entity_count = 0;
unsigned long entities_returned = 0; unsigned long entities_returned = 0;
int len; int len;
char cover[500];
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE); struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
if(mpd_search_db_songs(mpd.conn, true) == false) { if(mpd_search_db_songs(mpd.conn, true) == false) {
@ -968,6 +981,7 @@ int mympd_put_songs_in_album(char *buffer, char *albumartist, char *album)
entity_count ++; entity_count ++;
if(entity_count <= MAX_ELEMENTS_PER_PAGE) { if(entity_count <= MAX_ELEMENTS_PER_PAGE) {
if (entities_returned ++) len += json_printf(&out, ", "); if (entities_returned ++) len += json_printf(&out, ", ");
else mympd_get_cover(mpd_song_get_uri(song),cover,500);
len += json_printf(&out, "{ type: song, uri: %Q, duration: %d, title: %Q, track: %Q }", len += json_printf(&out, "{ type: song, uri: %Q, duration: %d, title: %Q, track: %Q }",
mpd_song_get_uri(song), mpd_song_get_uri(song),
mpd_song_get_duration(song), mpd_song_get_duration(song),
@ -978,11 +992,12 @@ int mympd_put_songs_in_album(char *buffer, char *albumartist, char *album)
mpd_song_free(song); mpd_song_free(song);
} }
len += json_printf(&out, "], totalEntities: %d, returnedEntities: %d, albumartist: %Q, album: %Q }", len += json_printf(&out, "], totalEntities: %d, returnedEntities: %d, albumartist: %Q, album: %Q, cover: %Q }",
entity_count, entity_count,
entities_returned, entities_returned,
albumartist, albumartist,
album album,
cover
); );
} }