mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Started migration from jquery
This commit is contained in:
@@ -9,8 +9,8 @@ var Admin = {
|
||||
w_p = false;
|
||||
|
||||
if(Admin.logged_in) {
|
||||
$("#thumbnail_form").css("display", "inline-block");
|
||||
$("#description_form").css("display", "inline-block");
|
||||
Helper.css("#thumbnail_form", "display", "inline-block");
|
||||
Helper.css("#description_form", "display", "inline-block");
|
||||
$("#user_suggests").removeClass("hide");
|
||||
$("#user-suggest-html").removeClass("hide");
|
||||
if($(".suggested-badge").text() != "0" && $(".suggested-badge").text() != "") {
|
||||
|
||||
@@ -571,8 +571,9 @@ var Channel = {
|
||||
socket.removeEventListener("suggested");
|
||||
socket.removeEventListener("color");
|
||||
socket.removeEventListener("chat_history");
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
url: "/",
|
||||
method: "GET",
|
||||
success: function(e){
|
||||
|
||||
if(!client) {
|
||||
|
||||
@@ -215,7 +215,7 @@ var Frontpage = {
|
||||
if(window.location.hostname == "fb.zoff.me") {
|
||||
add = "https://zoff.me";
|
||||
}
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
data: {id:id},
|
||||
url: add + "/api/imageblob",
|
||||
@@ -259,10 +259,11 @@ var Frontpage = {
|
||||
if(window.location.hostname == "fb.zoff.me") {
|
||||
add = "https://zoff.me";
|
||||
}
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
url: add + "/api/frontpages",
|
||||
method: "get",
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
Frontpage.frontpage_function(response.results);
|
||||
},
|
||||
error: function() {
|
||||
@@ -327,7 +328,7 @@ var Frontpage = {
|
||||
}
|
||||
currently_showing_channels = 1;
|
||||
clearTimeout(retry_frontpage);
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
url: "/" + new_channel,
|
||||
method: "get",
|
||||
data: {channel: new_channel},
|
||||
|
||||
@@ -22,7 +22,7 @@ function removeAllListeners() {
|
||||
}
|
||||
|
||||
function getColor(id) {
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
url: "/api/color",
|
||||
async: true,
|
||||
@@ -30,6 +30,7 @@ function getColor(id) {
|
||||
id: id
|
||||
},
|
||||
success: function(c) {
|
||||
c = JSON.parse(c);
|
||||
if(typeof(c) == "object") {
|
||||
Player.setBGimage({color:c, only:true});
|
||||
}
|
||||
@@ -185,7 +186,7 @@ function emit_list() {
|
||||
|
||||
function get_list_ajax() {
|
||||
//var c = Crypt.get_userpass(chan.toLowerCase());
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
data: {
|
||||
userpass: "",
|
||||
@@ -193,6 +194,7 @@ function get_list_ajax() {
|
||||
},
|
||||
url: "/api/list/" + chan.toLowerCase(),
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
if(response.results.length > 0) {
|
||||
if(response.status == 403) {
|
||||
start_auth();
|
||||
@@ -203,13 +205,14 @@ function get_list_ajax() {
|
||||
List.populate_list(response.results);
|
||||
}
|
||||
},
|
||||
error: function(response) {
|
||||
if(response.responseJSON.status == 403) {
|
||||
error: function(response, xmlhttp) {
|
||||
response = JSON.parse(response);
|
||||
if(response.status == 403) {
|
||||
start_auth();
|
||||
} else if(response.responseJSON.status == 429) {
|
||||
} else if(response.status == 429) {
|
||||
setTimeout(function() {
|
||||
get_list_ajax();
|
||||
}, response.getResponseHeader("Retry-After") * 1000)
|
||||
}, xmlhttp.getResponseHeader("Retry-After") * 1000)
|
||||
}
|
||||
if(client) {
|
||||
$("#channel-load").remove();
|
||||
@@ -260,7 +263,7 @@ function mouseContext(left, top) {
|
||||
function get_np_ajax() {
|
||||
/*var c = Crypt.get_userpass(chan.toLowerCase());
|
||||
if(c == undefined) c = "";*/
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
data: {
|
||||
userpass: "",
|
||||
@@ -269,15 +272,17 @@ function get_np_ajax() {
|
||||
},
|
||||
url: "/api/list/" + chan.toLowerCase() + "/__np__",
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
Player.getTitle(response.results[0].title, 1);
|
||||
},
|
||||
error: function(response) {
|
||||
if(response.responseJSON.status == 403) {
|
||||
error: function(response, xmlhttp) {
|
||||
response = JSON.parse(response);
|
||||
if(response.status == 403) {
|
||||
start_auth();
|
||||
} else if(response.responseJSON.status == 429) {
|
||||
} else if(response.status == 429) {
|
||||
setTimeout(function() {
|
||||
get_np_ajax();
|
||||
}, response.getResponseHeader("Retry-After") * 1000)
|
||||
}, xmlhttp.getResponseHeader("Retry-After") * 1000)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -288,7 +293,7 @@ function del_ajax(id) {
|
||||
var u = Crypt.get_userpass(chan.toLowerCase());
|
||||
if(a == undefined) a = "";
|
||||
if(u == undefined) u = "";*/
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "DELETE",
|
||||
data: {
|
||||
adminpass: "",
|
||||
@@ -300,13 +305,14 @@ function del_ajax(id) {
|
||||
toast("deletesong");
|
||||
get_list_ajax();
|
||||
},
|
||||
error: function(response) {
|
||||
if(response.responseJSON.status == 403) {
|
||||
error: function(response, xmlhttp) {
|
||||
response = JSON.parse(response);
|
||||
if(response.status == 403) {
|
||||
toast("listhaspass");
|
||||
} else if(response.responseJSON.status == 429) {
|
||||
} else if(response.status == 429) {
|
||||
setTimeout(function() {
|
||||
del_ajax(id);
|
||||
}, response.getResponseHeader("Retry-After") * 1000);
|
||||
}, xmlhttp.getResponseHeader("Retry-After") * 1000);
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -317,7 +323,7 @@ function add_ajax(id, title, duration, playlist, num, full_num, start, end) {
|
||||
var u = Crypt.get_userpass(chan.toLowerCase());
|
||||
if(a == undefined) a = "";
|
||||
if(u == undefined) u = "";*/
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
data: {
|
||||
adminpass: "",
|
||||
@@ -333,15 +339,16 @@ function add_ajax(id, title, duration, playlist, num, full_num, start, end) {
|
||||
toast("addedsong");
|
||||
get_list_ajax();
|
||||
},
|
||||
error: function(response) {
|
||||
if(response.responseJSON.status == 403) {
|
||||
error: function(response, xmlhttp) {
|
||||
response = JSON.parse(response);
|
||||
if(response.status == 403) {
|
||||
toast("listhaspass");
|
||||
} else if(response.responseJSON.status == 409) {
|
||||
} else if(response.status == 409) {
|
||||
vote_ajax(id);
|
||||
} else if(response.responseJSON.status == 429) {
|
||||
} else if(response.status == 429) {
|
||||
setTimeout(function() {
|
||||
add_ajax(id, title, duration, playlist, num, full_num, start, end);
|
||||
}, response.getResponseHeader("Retry-After") * 1000);
|
||||
}, xmlhttp.getResponseHeader("Retry-After") * 1000);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -352,7 +359,7 @@ function vote_ajax(id) {
|
||||
var u = Crypt.get_userpass(chan.toLowerCase());
|
||||
if(a == undefined) a = "";
|
||||
if(u == undefined) u = "";*/
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "PUT",
|
||||
data: {
|
||||
adminpass: "",
|
||||
@@ -364,13 +371,14 @@ function vote_ajax(id) {
|
||||
toast("voted");
|
||||
get_list_ajax();
|
||||
},
|
||||
error: function(response) {
|
||||
if(response.responseJSON.status == 403) {
|
||||
error: function(response, xmlhttp) {
|
||||
response = JSON.parse(response);
|
||||
if(response.status == 403) {
|
||||
toast("listhaspass");
|
||||
} else if(response.responseJSON.status == 429) {
|
||||
} else if(response.status == 429) {
|
||||
setTimeout(function() {
|
||||
vote_ajax(id);
|
||||
}, response.getResponseHeader("Retry-After") * 1000);
|
||||
}, xmlhttp.getResponseHeader("Retry-After") * 1000);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -18,6 +18,81 @@ var Helper = {
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
},
|
||||
|
||||
css: function(element, attribute, value) {
|
||||
try {
|
||||
if(element.substring(0,1) == "#") {
|
||||
document.getElementById(element.substring(1)).style[attribute] = value;
|
||||
} else {
|
||||
var elements = documents.getElementsByClassName(element.substring(1));
|
||||
for(var i = 0; i < elements.length; i++) {
|
||||
elements[i].style[attribute] = value;
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
|
||||
removeClass: function(element, className) {
|
||||
try {
|
||||
if(element.substring(0,1) == "#") {
|
||||
document.getElementById(element.substring(1)).classList.remove(className);
|
||||
} else {
|
||||
var elements = documents.getElementsByClassName(element.substring(1));
|
||||
for(var i = 0; i < elements.length; i++) {
|
||||
elements[i].classList.remove(className);
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
|
||||
addClass: function(element, className) {
|
||||
if(element.substring(0,1) == "#") {
|
||||
var elem = document.getElementById(element.substring(1));
|
||||
if(elem.className.indexOf(className) == -1) {
|
||||
elem.className += " " + className;
|
||||
}
|
||||
} else {
|
||||
var elements = documents.getElementsByClassName(element.substring(1));
|
||||
for(var i = 0; i < elements.length; i++) {
|
||||
if(elements[i].className.indexOf(className) == -1) {
|
||||
elements[i].className += " " + className;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
ajax: function(obj) {
|
||||
var _async = true;
|
||||
if(obj.async) _async = obj.async;
|
||||
if(obj.method == undefined) obj.method = "GET";
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
if(obj.headers) {
|
||||
for(header in obj.headers) {
|
||||
xmlhttp.setRequestHeader(header, obj.headers[header]);
|
||||
}
|
||||
}
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4
|
||||
if (xmlhttp.status == 200) {
|
||||
obj.success(xmlhttp.responseText, xmlhttp);
|
||||
}
|
||||
else {
|
||||
obj.error(xmlhttp);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xmlhttp.open(obj.method, obj.url, _async);
|
||||
if(obj.data) {
|
||||
if(typeof(obj.data) == "object") obj.data = JSON.stringify(obj.data);
|
||||
xmlhttp.send(obj.data);
|
||||
}
|
||||
else xmlhttp.send();
|
||||
},
|
||||
|
||||
randomString: function(length){
|
||||
var text = "";
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_";
|
||||
@@ -262,12 +337,6 @@ var Helper = {
|
||||
return string.substring(0,1).toUpperCase()+string.substring(1).toLowerCase();
|
||||
},
|
||||
|
||||
addClass: function(object, toAdd){
|
||||
if(!Helper.contains($(object).attr("class").split(" "), toAdd)){
|
||||
$(object).addClass(toAdd);
|
||||
}
|
||||
},
|
||||
|
||||
send_mail: function(from, message){
|
||||
if(from !== "" && message !== ""){
|
||||
|
||||
@@ -276,7 +345,7 @@ var Helper = {
|
||||
$("#contact-form-from").attr("disabled", "true");
|
||||
$("#contact-form-message").attr("disabled", "true");
|
||||
var captcha_response = grecaptcha.getResponse();
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
data: {
|
||||
from: from,
|
||||
|
||||
@@ -187,14 +187,15 @@ var List = {
|
||||
full_playlist
|
||||
]);
|
||||
if(full_playlist.length > 1){
|
||||
$.each(full_playlist, function(j, _current_song){
|
||||
for(var j = 0; j < full_playlist.length; j++) {
|
||||
var _current_song = full_playlist[j];
|
||||
if(!_current_song.hasOwnProperty("start")) full_playlist[j].start = 0;
|
||||
if(!_current_song.hasOwnProperty("end")) full_playlist[j].end = full_playlist[j].duration;
|
||||
if(!_current_song.now_playing && _current_song.type != "suggested"){ //check that the song isnt playing
|
||||
var generated = List.generateSong(_current_song, false, lazy_load, true, false, "", true)
|
||||
$("#wrapper").append(generated);
|
||||
}
|
||||
});
|
||||
}
|
||||
if($("#wrapper").children().length > List.can_fit && !$("#pageButtons").length){
|
||||
$(".prev_page").css("display", "none");
|
||||
$(".first_page").css("display", "none");
|
||||
@@ -593,17 +594,18 @@ var List = {
|
||||
exportToSpotify: function() {
|
||||
ga('send', 'event', "export", "spotify");
|
||||
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: "https://api.spotify.com/v1/me",
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token_data.access_token
|
||||
},
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
var user_id = response.id;
|
||||
$("#playlist_loader_export").removeClass("hide");
|
||||
$(".exported-list-container").removeClass("hide");
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
url: "https://api.spotify.com/v1/users/" + user_id + "/playlists",
|
||||
headers: {
|
||||
@@ -616,13 +618,14 @@ var List = {
|
||||
public: true
|
||||
}),
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
var playlist_id = response.id;
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: window.location.protocol + "//" + window.location.hostname + "/assets/images/small-square.base64.txt",
|
||||
success: function(base64image) {
|
||||
var image = base64image.substring(0, base64image.length - 1);
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "PUT",
|
||||
url: "https://api.spotify.com/v1/users/" + user_id + "/playlists/" + playlist_id + "/images",
|
||||
headers: {
|
||||
@@ -656,7 +659,7 @@ var List = {
|
||||
|
||||
$(".current_number").removeClass("hide");
|
||||
$(".current_number").text((current_element + 1) + " of " + (full_playlist.length));
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: "https://api.spotify.com/v1/search?q=" + track + "&type=track",
|
||||
headers: {
|
||||
@@ -677,8 +680,10 @@ var List = {
|
||||
}
|
||||
},
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
var found = false;
|
||||
$.each(response.tracks.items, function(i, data){
|
||||
for(var i = 0; i < response.tracks.items.length; i++) {
|
||||
var data = response.tracks.items[i];
|
||||
data.name = Helper.replaceForFind(data.name);
|
||||
data.artists[0].name = Helper.replaceForFind(data.artists[0].name);
|
||||
if(data.name.substring(data.name.length-1) == " ") data.name = data.name.substring(0,data.name.length-1);
|
||||
@@ -693,7 +698,7 @@ var List = {
|
||||
track
|
||||
]);
|
||||
//List.num_songs = List.num_songs + 1;
|
||||
return false;
|
||||
break;
|
||||
} else if(decodeURIComponent(track).indexOf(data.artists[0].name.toLowerCase()) >= 0 && decodeURIComponent(track).indexOf(data.name.toLowerCase()) >= 0){
|
||||
found = true;
|
||||
List.uris.push(data.uri);
|
||||
@@ -702,16 +707,19 @@ var List = {
|
||||
track
|
||||
]);
|
||||
//List.num_songs = List.num_songs + 1;
|
||||
return false;
|
||||
break;
|
||||
} else {
|
||||
var splitted = data.name.split(" ");
|
||||
for(var i = 0; i < splitted.length; i++){
|
||||
var toBreak = false;
|
||||
for(var i = 0; i < splitted.length; i++) {
|
||||
if((splitted[i] == "and" && track.indexOf("&") >= 0) || (splitted[i] == "&" && track.indexOf("and") >= 0)){
|
||||
continue;
|
||||
} else if(track.indexOf(splitted[i]) < 0){
|
||||
return true;
|
||||
toBreak = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(toBreak) break;
|
||||
found = true;
|
||||
List.uris.push(data.uri);
|
||||
Helper.log([
|
||||
@@ -719,9 +727,9 @@ var List = {
|
||||
track
|
||||
]);
|
||||
//List.num_songs = List.num_songs + 1;
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(!found){
|
||||
List.not_found.push(original_track);
|
||||
List.num_songs = List.num_songs + 1;
|
||||
@@ -745,12 +753,14 @@ var List = {
|
||||
if($(".exported-spotify-list").length == 0) {
|
||||
$(".exported-list").append("<a target='_blank' class='btn light exported-playlist exported-spotify-list' href='https://open.spotify.com/user/" + user_id + "/playlist/"+ playlist_id + "'>" + chan + "</a>");
|
||||
}
|
||||
$.each(List.not_found, function(i, data){
|
||||
for(var i = 0; i < List.not_found.length; i++) {
|
||||
var data = List.not_found[i];
|
||||
|
||||
var not_added_song = $("<div>" + not_export_html + "</div>");
|
||||
not_added_song.find(".extra-add-text").attr("value", data);
|
||||
not_added_song.find(".extra-add-text").attr("title", data);
|
||||
$(".not-exported-container").append(not_added_song.html());
|
||||
})
|
||||
}
|
||||
$(".current_number").addClass("hide");
|
||||
$(".not-exported").removeClass("hide");
|
||||
$(".spotify_export_button").css("display", "block");
|
||||
@@ -762,7 +772,7 @@ var List = {
|
||||
},
|
||||
|
||||
addToSpotifyPlaylist: function(uris, playlist_id, user_id) {
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
url: "https://api.spotify.com/v1/users/" + user_id + "/playlists/" + playlist_id + "/tracks",
|
||||
headers: {
|
||||
@@ -792,7 +802,7 @@ var List = {
|
||||
var request_url = "https://www.googleapis.com/youtube/v3/playlists?part=snippet";
|
||||
$(".exported-list-container").removeClass("hide");
|
||||
$("#playlist_loader_export").removeClass("hide");
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
url: request_url,
|
||||
headers: {
|
||||
@@ -806,12 +816,14 @@ var List = {
|
||||
}
|
||||
}),
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
var number_added = 0;
|
||||
var playlist_id = response.id;
|
||||
var request_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet";
|
||||
List.addToYoutubePlaylist(playlist_id, full_playlist, number_added, request_url)
|
||||
},
|
||||
error: function(response){
|
||||
response = response.responseText;
|
||||
Helper.log([
|
||||
"export to youtube response",
|
||||
response
|
||||
@@ -830,7 +842,7 @@ var List = {
|
||||
}
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
url: request_url,
|
||||
headers: {
|
||||
@@ -839,6 +851,7 @@ var List = {
|
||||
},
|
||||
data: _data,
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
Helper.log(["Added video: " + full_playlist[num].id + " to playlist id " + playlist_id]);
|
||||
if(num == full_playlist.length - 1){
|
||||
Helper.log(["All videoes added!"]);
|
||||
|
||||
@@ -141,9 +141,10 @@ try{
|
||||
|
||||
} catch(e) {}
|
||||
|
||||
/*
|
||||
$.ajaxPrefilter(function( options, original_Options, jqXHR ) {
|
||||
options.async = true;
|
||||
});
|
||||
});*/
|
||||
|
||||
window.zoff = {
|
||||
enable_debug: enable_debug,
|
||||
@@ -1226,7 +1227,7 @@ $(document).on('submit', "#error-report-form", function(e) {
|
||||
e.preventDefault();
|
||||
var captcha_response = grecaptcha.getResponse();
|
||||
$("#send-loader").removeClass("hide");
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
data: {
|
||||
from: "no-reply@zoff.me",
|
||||
@@ -1358,7 +1359,7 @@ $(document).on("click", "#player_bottom_overlay", function(e){
|
||||
|
||||
$(document).on("click", ".generate-channel-name", function(e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: "/api/generate_name",
|
||||
success: function(response) {
|
||||
|
||||
@@ -295,6 +295,8 @@ var Player = {
|
||||
}*/
|
||||
//}
|
||||
}
|
||||
$("#playpause").css("visibility", "visible");
|
||||
$("#playpause").css("pointer-events", "all");
|
||||
playing = true;
|
||||
if(beginning && Helper.mobilecheck() && !chromecastAvailable){
|
||||
//Player.pauseVideo();
|
||||
|
||||
@@ -58,11 +58,12 @@ var Search = {
|
||||
if(Helper.contains($("#results").attr("class").split(" "), "hide"))
|
||||
$("#results").removeClass("hide");
|
||||
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: yt_url,
|
||||
dataType:"jsonp",
|
||||
dataType: "jsonp",
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
var nextPageToken = response.nextPageToken;
|
||||
var prevPageToken = response.prevPageToken;
|
||||
if(response.items.length === 0) {
|
||||
@@ -73,23 +74,23 @@ var Search = {
|
||||
$(".search_loader_spinner").removeClass("active");
|
||||
|
||||
} else if(response.items){
|
||||
$.each(response.items, function(i,data) {
|
||||
vid_url += data.id.videoId+",";
|
||||
});
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
vid_url += response.items[i].id.videoId+",";
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: vid_url,
|
||||
dataType:"jsonp",
|
||||
success: function(response){
|
||||
|
||||
response = JSON.parse(response);
|
||||
var output = "";
|
||||
var pre_result = $(result_html);
|
||||
|
||||
//$("#results").append(result_html);
|
||||
|
||||
$.each(response.items, function(i,song)
|
||||
{
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
var song = response.items[i];
|
||||
var duration=song.contentDetails.duration;
|
||||
secs=Search.durationToSeconds(duration);
|
||||
var _temp_duration = Helper.secondsToOther(secs);
|
||||
@@ -121,7 +122,7 @@ var Search = {
|
||||
output += songs.html();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
var fresh = false;
|
||||
if($("#inner-results").length == 0) {
|
||||
fresh = true;
|
||||
@@ -189,11 +190,12 @@ var Search = {
|
||||
artist = artist.split(" ");
|
||||
var temptitle = title.split("-");
|
||||
temptitle = temptitle.join(" ").split(" ");
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: yt_url,
|
||||
dataType:"jsonp",
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
//Helper.log(response);
|
||||
if(response.items.length === 0){
|
||||
Search.readySubmit(false, {totalLength: totalNumber - 1});
|
||||
@@ -209,19 +211,21 @@ var Search = {
|
||||
$(".not-imported-container").append(not_added_song.html());
|
||||
$(".not-imported").removeClass("hide");
|
||||
} else if(response.items.length > 0) {
|
||||
$.each(response.items, function(i,data)
|
||||
{
|
||||
for(var i = 0; i < response.items; i++) {
|
||||
var data = response.items[i];
|
||||
vid_url += data.id.videoId+",";
|
||||
});
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: vid_url,
|
||||
dataType:"jsonp",
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
if(response.items.length > 0) {
|
||||
var matched = false;
|
||||
$.each(response.items, function(i, data){
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
var data = response.items[i];
|
||||
//Helper.log(data);
|
||||
//var title = data.snippet.title;
|
||||
var duration = Search.durationToSeconds(data.contentDetails.duration);
|
||||
@@ -229,7 +233,9 @@ var Search = {
|
||||
if(similarity(data.snippet.title, artist + " - " + title) > 0.75) {
|
||||
not_matched = false;
|
||||
} else {
|
||||
$.each(temptitle, function(i, data_title){
|
||||
for(var i = 0; i < temptitle.length; i++) {
|
||||
var data_title = temptitle[i];
|
||||
|
||||
if(data.snippet.title.toLowerCase().indexOf(data_title.toLowerCase()) == -1 || !(
|
||||
data.snippet.title.toLowerCase().indexOf("cover") == -1 &&
|
||||
title.toLowerCase().indexOf("cover") == -1 &&
|
||||
@@ -243,16 +249,16 @@ var Search = {
|
||||
not_matched = true;
|
||||
else if(duration > 1800) not_matched = true;
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if((!not_matched)){
|
||||
matched = true;
|
||||
Search.readySubmit(true, { id: data.id, title: data.snippet.title, duration: duration, totalLength: totalNumber - 1});
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(!matched){
|
||||
Search.readySubmit(false, {totalLength: totalNumber - 1});
|
||||
Helper.log([
|
||||
@@ -327,13 +333,14 @@ var Search = {
|
||||
headers = {};//'Content-Type': 'application/json'};
|
||||
datatype = "jsonp";
|
||||
}
|
||||
$.ajax({
|
||||
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);
|
||||
@@ -372,12 +379,13 @@ var Search = {
|
||||
if(typeof(response) == "string") response = $.parseJSON(response);
|
||||
//Search.addVideos(response.items[0].contentDetails.videoId);
|
||||
//response.items.shift();
|
||||
$.each(response.items, function(i,data) {
|
||||
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);
|
||||
@@ -394,18 +402,19 @@ var Search = {
|
||||
},
|
||||
|
||||
importSpotifyPlaylist: function(url){
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
url: url,
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token_data.access_token
|
||||
},
|
||||
success: function(response) {
|
||||
$.each(response.items, function(i,data)
|
||||
{
|
||||
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);
|
||||
}
|
||||
@@ -433,16 +442,18 @@ var Search = {
|
||||
request_url += ids[i] + ",";
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
url: request_url,
|
||||
dataType:"jsonp",
|
||||
success: function(response){
|
||||
response = JSON.parse(response);
|
||||
var x = 0;
|
||||
if(response.error) {
|
||||
Search.submitYouTubeError = true;
|
||||
}
|
||||
$.each(response.items, function(i,song) {
|
||||
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);
|
||||
@@ -450,7 +461,7 @@ var Search = {
|
||||
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});
|
||||
|
||||
@@ -40,26 +40,29 @@ var Suggestions = {
|
||||
var get_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&relatedToVideoId="+id+"&type=video&key="+api_key;
|
||||
var video_urls = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key+"&id=";
|
||||
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: get_url,
|
||||
dataType:"jsonp",
|
||||
success: function(response)
|
||||
{
|
||||
$.each(response.items.slice(0,5), function(i,data){
|
||||
response = JSON.parse(response);
|
||||
var this_resp = response.items.slice(0,5);
|
||||
for(var i = 0; i < this_resp.length; i++) {
|
||||
var data = this_resp[i];
|
||||
video_urls += data.id.videoId+",";
|
||||
});
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "GET",
|
||||
url: video_urls,
|
||||
dataType: "jsonp",
|
||||
success: function(response)
|
||||
{
|
||||
response = JSON.parse(response);
|
||||
$("#suggest-song-html").empty();
|
||||
|
||||
$.each(response.items, function(i,song)
|
||||
{
|
||||
for(var i = 0; i < response.items.length; i++) {
|
||||
var song = response.items[i];
|
||||
var duration = song.contentDetails.duration;
|
||||
var length = Search.durationToSeconds(duration);
|
||||
duration = Helper.secondsToOther(Search.durationToSeconds(duration));
|
||||
@@ -67,7 +70,7 @@ var Suggestions = {
|
||||
var video_title = song.snippet.title;
|
||||
|
||||
$("#suggest-song-html").append(List.generateSong({id: video_id, title: video_title, length: length, duration: duration}, false, false, false));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ $(document).ready(function() {
|
||||
$(".submit").toggleClass("disabled");
|
||||
$(".full-form-token").removeClass("hide");
|
||||
var captcha_response = grecaptcha.getResponse();
|
||||
$.ajax({
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
url: "/api/apply",
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user