diff --git a/htdocs/css/mympd.css b/htdocs/css/mympd.css index 1f5064f..65e5cbf 100644 --- a/htdocs/css/mympd.css +++ b/htdocs/css/mympd.css @@ -275,4 +275,9 @@ caption { .modal-body .album-cover { float:none; -} \ No newline at end of file +} + +#BrowseDatabaseAlbumListCaption { + width:100%; + margin-left: 15px; +} diff --git a/htdocs/index.html b/htdocs/index.html index d0a4e9a..3219552 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -134,16 +134,6 @@ Any Tag @@ -302,13 +292,6 @@
@@ -356,7 +339,9 @@
-
+
+

+
@@ -465,16 +450,6 @@ Any Tag
diff --git a/htdocs/js/mympd.js b/htdocs/js/mympd.js index 43787fd..d90682c 100644 --- a/htdocs/js/mympd.js +++ b/htdocs/js/mympd.js @@ -198,15 +198,7 @@ function appRoute() { sendAPI({"cmd": "MPD_API_PLAYER_CURRENT_SONG"}, songChange); } else if (app.current.app == 'Queue' ) { - var btns = document.getElementById('searchqueuetag').getElementsByTagName('button'); - var btnsLen = btns.length; - for (var i = 0; i < btnsLen; i++) { - btns[i].classList.remove('active'); - if (btns[i].getAttribute('data-tag') == app.current.filter) { - btns[i].classList.add('active'); - document.getElementById('searchqueuetagdesc').innerText = btns[i].innerText; - } - } + selectTag('searchqueuetag', 'searchqueuetagdesc', app.current.filter); getQueue(); } else if (app.current.app == 'Browse' && app.current.tab == 'Playlists' && app.current.view == 'All') { @@ -226,15 +218,7 @@ function appRoute() { else { sendAPI({"cmd": "MPD_API_DATABASE_TAG_LIST","data": {"offset": app.current.page, "filter": app.current.filter, "tag": app.current.view}}, parseListDBtags); doSetFilterLetter('BrowseDatabaseFilter'); - var btns = document.getElementById('BrowseDatabaseByTagDropdown').getElementsByTagName('button'); - var btnsLen = btns.length; - for (var i = 0; i < btnsLen; i++) { - btns[i].classList.remove('active'); - if (btns[i].getAttribute('data-tag') == app.current.view) { - btns[i].classList.add('active'); - document.getElementById('btnBrowseDatabaseByTag').innerText = btns[i].innerText; - } - } + selectTag('BrowseDatabaseByTagDropdown', 'btnBrowseDatabaseByTag', app.current.view); } } else if (app.current.app == 'Browse' && app.current.tab == 'Filesystem') { @@ -292,16 +276,7 @@ function appRoute() { document.getElementById('SearchList').classList.remove('opacity05'); setPagination(0); } - - var btns = document.getElementById('searchtags').getElementsByTagName('button'); - var btnsLen = btns.length; - for (var i = 0; i < btnsLen; i++) { - btns[i].classList.remove('active'); - if (btns[i].getAttribute('data-tag') == app.current.filter) { - btns[i].classList.add('active'); - document.getElementById('searchtagsdesc').innerText = btns[i].innerText; - } - } + selectTag('searchtags', 'searchtagsdesc', app.current.filter); } else { appGoto("Playback"); @@ -488,13 +463,24 @@ function appInit() { document.getElementById('searchAddAllSongsDropdown').addEventListener('click', function(event) { if (event.target.nodeName == 'BUTTON') { if (event.target.innerText == 'Add all to queue') { - addAllFromSearch(); + addAllFromSearchPlist('queue'); } else if (event.target.innerText == 'Add all to playlist') { showAddToPlaylist('SEARCH'); } } }, false); + + document.getElementById('BrowseDatabaseAddAllSongsDropdown').addEventListener('click', function(event) { + if (event.target.nodeName == 'BUTTON') { + if (event.target.innerText == 'Add all to queue') { + addAllFromBrowseDatabasePlist('queue'); + } + else if (event.target.innerText == 'Add all to playlist') { + showAddToPlaylist('DATABASE'); + } + } + }, false); document.getElementById('searchtags').addEventListener('click', function(event) { if (event.target.nodeName == 'BUTTON') @@ -862,13 +848,17 @@ function parseSettings(obj) { document.getElementsByClassName('mixramp')[0].style.display = 'none'; } - settings=obj.data; + settings = obj.data; settings.mpdstream = 'http://'; if (settings.mpdhost == '127.0.0.1' || settings.mpdhost == 'localhost') settings.mpdstream += window.location.hostname; else settings.mpdstream += settings.mpdhost; settings.mpdstream += ':' + settings.streamport + '/'; + + addTagList('BrowseDatabaseByTagDropdown', false); + addTagList('searchqueuetag', true); + addTagList('searchtags', true); } function getSettings() { @@ -1242,6 +1232,7 @@ function parseListDBtags(obj) { document.getElementById('btnBrowseDatabaseTag').parentNode.classList.remove('hide'); document.getElementById('BrowseDatabaseAddAllSongs').parentNode.parentNode.classList.remove('hide'); document.getElementById('btnBrowseDatabaseTag').innerHTML = '« ' + app.current.view; + document.getElementById('BrowseDatabaseAlbumListCaption').innerText = obj.searchtagtype + ': ' + obj.searchstr; var nrItems = obj.data.length; if (nrItems == 1 && obj.data[0].value == '') nrItems = 0; @@ -1259,7 +1250,7 @@ function parseListDBtags(obj) { card.innerHTML = '
' + ' ' + '
' + - '
' + obj.searchstr + '
' + + '
' + '

' + obj.data[i].value + '

' + ' '+ @@ -1285,11 +1276,13 @@ function parseListDBtags(obj) { document.getElementById('btnBrowseDatabaseByTag').parentNode.classList.remove('hide'); document.getElementById('BrowseDatabaseAddAllSongs').parentNode.parentNode.classList.add('hide'); document.getElementById('btnBrowseDatabaseTag').parentNode.classList.add('hide'); + + if (obj.data[0] && obj.data[0].value == '') + obj.data.shift(); var nrItems = obj.data.length; - if (nrItems == 1 && obj.data[0].value == '') - nrItems = 0; var tbody = document.getElementById(app.current.app + app.current.tab + 'TagList').getElementsByTagName('tbody')[0]; var tr = tbody.getElementsByTagName('tr'); + var skipped = 0; for (var i = 0; i < nrItems; i++) { var uri = encodeURI(obj.data[i].value); if (tr[i]) @@ -1333,6 +1326,7 @@ function parseListTitles(obj) { imga.setAttribute('data-uri', encodeURI(obj.data[0].uri.replace(/\/[^\/]+$/, ''))); imga.setAttribute('data-name', obj.album); imga.setAttribute('data-type', 'dir'); + document.getElementById('albumartist' + id).innerText = obj.albumartist; var titleList = ''; var nrItems = obj.data.length; @@ -1622,10 +1616,12 @@ function addToPlaylist() { } } if (plist != '') { - if (uri != 'SEARCH') - sendAPI({"cmd": "MPD_API_PLAYLIST_ADD_TRACK", "data": {"uri": uri, "plist": plist}}); + if (uri == 'SEARCH') + addAllFromSearchPlist(plist); + else if (uri == 'DATABASE') + addAllFromBrowseDatabasePlist(plist); else - addAllFromSearchPlist(plist); + sendAPI({"cmd": "MPD_API_PLAYLIST_ADD_TRACK", "data": {"uri": uri, "plist": plist}}); modalAddToPlaylist.hide(); } else { @@ -1950,13 +1946,6 @@ function addAllFromBrowseFilesystem() { showNotification('Added all songs', '', '', 'success'); } -function addAllFromSearch() { - if (app.current.search.length >= 2) { - sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": {"plist": "queue", "filter": app.current.filter, "searchstr": app.current.search, "offset": 0}}); - showNotification('Added '+ parseInt(document.getElementById('panel-heading-search').innerText) +' songs from search', '', '', 'success'); - } -} - function addAllFromSearchPlist(plist) { if (app.current.search.length >= 2) { sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": {"plist": plist, "filter": app.current.filter, "searchstr": app.current.search, "offset": 0}}); @@ -1964,6 +1953,13 @@ function addAllFromSearchPlist(plist) { } } +function addAllFromBrowseDatabasePlist(plist) { + if (app.current.search.length >= 2) { + sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": {"plist": plist, "filter": app.current.view, "searchstr": app.current.search, "offset": 0}}); + showNotification('Added songs from database selection to ' + plist, '', '', 'success'); + } +} + function scrollTo(pos) { document.body.scrollTop = pos; // For Safari document.documentElement.scrollTop = pos; // For Chrome, Firefox, IE and Opera @@ -2144,6 +2140,31 @@ function addFilterLetter(x) { }, false); } +function selectTag(btnsEl, desc, setTo) { + var btns = document.getElementById(btnsEl); + var aBtn = btns.querySelector('.active') + if (aBtn) + aBtn.classList.remove('active'); + aBtn = btns.querySelector('[data-tag=' + setTo + ']'); + if (aBtn) { + aBtn.classList.add('active'); + document.getElementById(desc).innerText = aBtn.innerText; + } +} + +function addTagList(x, any) { + var tagList = ''; + if (any == true) + tagList += ''; + for (var key in settings.tags) { + if (settings.tags[key] == true && key != 'Track') { + tagList += ''; + } + } + var tagListEl = document.getElementById(x); + tagListEl.innerHTML = tagList; +} + function gotoTagList() { appGoto(app.current.app, app.current.tab, app.current.view, '0/-/'); } @@ -2170,7 +2191,7 @@ function beautifyDuration(x) { } function genId(x) { - return 'id' + x.replace(/[^\w]/g, ''); + return 'id' + x.replace(/[^\w\-\_]/g, ''); } //Init app diff --git a/src/mpd_client.c b/src/mpd_client.c index 100d5be..b44ee22 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -636,7 +636,7 @@ void mympd_mpd_features() { if (mpd.tag_artist == false) printf("WARNING: Artist tag not enabled in mpd\n"); if (mpd.tag_album_artist == false) - printf("WARNING: Albumartist tag not enabled in mpd\n"); + printf("WARNING: AlbumArtist tag not enabled in mpd\n"); if (mpd.tag_title == false) printf("WARNING: Title tag not enabled in mpd\n"); if (mpd.tag_track == false) @@ -868,6 +868,8 @@ char* mympd_get_tag(struct mpd_song const *song, enum mpd_tag_type tag) { if (str == NULL) { if (tag == MPD_TAG_TITLE) str = basename((char *)mpd_song_get_uri(song)); + else if (tag == MPD_TAG_ALBUM_ARTIST) + str = (char *)mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); else str = "-"; } @@ -1419,6 +1421,7 @@ int mympd_put_songs_in_album(char *buffer, char *album, char *search, char *tag) unsigned long entities_returned = 0; int len; char cover[500]; + char *albumartist; struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE); if (mpd_search_db_songs(mpd.conn, true) == false) @@ -1440,9 +1443,10 @@ int mympd_put_songs_in_album(char *buffer, char *album, char *search, char *tag) if (entity_count <= MAX_ELEMENTS_PER_PAGE) { if (entities_returned ++) len += json_printf(&out, ", "); - else + else { mympd_get_cover(mpd_song_get_uri(song), cover, 500); - + albumartist = strdup(mympd_get_tag(song, MPD_TAG_ALBUM_ARTIST)); + } len += json_printf(&out, "{type: song, uri: %Q, duration: %d, title: %Q, track: %Q}", mpd_song_get_uri(song), mpd_song_get_duration(song), @@ -1453,15 +1457,17 @@ int mympd_put_songs_in_album(char *buffer, char *album, char *search, char *tag) mpd_song_free(song); } - len += json_printf(&out, "], totalEntities: %d, returnedEntities: %d, album: %Q, search: %Q, tag: %Q, cover: %Q}", + len += json_printf(&out, "], totalEntities: %d, returnedEntities: %d, album: %Q, search: %Q, tag: %Q, cover: %Q, albumartist: %Q}", entity_count, entities_returned, album, search, tag, - cover + cover, + albumartist ); } + free(albumartist); if (len > MAX_SIZE) printf("Buffer truncated\n");