Adding playlists works even better now

This commit is contained in:
Kasper Rynning-Tønnesen
2016-05-02 14:30:52 +02:00
parent 9a519d4d4b
commit 3fdbeb4977
5 changed files with 3081 additions and 36 deletions

File diff suppressed because one or more lines are too long

3034
static/dist/main.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -31,6 +31,33 @@ var List = {
} }
}, },
insertAtBeginning: function(song_info, transition) {
var add = List.generateSong(song_info, transition, false, true, false);
$("#wrapper").append(add);
},
insertAtIndex: function(song_info, transition) {
var i = List.getIndexOfSong(song_info.id);
if(!song_info.now_playing){
var add = List.generateSong(song_info, transition, false, true, false);
if(i == 0) {
$("#wrapper").prepend(add);
} else {
$("#wrapper > div:nth-child(" + (i) + ")").after(add);
}
}
var added = $("#wrapper").children()[i];
if(transition)
{
setTimeout(function(){
$(added).css("height", 66);
},5);
}
},
populate_list: function(msg) populate_list: function(msg)
{ {
if(list_html == undefined) list_html = $("#list-song-html").html(); if(list_html == undefined) list_html = $("#list-song-html").html();
@@ -63,18 +90,20 @@ var List = {
$("#settings").css("visibility", "visible"); $("#settings").css("visibility", "visible");
$("#settings").css("opacity", "1"); $("#settings").css("opacity", "1");
$("#wrapper").css("opacity", "1"); $("#wrapper").css("opacity", "1");
}, },
added_song: function(added){ added_song: function(added){
now_playing = full_playlist.pop();
full_playlist.push(added); full_playlist.push(added);
List.sortList(); List.sortList();
full_playlist.push(now_playing);
$("#suggested-"+added.id).remove(); $("#suggested-"+added.id).remove();
if(List.empty){ if(List.empty){
$("#empty-channel-message").remove();
List.empty = false; List.empty = false;
} }
$("#empty-channel-message").remove();
List.insertAtIndex(added, true); List.insertAtIndex(added, true);
}, },
deleted_song: function(deleted){ deleted_song: function(deleted){
@@ -130,7 +159,10 @@ var List = {
full_playlist.push(full_playlist.shift()); full_playlist.push(full_playlist.shift());
if(!List.empty) if(!List.empty)
$("#wrapper").children()[0].remove(); $("#wrapper").children()[0].remove();
if($("#wrapper").children().length == 0) {
List.empty = true;
$("#wrapper").append("<span id='empty-channel-message'>The playlist is empty.</span>");
}
List.insertAtIndex(full_playlist[length-1], false); List.insertAtIndex(full_playlist[length-1], false);
document.getElementById('wrapper').scrollTop += 1; document.getElementById('wrapper').scrollTop += 1;
document.getElementById('wrapper').scrollTop += -1; document.getElementById('wrapper').scrollTop += -1;
@@ -202,24 +234,6 @@ var List = {
} }
}, },
insertAtIndex: function(song_info, transition) {
i = List.getIndexOfSong(song_info.id);
if(i === 0)
$("#wrapper").prepend(List.generateSong(song_info, transition, false, true, false));
else
$("#wrapper > div:nth-child(" + (i) + ")").after(List.generateSong(song_info, transition, false, true, false));
var added = $("#wrapper").children()[i];
if(transition)
{
setTimeout(function(){
$(added).css("height", 66);
},5);
}
},
generateSong: function(song_info, transition, lazy, list, user) generateSong: function(song_info, transition, lazy, list, user)
{ {
var video_id = song_info.id; var video_id = song_info.id;

View File

@@ -40,11 +40,10 @@ var Player = {
if(mobile_beginning && window.mobilecheck() && seekTo == 0) if(mobile_beginning && window.mobilecheck() && seekTo == 0)
seekTo = 1; seekTo = 1;
if(full_playlist[0].id == video_id){
List.song_change(full_playlist[0].added);
}
try{ try{
if(full_playlist[0].id == video_id){
List.song_change(full_playlist[0].added);
}
Suggestions.fetchYoutubeSuggests(video_id); Suggestions.fetchYoutubeSuggests(video_id);
}catch(e){} }catch(e){}
Player.getTitle(song_title, viewers); Player.getTitle(song_title, viewers);

View File

@@ -146,21 +146,22 @@ var Search = {
success: function(response) success: function(response)
{ {
var ids=""; var ids="";
Search.addVideos(response.items[0].contentDetails.videoId); //Search.addVideos(response.items[0].contentDetails.videoId);
//response.items.shift();
$.each(response.items, function(i,data) $.each(response.items, function(i,data)
{ {
ids+=data.contentDetails.videoId+","; ids+=data.contentDetails.videoId+",";
}); });
Search.addVideos(ids); Search.addVideos(ids, true);
if(response.nextPageToken) Search.importPlaylist(pId, response.nextPageToken); if(response.nextPageToken) Search.importPlaylist(pId, response.nextPageToken);
document.getElementById("import").value = ""; document.getElementById("import").value = "";
} }
}); });
}, },
addVideos: function(ids){ addVideos: function(ids, playlist){
var request_url="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=***REMOVED***&id="; var request_url="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=***REMOVED***&id=";
request_url += ids; request_url += ids;
$.ajax({ $.ajax({
type: "POST", type: "POST",
@@ -172,7 +173,7 @@ var Search = {
var duration=Search.durationToSeconds(song.contentDetails.duration); var duration=Search.durationToSeconds(song.contentDetails.duration);
if(!longsongs || duration<720){ if(!longsongs || duration<720){
enc_title= song.snippet.title;//encodeURIComponent(song.snippet.title); enc_title= song.snippet.title;//encodeURIComponent(song.snippet.title);
Search.submit(song.id, enc_title, duration); Search.submit(song.id, enc_title, duration, playlist);
} }
}); });
@@ -180,8 +181,9 @@ var Search = {
}); });
}, },
submit: function(id,title,duration){ submit: function(id,title,duration, playlist){
socket.emit("add", [id, decodeURIComponent(title), adminpass, duration]); socket.emit("add", {id: id, title: decodeURIComponent(title), adminpass: adminpass, list: chan.toLowerCase(), duration: duration, playlist: playlist});
//[id, decodeURIComponent(title), adminpass, duration, playlist]);
}, },
durationToSeconds: function(duration) { durationToSeconds: function(duration) {