Better YouTube importing, and auth-form prettier

This commit is contained in:
Kasper Rynning-Tønnesen
2018-03-22 15:53:55 +01:00
parent f518a06ed2
commit 9ccdcf7aec
5 changed files with 100 additions and 144 deletions

View File

@@ -142,6 +142,7 @@ function start_auth() {
$("#player_overlay").removeClass("hide");
$("#player_overlay").css("display", "block");
$("#user_password").modal("open");
$("#user-pass-input").focus();
//Crypt.remove_userpass(chan.toLowerCase());
before_toast();
Materialize.toast("That is not the correct password, try again..", 4000);
@@ -632,6 +633,11 @@ function toast(msg) {
break;
case "addedplaylist":
if(embed) return;
if(Search.submitYouTubeError) {
Materialize.toast("Added most of your playlist, but something was wrong. Check the playlist..", 4000, "red lighten connect_error");
Search.submitYouTubeError = false;
return;
}
msg=Helper.rnd(["I added the playlist", "Your playlist has been added", "Yay, many more songs!", "Thats a cool playlist!", "I added all the songs for you", "I see you like adding songs.."]);
document.getElementById("import").disabled = false;
$("#playlist_loader").addClass("hide");

View File

@@ -17,43 +17,43 @@ var List = {
{
case "list":
//if(full_playlist == undefined || !offline){
if((!offline || (offline && !msg.shuffled)) && !(offline && prev_chan_list == chan)){
prev_chan_list = chan;
List.populate_list(msg.playlist);
if(full_playlist.length > 0) {
Player.sendNext({title: full_playlist[0].title, videoId: full_playlist[0].id});
//if(full_playlist == undefined || !offline){
if((!offline || (offline && !msg.shuffled)) && !(offline && prev_chan_list == chan)){
prev_chan_list = chan;
List.populate_list(msg.playlist);
if(full_playlist.length > 0) {
Player.sendNext({title: full_playlist[0].title, videoId: full_playlist[0].id});
}
} else if(offline && prev_chan_list == chan && full_playlist != undefined && !msg.shuffled){
List.populate_list(full_playlist, true);
if(full_playlist.length > 0) {
Player.sendNext({title: full_playlist[0].title, videoId: full_playlist[0].id});
}
}
} else if(offline && prev_chan_list == chan && full_playlist != undefined && !msg.shuffled){
List.populate_list(full_playlist, true);
if(full_playlist.length > 0) {
Player.sendNext({title: full_playlist[0].title, videoId: full_playlist[0].id});
}
}
break;
break;
case "added":
List.added_song(msg.value);
if(full_playlist.length > 0) {
Player.sendNext({title: full_playlist[0].title, videoId: full_playlist[0].id});
}
found_array = [];
found_array_index = 0;
break;
case "deleted":
List.deleted_song(msg.value, msg.removed);
found_array = [];
found_array_index = 0;
break;
case "vote":
if(!offline){
List.voted_song(msg.value, msg.time);
List.added_song(msg.value);
if(full_playlist.length > 0) {
Player.sendNext({title: full_playlist[0].title, videoId: full_playlist[0].id});
}
}
found_array = [];
found_array_index = 0;
break;
found_array = [];
found_array_index = 0;
break;
case "deleted":
List.deleted_song(msg.value, msg.removed);
found_array = [];
found_array_index = 0;
break;
case "vote":
if(!offline){
List.voted_song(msg.value, msg.time);
if(full_playlist.length > 0) {
Player.sendNext({title: full_playlist[0].title, videoId: full_playlist[0].id});
}
}
found_array = [];
found_array_index = 0;
break;
case "song_change":
if((offline && msg.offline_change) || !offline) {
if(window.location.pathname != "/") List.song_change(msg.time, msg.remove);

View File

@@ -2,6 +2,10 @@ var Search = {
submitArray: [],
submitArrayExpected: null,
submitYouTubeArrayIds: [],
submitYouTubeArray: [],
submitYouTubeExpected: 0,
submitYouTubeError: false,
showSearch: function(){
$("#search-wrapper").toggleClass("hide");
@@ -313,7 +317,7 @@ var Search = {
if(pageToken !== undefined)
token = "&pageToken="+pageToken;
playlist_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=49&key="+api_key+"&playlistId="+pId+token;
if(youtube_authenticated){
if(youtube_authenticated) {
datatype = "html";
headers = {
'Content-Type': 'application/json',
@@ -329,8 +333,7 @@ var Search = {
dataType: datatype,
//dataType:"jsonp",
headers: headers,
success: function(response)
{
success: function(response) {
if(response.error){
if(response.error.errors[0].reason == "playlistItemsNotAccessible"){
var nonce = Helper.randomString(29);
@@ -365,15 +368,26 @@ var Search = {
} else {
var ids="";
var this_length = 0;
if(typeof(response) == "string") response = $.parseJSON(response);
//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+",";
Search.submitYouTubeArrayIds.push(data.contentDetails.videoId);
this_length += 1;
Search.submitYouTubeExpected += 1;
});
Search.addVideos(ids, true);
if(response.nextPageToken) Search.importPlaylist(pId, response.nextPageToken);
if(response.nextPageToken) {
console.log(Search.submitYouTubeExpected);
//Search.addVideos(ids, true, 0, false, this_length);
Search.importPlaylist(pId, response.nextPageToken);
} else {
Search.addVideos(Search.submitYouTubeArrayIds);
//Search.addVideos(ids, true, Search.submitYouTubeExpected, true, this_length);
//Search.submitYouTubeExpected = 0;
}
document.getElementById("import").value = "";
}
}
@@ -407,9 +421,20 @@ var Search = {
});
},
addVideos: function(ids, playlist){
addVideos: function(ids){
var more = false;
var next_ids = [];
var this_ids = [];
var request_url="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=***REMOVED***&id=";
request_url += ids;
for(var i = 0; i < ids.length; i++) {
if(i > 48) {
more = true;
next_ids = ids.slice(i, ids.length);
break;
}
request_url += ids[i] + ",";
this_ids.push(ids[i]);
}
$.ajax({
type: "POST",
@@ -417,23 +442,24 @@ var Search = {
dataType:"jsonp",
success: function(response){
var x = 0;
var to_add = [];
$.each(response.items, function(i,song)
{
if(response.error) {
Search.submitYouTubeError = true;
}
$.each(response.items, function(i,song) {
var duration=Search.durationToSeconds(song.contentDetails.duration);
if(!longsongs || duration<720){
enc_title= song.snippet.title;//encodeURIComponent(song.snippet.title);
//Search.submit(song.id, enc_title, duration, playlist, i);
x += 1;
to_add.push({id: song.id, title: enc_title, duration: duration, playlist: playlist});
Search.submitYouTubeArray.push({id: song.id, title: enc_title, duration: duration});
}
});
socket.emit("addPlaylist", {channel: chan.toLowerCase(), songs: to_add});
/*
$.each(to_add, function(i, item){
Search.submit(item.id, item.enc_title, item.duration, item.playlist, i, x, 0, item.duration);
});
*/
if(more) Search.addVideos(next_ids);
else {
socket.emit("addPlaylist", {channel: chan.toLowerCase(), songs: Search.submitYouTubeArray});
Search.submitYouTubeArray = [];
Search.submitYouTubeExpected = 0;
}
}
});
},
@@ -451,14 +477,14 @@ var Search = {
}
});
if(found_array.length == 0){
List.channel_function({type: "added", start: start, end: end, value: {added: (new Date).getTime()/1000, guids: [1], id: id, title: title, duration: duration, playlist: false, now_playing: false, votes: 1}});
List.channel_function({type: "added", start: start, end: end, value: {added: (new Date).getTime()/1000, guids: [1], id: id, title: title, duration: duration, now_playing: false, votes: 1}});
} else {
List.vote(id, "pos");
}
} else {
/*var u = Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true);
if(u == undefined) u = "";*/
emit("add", {id: id, start: start, end: end, title: title, list: chan.toLowerCase(), duration: duration, playlist: playlist, num: num, total: full_num});
emit("add", {id: id, start: start, end: end, title: title, list: chan.toLowerCase(), duration: duration});
}//[id, decodeURIComponent(title), adminpass, duration, playlist]);
},