mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Soundcloud-player + soundcloud-search added
This commit is contained in:
@@ -17,28 +17,29 @@ var Search = {
|
||||
//$("#results").empty();
|
||||
if(document.querySelector("#search-btn i").innerText == "close") {
|
||||
document.querySelector("body").setAttribute("style", "overflow-y:auto")
|
||||
/*$("#results").slideUp({
|
||||
complete: function() {
|
||||
$("#results").empty();
|
||||
}
|
||||
});*/
|
||||
|
||||
document.getElementById("results").innerHTML = "";
|
||||
document.getElementById("results_soundcloud").innerHTML = "";
|
||||
Helper.css(".search_results", "display", "none");
|
||||
Helper.css(".results-tabs", "display", "none");
|
||||
document.querySelector(".search_input").value = "";
|
||||
document.querySelector("#search-btn i").innerText = "search";
|
||||
} else {
|
||||
document.querySelector("#search-btn i").innerText = "close";
|
||||
Helper.css(".search_results", "display", "block");
|
||||
}
|
||||
document.querySelector("#search").focus();
|
||||
|
||||
},
|
||||
|
||||
search: function(search_input, retried, related, pagination){
|
||||
|
||||
if(result_html === undefined || empty_results_html === undefined) {
|
||||
result_html = document.getElementById("temp-results-container");
|
||||
empty_results_html = Helper.html("#empty-results-container");
|
||||
}
|
||||
if(!pagination && document.querySelectorAll("#inner-results").length == 0) {
|
||||
Helper.setHtml(".search_results", '');
|
||||
Helper.setHtml("#results", '');
|
||||
}
|
||||
if(search_input !== ""){
|
||||
searching = true;
|
||||
@@ -55,7 +56,8 @@ var Search = {
|
||||
|
||||
|
||||
Helper.addClass(".search_loader_spinner", "active");
|
||||
Helper.removeClass("#results", "hide");
|
||||
Helper.removeClass(".search_results", "hide");
|
||||
Helper.css(".results-tabs", "display", "none");
|
||||
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
@@ -63,11 +65,13 @@ var Search = {
|
||||
dataType: "jsonp",
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
var output = "";
|
||||
var nextPageToken = response.nextPageToken;
|
||||
var prevPageToken = response.prevPageToken;
|
||||
if(response.items.length === 0) {
|
||||
document.getElementById("results").innerHTML = "";
|
||||
Helper.css("#results", "display", "block");
|
||||
Helper.css(".results-tabs", "display", "block");
|
||||
//$("<div style='display:none;' id='inner-results' class='empty-inner-results'>"+empty_results_html+"</div>").appendTo($("#results")).show("blind", 83.33);
|
||||
document.getElementById("results").insertAdjacentHTML("beforeend", "<div style='display:block;' id='inner-results' style='height:calc(100vh - 64px);' class='empty-inner-results'>"+empty_results_html+"</div>");
|
||||
Helper.removeClass(".search_loader_spinner", "active");
|
||||
@@ -88,18 +92,17 @@ var Search = {
|
||||
pre_result.innerHTML = result_html.outerHTML;
|
||||
|
||||
//$("#results").append(result_html);
|
||||
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
var song = response.items[i];
|
||||
var duration=song.contentDetails.duration;
|
||||
secs=Search.durationToSeconds(duration);
|
||||
var secs=Search.durationToSeconds(duration);
|
||||
var _temp_duration = Helper.secondsToOther(secs);
|
||||
if(!longsongs || secs<720){
|
||||
title=song.snippet.title;
|
||||
enc_title=title;//encodeURIComponent(title).replace(/'/g, "\\\'");
|
||||
id=song.id;
|
||||
var title=song.snippet.title;
|
||||
var enc_title=title;//encodeURIComponent(title).replace(/'/g, "\\\'");
|
||||
var id=song.id;
|
||||
duration = duration.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s");
|
||||
thumb=song.snippet.thumbnails.medium.url;
|
||||
var thumb=song.snippet.thumbnails.medium.url;
|
||||
|
||||
//$("#results").append(result_html);
|
||||
var songs = pre_result.cloneNode(true);
|
||||
@@ -127,7 +130,7 @@ var Search = {
|
||||
if(document.querySelectorAll("#inner-results").length == 0) {
|
||||
fresh = true;
|
||||
}
|
||||
document.getElementsByClassName("search_results")[0].innerHTML = "";
|
||||
document.getElementById("results").innerHTML = "";
|
||||
if(output.length > 0) {
|
||||
//$(window).scrollTop(0);
|
||||
if(!pagination && fresh) {
|
||||
@@ -158,6 +161,7 @@ var Search = {
|
||||
|
||||
Helper.removeClass(".search_loader_spinner", "active");
|
||||
Helper.css(".search_results", "display", "block");
|
||||
Helper.css(".results-tabs", "display", "block");
|
||||
|
||||
} else if(!retried){
|
||||
Search.search(search_input, true);
|
||||
@@ -179,6 +183,104 @@ var Search = {
|
||||
}
|
||||
},
|
||||
|
||||
soundcloudSearch: function(keyword) {
|
||||
_SC1.get('/tracks', {
|
||||
q: keyword
|
||||
}).then(function(tracks) {
|
||||
|
||||
var pre_result = document.createElement("div");
|
||||
pre_result.innerHTML = result_html.outerHTML;
|
||||
|
||||
//$("#results").append(result_html);
|
||||
var output = "";
|
||||
for(var i = 0; i < tracks.length; i++) {
|
||||
var song = tracks[i];
|
||||
|
||||
var duration=Math.floor(song.duration / 1000);
|
||||
//var secs=Search.durationToSeconds(duration);
|
||||
var secs = duration;
|
||||
var _temp_duration = Helper.secondsToOther(secs);
|
||||
if(!longsongs || secs<720){
|
||||
var title=song.title;
|
||||
var enc_title=title;//encodeURIComponent(title).replace(/'/g, "\\\'");
|
||||
var id=song.permalink_url;
|
||||
//duration = duration.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s");
|
||||
//thumb=song.artwork_url;
|
||||
var thumb = null;
|
||||
if(thumb == null) thumb = song.waveform_url;
|
||||
console.log(song);
|
||||
//$("#results").append(result_html);
|
||||
var songs = pre_result.cloneNode(true);
|
||||
songs.querySelector(".search-title").innerText = title;
|
||||
songs.querySelector(".result_info").innerText = Helper.pad(_temp_duration[0]) + ":" + Helper.pad(_temp_duration[1]);
|
||||
songs.querySelector(".thumb").setAttribute("src", thumb);
|
||||
//songs.querySelector(".add-many").attr("onclick", "submit('"+id+"','"+enc_title+"',"+secs+");");
|
||||
songs.querySelector("#add-many").setAttribute("data-video-id", id);
|
||||
songs.querySelector("#add-many").setAttribute("data-video-title", enc_title);
|
||||
songs.querySelector("#add-many").setAttribute("data-video-length", secs);
|
||||
//$($(songs).querySelector("div")[0]).setAttribute("onclick", "submitAndClose('"+id+"','"+enc_title+"',"+secs+");");
|
||||
songs.querySelector("#temp-results").setAttribute("data-video-id", id);
|
||||
songs.querySelector("#temp-results").setAttribute("data-video-title", enc_title);
|
||||
songs.querySelector("#temp-results").setAttribute("data-video-length", secs);
|
||||
songs.querySelector(".open-externally").setAttribute("href", song.permalink_url);
|
||||
songs.querySelector(".result-end").setAttribute("value", secs);
|
||||
songs.querySelector("#temp-results").setAttribute("data-type-source", "soundcloud");
|
||||
songs.querySelector("#temp-results").setAttribute("data-type-thumbnail", thumb);
|
||||
//$($(songs).querySelector("div")[0]).setAttribute("id", id)
|
||||
//output += undefined;
|
||||
if(songs.innerHTML != undefined && songs.innerHTML != "") {
|
||||
output += songs.innerHTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
var fresh = false;
|
||||
if(document.querySelectorAll("#inner-results").length == 0) {
|
||||
fresh = true;
|
||||
}
|
||||
document.getElementById("results_soundcloud").innerHTML = "";
|
||||
//console.log(output);
|
||||
if(output.length > 0) {
|
||||
//$(window).scrollTop(0);
|
||||
/*if(!pagination && fresh) {
|
||||
//Helper.css(".search_results", "display", "none");
|
||||
}*/
|
||||
//document.getElementById("results_soundcloud").insertAdjacentHTML("beforeend", pagination_buttons_html);
|
||||
//$("<div id='inner-results'>"+output+"</div>").prependTo($("#results"));
|
||||
document.getElementById("results_soundcloud").insertAdjacentHTML("afterbegin", "<div id='inner-results'>"+output+"</div>");
|
||||
if(!pagination && fresh) {
|
||||
//$(".search_results").slideDown();
|
||||
}
|
||||
document.getElementsByTagName("body")[0].setAttribute("style", "overflow-y:hidden !important")
|
||||
|
||||
/*if(nextPageToken) {
|
||||
document.querySelector(".next-results-button").setAttribute("data-pagination", nextPageToken);
|
||||
} else {
|
||||
Helper.addClass(".next-results-button", "disabled");
|
||||
}
|
||||
if(prevPageToken) {
|
||||
document.querySelector(".prev-results-button").setAttribute("data-pagination", prevPageToken);
|
||||
} else {
|
||||
Helper.addClass(".prev-results-button", "disabled");
|
||||
}
|
||||
|
||||
document.querySelector(".pagination-results a").setAttribute("data-original-search", search_input);
|
||||
*/
|
||||
//setTimeout(function(){$(".thumb").lazyload({container: $("#results")});}, 250);
|
||||
|
||||
/*Helper.removeClass(".search_loader_spinner", "active");
|
||||
Helper.css(".search_results", "display", "block");*/
|
||||
|
||||
} /*else if(!retried){
|
||||
Search.search(search_input, true);
|
||||
} else {
|
||||
//$("<div style='display:none;' id='inner-results'>"+empty_results_html+"</div>").appendTo($("#results_soundcloud")).show("blind", 83.33);
|
||||
document.getElementById("results_soundcloud").insertAdjacentHTML("beforeend", "<div style='display:block;' id='inner-results' style='height:calc(100vh - 64px);'>"+empty_results_html+"</div>");
|
||||
Helper.css("#results_soundcloud", "display", "block");
|
||||
Helper.removeClass(".search_loader_spinner", "active");
|
||||
}*/
|
||||
});
|
||||
},
|
||||
|
||||
backgroundSearch: function(title, artist, length, totalNumber, current){
|
||||
var keyword= encodeURIComponent(title + " " + artist);
|
||||
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+api_key+"&videoEmbeddable=true&part=id,snippet&fields=items(id,snippet)&type=video&order=relevance&safeSearch=none&maxResults=10&videoCategoryId=10";
|
||||
@@ -299,112 +401,57 @@ var Search = {
|
||||
if((Search.submitArray.length - 1) == Search.submitArrayExpected) {
|
||||
socket.emit("addPlaylist", {channel: chan.toLowerCase(), songs: Search.submitArray});
|
||||
/*$.each(Search.submitArray, function(i, data){
|
||||
Search.submit(data.id, data.title, data.duration, true, i, Search.submitArray.length - 1, 0, data.duration);
|
||||
});*/
|
||||
document.getElementById("import_spotify").disabled = false;
|
||||
Helper.removeClass("#import_spotify", "hide");
|
||||
Helper.addClass("#playlist_loader_spotify", "hide");
|
||||
Search.submitArray = [];
|
||||
Search.submitArrayExpected = null;
|
||||
}
|
||||
},
|
||||
Search.submit(data.id, data.title, data.duration, true, i, Search.submitArray.length - 1, 0, data.duration);
|
||||
});*/
|
||||
document.getElementById("import_spotify").disabled = false;
|
||||
Helper.removeClass("#import_spotify", "hide");
|
||||
Helper.addClass("#playlist_loader_spotify", "hide");
|
||||
Search.submitArray = [];
|
||||
Search.submitArrayExpected = null;
|
||||
}
|
||||
},
|
||||
|
||||
submitAndClose: function(id,title,duration, start, end){
|
||||
Search.submit(id,title, duration, false, 0, 1, start, end);
|
||||
Helper.setHtml("#results", '');
|
||||
Search.showSearch();
|
||||
document.getElementById("search").value = "";
|
||||
document.getElementsByTagName("body")[0].setAttribute("style", "overflow-y:auto")
|
||||
Helper.setHtml("#results","");
|
||||
Helper.removeClass(".main", "blurT");
|
||||
Helper.removeClass("#controls", "blurT");
|
||||
Helper.removeClass(".main", "clickthrough");
|
||||
},
|
||||
submitAndClose: function(id,title,duration, start, end, source, thumbnail){
|
||||
Search.submit(id,title, duration, false, 0, 1, start, end, source, thumbnail);
|
||||
Helper.setHtml("#results", '');
|
||||
Search.showSearch();
|
||||
document.getElementById("search").value = "";
|
||||
document.getElementsByTagName("body")[0].setAttribute("style", "overflow-y:auto")
|
||||
Helper.setHtml("#results","");
|
||||
Helper.setHtml("#results-soundcloud", "");
|
||||
Helper.removeClass(".main", "blurT");
|
||||
Helper.removeClass("#controls", "blurT");
|
||||
Helper.removeClass(".main", "clickthrough");
|
||||
Helper.css(".search_results", "display", "none");
|
||||
},
|
||||
|
||||
importPlaylist: function(pId,pageToken){
|
||||
token = "";
|
||||
var headers;
|
||||
var datatype;
|
||||
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) {
|
||||
datatype = "html";
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + access_token_data_youtube.access_token
|
||||
};
|
||||
} else {
|
||||
headers = {};//'Content-Type': 'application/json'};
|
||||
datatype = "jsonp";
|
||||
}
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: playlist_url,
|
||||
dataType: datatype,
|
||||
//dataType:"jsonp",
|
||||
headers: headers,
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
if(response.error){
|
||||
if(response.error.errors[0].reason == "playlistItemsNotAccessible"){
|
||||
var nonce = Helper.randomString(29);
|
||||
window.callback = function(data) {
|
||||
access_token_data_youtube = data;
|
||||
if(access_token_data_youtube.state == nonce){
|
||||
youtube_authenticated = true;
|
||||
setTimeout(function(){
|
||||
youtube_authenticated = false;
|
||||
access_token_data_youtube = {};
|
||||
}, access_token_data_youtube.expires_in * 1000);
|
||||
Search.importPlaylist(pId, pageToken);
|
||||
} else {
|
||||
access_token_data_youtube = "";
|
||||
console.error("Nonce doesn't match");
|
||||
}
|
||||
youtube_window.close();
|
||||
window.callback = "";
|
||||
};
|
||||
youtube_window = window.open("/o_callback#youtube=true&nonce=" + nonce, "", "width=600, height=600");
|
||||
} else {
|
||||
Helper.log([
|
||||
"import list error: ",
|
||||
response.error
|
||||
]);
|
||||
document.getElementById("import").disabled = false;
|
||||
Helper.addClass("#playlist_loader", "hide");
|
||||
Helper.removeClass("#import", "hide");
|
||||
before_toast();
|
||||
M.toast({html: "It seems you've entered a invalid url.", displayLength: 4000});
|
||||
}
|
||||
|
||||
} else {
|
||||
var ids="";
|
||||
var this_length = 0;
|
||||
if(typeof(response) == "string") response = JSON.parse(response);
|
||||
//Search.addVideos(response.items[0].contentDetails.videoId);
|
||||
//response.items.shift();
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
var data = response.items[i];
|
||||
ids+=data.contentDetails.videoId+",";
|
||||
Search.submitYouTubeArrayIds.push(data.contentDetails.videoId);
|
||||
this_length += 1;
|
||||
Search.submitYouTubeExpected += 1;
|
||||
}
|
||||
|
||||
if(response.nextPageToken) {
|
||||
//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 = "";
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
if(e.status == 403){
|
||||
importPlaylist: function(pId,pageToken){
|
||||
token = "";
|
||||
var headers;
|
||||
var datatype;
|
||||
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) {
|
||||
datatype = "html";
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + access_token_data_youtube.access_token
|
||||
};
|
||||
} else {
|
||||
headers = {};//'Content-Type': 'application/json'};
|
||||
datatype = "jsonp";
|
||||
}
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: playlist_url,
|
||||
dataType: datatype,
|
||||
//dataType:"jsonp",
|
||||
headers: headers,
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
if(response.error){
|
||||
if(response.error.errors[0].reason == "playlistItemsNotAccessible"){
|
||||
var nonce = Helper.randomString(29);
|
||||
window.callback = function(data) {
|
||||
access_token_data_youtube = data;
|
||||
@@ -434,110 +481,167 @@ var Search = {
|
||||
before_toast();
|
||||
M.toast({html: "It seems you've entered a invalid url.", displayLength: 4000});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
importSpotifyPlaylist: function(url){
|
||||
Helper.ajax({
|
||||
method: "get",
|
||||
url: url,
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token_data.access_token
|
||||
},
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
} else {
|
||||
var ids="";
|
||||
var this_length = 0;
|
||||
if(typeof(response) == "string") response = JSON.parse(response);
|
||||
//Search.addVideos(response.items[0].contentDetails.videoId);
|
||||
//response.items.shift();
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
var data = response.items[i];
|
||||
//ids+=data.contentDetails.videoId+",";
|
||||
Search.backgroundSearch(data.track.name, data.track.artists.map(function(elem){return elem.name;}).join(" "), Math.floor(data.track.duration_ms/1000), response.total, i + response.offset);
|
||||
ids+=data.contentDetails.videoId+",";
|
||||
Search.submitYouTubeArrayIds.push(data.contentDetails.videoId);
|
||||
this_length += 1;
|
||||
Search.submitYouTubeExpected += 1;
|
||||
}
|
||||
|
||||
if(response.nextPageToken) {
|
||||
//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;
|
||||
}
|
||||
if(response.next){
|
||||
Search.importSpotifyPlaylist(response.next);
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
document.getElementById("import_spotify").disabled = false;
|
||||
Helper.removeClass("#import_spotify", "hide");
|
||||
Helper.addClass("#playlist_loader_spotify", "hide");
|
||||
document.getElementById("import").value = "";
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
if(e.status == 403){
|
||||
var nonce = Helper.randomString(29);
|
||||
window.callback = function(data) {
|
||||
access_token_data_youtube = data;
|
||||
if(access_token_data_youtube.state == nonce){
|
||||
youtube_authenticated = true;
|
||||
setTimeout(function(){
|
||||
youtube_authenticated = false;
|
||||
access_token_data_youtube = {};
|
||||
}, access_token_data_youtube.expires_in * 1000);
|
||||
Search.importPlaylist(pId, pageToken);
|
||||
} else {
|
||||
access_token_data_youtube = "";
|
||||
console.error("Nonce doesn't match");
|
||||
}
|
||||
youtube_window.close();
|
||||
window.callback = "";
|
||||
};
|
||||
youtube_window = window.open("/o_callback#youtube=true&nonce=" + nonce, "", "width=600, height=600");
|
||||
} else {
|
||||
Helper.log([
|
||||
"import list error: ",
|
||||
response.error
|
||||
]);
|
||||
document.getElementById("import").disabled = false;
|
||||
Helper.addClass("#playlist_loader", "hide");
|
||||
Helper.removeClass("#import", "hide");
|
||||
before_toast();
|
||||
M.toast({html: "It seems you've entered a invalid url.", displayLength: 4000});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
addVideos: function(ids){
|
||||
var more = false;
|
||||
var next_ids = [];
|
||||
var request_url="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=" + api_key + "&id=";
|
||||
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] + ",";
|
||||
}
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: request_url,
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
var x = 0;
|
||||
if(response.error) {
|
||||
Search.submitYouTubeError = true;
|
||||
}
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
var song = response.items[i];
|
||||
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;
|
||||
Search.submitYouTubeArray.push({id: song.id, title: enc_title, duration: duration});
|
||||
}
|
||||
}
|
||||
if(more) Search.addVideos(next_ids);
|
||||
else {
|
||||
socket.emit("addPlaylist", {channel: chan.toLowerCase(), songs: Search.submitYouTubeArray});
|
||||
Search.submitYouTubeArray = [];
|
||||
Search.submitYouTubeExpected = 0;
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
submit: function(id,title,duration, playlist, num, full_num, start, end){
|
||||
if((client || Helper.mobilecheck()) && !socket_connected) {
|
||||
add_ajax(id, title, duration, playlist, num, full_num, start, end);
|
||||
return;
|
||||
importSpotifyPlaylist: function(url){
|
||||
Helper.ajax({
|
||||
method: "get",
|
||||
url: url,
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token_data.access_token
|
||||
},
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
var data = response.items[i];
|
||||
//ids+=data.contentDetails.videoId+",";
|
||||
Search.backgroundSearch(data.track.name, data.track.artists.map(function(elem){return elem.name;}).join(" "), Math.floor(data.track.duration_ms/1000), response.total, i + response.offset);
|
||||
|
||||
}
|
||||
if(response.next){
|
||||
Search.importSpotifyPlaylist(response.next);
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
document.getElementById("import_spotify").disabled = false;
|
||||
Helper.removeClass("#import_spotify", "hide");
|
||||
Helper.addClass("#playlist_loader_spotify", "hide");
|
||||
before_toast();
|
||||
M.toast({html: "It seems you've entered a invalid url.", displayLength: 4000});
|
||||
}
|
||||
if(offline && document.getElementsByName("addsongs")[0].checked && document.getElementsByName("addsongs")[0].disabled){
|
||||
var found_array = [];
|
||||
for(var i = 0; i < full_playlist.length; i++) {
|
||||
if(full_playlist[i].id == id) found_array.push(i);
|
||||
}
|
||||
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, 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});
|
||||
}//[id, decodeURIComponent(title), adminpass, duration, playlist]);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
durationToSeconds: function(duration) {
|
||||
var matches = duration.match(time_regex);
|
||||
hours= parseInt(matches[12])||0;
|
||||
minutes= parseInt(matches[14])||0;
|
||||
seconds= parseInt(matches[16])||0;
|
||||
return hours*60*60+minutes*60+seconds;
|
||||
addVideos: function(ids){
|
||||
var more = false;
|
||||
var next_ids = [];
|
||||
var request_url="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=" + api_key + "&id=";
|
||||
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] + ",";
|
||||
}
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: request_url,
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
var x = 0;
|
||||
if(response.error) {
|
||||
Search.submitYouTubeError = true;
|
||||
}
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
var song = response.items[i];
|
||||
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;
|
||||
Search.submitYouTubeArray.push({id: song.id, title: enc_title, duration: duration});
|
||||
}
|
||||
}
|
||||
if(more) Search.addVideos(next_ids);
|
||||
else {
|
||||
socket.emit("addPlaylist", {channel: chan.toLowerCase(), songs: Search.submitYouTubeArray});
|
||||
Search.submitYouTubeArray = [];
|
||||
Search.submitYouTubeExpected = 0;
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
submit: function(id,title,duration, playlist, num, full_num, start, end, source, thumbnail){
|
||||
if((client || Helper.mobilecheck()) && !socket_connected) {
|
||||
add_ajax(id, title, duration, playlist, num, full_num, start, end, source, thumbnail);
|
||||
return;
|
||||
}
|
||||
if(offline && document.getElementsByName("addsongs")[0].checked && document.getElementsByName("addsongs")[0].disabled){
|
||||
var found_array = [];
|
||||
for(var i = 0; i < full_playlist.length; i++) {
|
||||
if(full_playlist[i].id == id) found_array.push(i);
|
||||
}
|
||||
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, 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, source: source, thumbnail: thumbnail});
|
||||
}//[id, decodeURIComponent(title), adminpass, duration, playlist]);
|
||||
},
|
||||
|
||||
durationToSeconds: function(duration) {
|
||||
var matches = duration.match(time_regex);
|
||||
hours= parseInt(matches[12])||0;
|
||||
minutes= parseInt(matches[14])||0;
|
||||
seconds= parseInt(matches[16])||0;
|
||||
return hours*60*60+minutes*60+seconds;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user