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

hopefully fix addChunk / 2

parent 941b1742
Branches
No related tags found
No related merge requests found
...@@ -109,22 +109,27 @@ djr.Playlist.prototype.allSongs = function() { ...@@ -109,22 +109,27 @@ djr.Playlist.prototype.allSongs = function() {
}; };
// Add a new chunk (only adds unique songs). // Add a new chunk (only adds unique songs).
// Returns the chunk ID. // Returns the chunk ID, or -1 if no songs were added.
djr.Playlist.prototype.addChunk = function(playlist_chunk) { djr.Playlist.prototype.addChunk = function(playlist_chunk) {
djr.debug('adding chunk to playlist ' + this.uuid); djr.debug('adding chunk to playlist ' + this.uuid);
chunk_id = this.next_chunk_id++; chunk_id = this.next_chunk_id++;
var songs = []; var songs = [];
var playlist = this; for (i = 0; i < playlist_chunk.songs.length; i++) {
$.each(playlist_chunk.songs, function(idx, song) { if (this.song_map[song]) {
if (playlist.song_map[song]) { continue;
return;
} }
songs.push(song); songs.push(playlist_chunk.songs[i]);
playlist.song_map[song] = chunk_id; this.song_map[playlist_chunk.songs[i]] = chunk_id;
}); }
if (songs.length == 0) {
return -1;
} else {
this.chunk_map[chunk_id] = new djr.PlaylistChunk(songs); this.chunk_map[chunk_id] = new djr.PlaylistChunk(songs);
this.chunks.push(chunk_id); this.chunks.push(chunk_id);
return chunk_id; return chunk_id;
}
}; };
// Remove a chunk (by ID). // Remove a chunk (by ID).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment