Skip to content
Snippets Groups Projects
Commit 422b2073 authored by ale's avatar ale
Browse files

load the song metadata from the backend, instead of scraping the playlist HTML

parent 834a764b
No related branches found
No related tags found
No related merge requests found
...@@ -184,6 +184,21 @@ djr.Backend.prototype.streamPlaylist = function(uuid, streaming, callback, ctx) ...@@ -184,6 +184,21 @@ djr.Backend.prototype.streamPlaylist = function(uuid, streaming, callback, ctx)
}); });
}; };
/**
* Return song information.
*
* @param {string} song SHA1 of the song
*/
djr.Backend.prototype.getSongInfo = function(song, callback) {
$.ajax({url: '/json/song/' + song,
dataType: 'json',
type: 'GET',
success: function(data, status, jqxhr) {
callback(data);
}
});
};
/** /**
* Return the HTML fragment to render a list of songs. * Return the HTML fragment to render a list of songs.
* *
......
...@@ -242,3 +242,13 @@ djr.generateRandomId = function() { ...@@ -242,3 +242,13 @@ djr.generateRandomId = function() {
return uuid.join(''); return uuid.join('');
}; };
// Add the escapeHTML() function to the String base class.
String.prototype.escapeHTML = function () {
return(
this.replace(/&/g,'&').
replace(/>/g,'>').
replace(/</g,'&lt;').
replace(/"/g,'&quot;')
);
};
...@@ -331,21 +331,23 @@ djr.Player.prototype.play = function(song) { ...@@ -331,21 +331,23 @@ djr.Player.prototype.play = function(song) {
this.player.jPlayer('setMedia', this.player.jPlayer('setMedia',
{mp3: url}).jPlayer('play'); {mp3: url}).jPlayer('play');
// Load song info in the player UI. We cheat by stealing the data // Load song info in the player UI.
// from the existing <div> instead than from the server. this.backend.getSongInfo(song, function(song_info) {
var artist = $('#song_' + song + ' .artist').text(); // Show song info.
var album = $('#song_' + song + ' .album').text();
$('#songInfoDiv').html( $('#songInfoDiv').html(
$('#song_' + song + ' .title').text() + '<br>' song_info.title.escapeHTML() + '<br>'
+ artist + '<br>' + song_info.artist.escapeHTML() + '<br>'
+ '<small>' + album + '</small>' + '<small>' + song_info.album.escapeHTML() + '</small>'
); );
// Load album art full-screen. // Load album art full-screen.
var album_art_url = '/album_image/' + escape(artist) + '/' + escape(album); var album_art_url = ('/album_image/'
+ escape(song_info.artist)
+ '/' + escape(song_info.album));
$('#albumart_fs').attr('src', album_art_url); $('#albumart_fs').attr('src', album_art_url);
$('#albumart_fs').fullBg(); $('#albumart_fs').fullBg();
$('#albumart_fs').show(); $('#albumart_fs').show();
});
// Report the new song being played. // Report the new song being played.
this.backend.nowPlaying(song, this.old_songs); this.backend.nowPlaying(song, this.old_songs);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment