function loadArtists(id, refresh) { console.log("LOAD ARTISTS"); if (refresh) { $('#ArtistContainer').empty(); } var url; if (id == "all") { url = baseURL + '/getIndexes.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp'; } else if (id) { url = baseURL + '/getIndexes.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp&musicFolderId=' + id; } else { url = baseURL + '/getIndexes.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp'; } console.log(url); var content = $('#ArtistContainer').html(); if (content === "") { // Load Artist List $.ajax({ url: url, method: 'GET', dataType: 'jsonp', timeout: 10000, done: function() { console.log("DONE!"); }, error: function() { console.log("ERROR!"); }, success: function (data) { console.log("SUCCESS"); if (data["subsonic-response"].status === 'ok') { var indexlist, indexname; // There is a bug in the API that doesn't return a JSON array for one artist var indexes = []; if (data["subsonic-response"].indexes.index.length > 0) { indexes = data["subsonic-response"].indexes.index; } else { indexes[0] = data["subsonic-response"].indexes.index; } $.each(indexes, function (i, index) { if (index.name === '#') { indexname = '0-9'; } else { indexname = index.name; } $('
  • ' + indexname + '
  • ').appendTo("#ArtistContainer"); indexlist += '
  • ' + indexname + '
  • '; var artists = []; if (index.artist.length > 0) { artists = index.artist; } else { artists[0] = index.artist; } $.each(artists, function (i, artist) { if (artist.name !== undefined) { var html = ""; html += '
  • '; html += '' + artist.name + ''; html += '
  • '; $(html).appendTo("#ArtistContainer"); } }); }); //$(indexlist).appendTo("#IndexList"); $("#BottomIndex").empty(); $(indexlist).appendTo("#BottomIndex"); } else { var error = data["subsonic-response"].status; var errorcode = data["subsonic-response"].error.code; var errormsg = data["subsonic-response"].error.message; alert('Status: ' + error + ', Code: ' + errorcode + ', Message: ' + errormsg); //var errorhtml = '
  • ' + error + '
  • '; //$(errorhtml).appendTo("#IndexList"); } } }); } } function getMusicFolders() { $.ajax({ url: baseURL + '/getMusicFolders.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp', method: 'GET', dataType: 'jsonp', timeout: 10000, beforeSend: function (req) { req.setRequestHeader('Authorization', auth); }, success: function (data) { if (data["subsonic-response"].musicFolders.musicFolder !== undefined) { // There is a bug in the API that doesn't return a JSON array for one artist var folders = []; if (data["subsonic-response"].musicFolders.musicFolder.length > 0) { folders = data["subsonic-response"].musicFolders.musicFolder; } else { folders[0] = data["subsonic-response"].musicFolders.musicFolder; } var savedMusicFolder = $.cookie('MusicFolders'); var options = []; options.push(''); $.each(folders, function (i, folder) { if (savedMusicFolder == folder.id) { options.push(''); } else { options.push(''); } }); $('#MusicFolders').html(options.join('')); } else { } } }); } function getAlbums(id, action, appendto) { $.ajax({ url: baseURL + '/getMusicDirectory.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp&id=' + id, method: 'GET', dataType: 'jsonp', timeout: 10000, beforeSend: function (req) { req.setRequestHeader('Authorization', auth); }, success: function (data) { if (action === '') { $('#AlbumRows').empty(); } if (action === 'autoplay') { $('#CurrentPlaylistContainer tbody').empty(); } if (data["subsonic-response"].directory.child !== undefined) { // There is a bug in the API that doesn't return a JSON array for one artist var children = []; if (data["subsonic-response"].directory.child.length > 0) { children = data["subsonic-response"].directory.child; } else { children[0] = data["subsonic-response"].directory.child; } var rowcolor; var albumhtml; var isDir; var header; $.each(children, function (i, child) { if (i % 2 === 0) { rowcolor = 'even'; } else { rowcolor = 'odd'; } isDir = child.isDir; if (isDir === true) { albumhtml = generateAlbumHTML(rowcolor, child.id, child.parent, child.coverArt, child.title, child.artist, child.userRating); } else { var track; if (child.track === undefined) { track = " "; } else { track = child.track; } var time = secondsToTime(child.duration); albumhtml = generateSongHTML(rowcolor, child.id, child.parent, track, child.title, child.artist, child.album, child.coverArt, child.userRating, time['m'], time['s']); } $(albumhtml).appendTo(appendto); }); if (appendto === '#CurrentPlaylistContainer') { updateMessage(children.length + ' Song(s) Added'); } if (appendto === '#AlbumRows' && isDir === true) { header = generateAlbumHeaderHTML(); } if (appendto === '#AlbumRows' && isDir === false) { header = generateSongHeaderHTML(); } $("#AlbumHeader").html(header); if (action === 'autoplay') { autoPlay(); } } } }); } function getAlbumListBy(id) { var size; if ($.cookie('AutoAlbumSize') === null) { size = 15; } else { size = $.cookie('AutoAlbumSize'); } $.ajax({ url: baseURL + '/getAlbumList.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp&size=' + size + '&type=' + id, method: 'GET', dataType: 'jsonp', timeout: 10000, beforeSend: function (req) { req.setRequestHeader('Authorization', auth); }, success: function (data) { if (data["subsonic-response"].albumList.album !== undefined) { $("#AlbumRows").empty(); var header = generateAlbumHeaderHTML(); $("#AlbumHeader").html(header); // There is a bug in the API that doesn't return a JSON array for one artist var albums = []; if (data["subsonic-response"].albumList.album.length > 0) { albums = data["subsonic-response"].albumList.album; } else { albums[0] = data["subsonic-response"].albumList.album; } var rowcolor; var html; $.each(albums, function (i, album) { if (i % 2 === 0) { rowcolor = 'even'; } else { rowcolor = 'odd'; } // Only show albums, not songs (Rated songs will also be returned in API call, trying to display them will break Back button, disabled for now) var albumhtml; if (album.isDir === true) { albumhtml = generateAlbumHTML(rowcolor, album.id, album.parent, album.coverArt, album.title, album.artist, album.userRating); } $(albumhtml).appendTo("#AlbumRows"); }); } else { $('#AlbumRows').empty(); } } }); } function getRandomSongList(action, appendto) { var size; if ($.cookie('AutoPlaylistSize') === null) { size = 25; } else { size = $.cookie('AutoPlaylistSize'); } $.ajax({ url: baseURL + '/getRandomSongs.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp&size=' + size, method: 'GET', dataType: 'jsonp', timeout: 10000, beforeSend: function (req) { req.setRequestHeader('Authorization', auth); }, success: function (data) { if (data["subsonic-response"].randomSongs.song !== undefined) { if (appendto === '#TrackContainer') { $("#TrackContainer").empty(); } if (action === 'autoplay') { $(appendto).empty(); } // There is a bug in the API that doesn't return a JSON array for one artist var items = []; if (data["subsonic-response"].randomSongs.song.length > 0) { items = data["subsonic-response"].randomSongs.song; } else { items[0] = data["subsonic-response"].randomSongs.song; } var rowcolor; var html; $.each(items, function (i, item) { if (i % 2 === 0) { rowcolor = 'even'; } else { rowcolor = 'odd'; } var track; if (item.track === undefined) { track = " "; } else { track = item.track; } var time = secondsToTime(item.duration); html = generateSongHTML(rowcolor, item.id, item.parent, track, item.title, item.artist, item.album, item.coverArt, item.userRating, time['m'], time['s']); $(html).appendTo(appendto); }); if (appendto === '#CurrentPlaylistContainer') { updateMessage(items.length + ' Song(s) Added'); } if (action === 'autoplay') { autoPlay(); } } else { $(appendto).empty(); } } }); }