mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Soundcloud updates for private lists testing
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Zoff OAuth Callback</title>
|
||||
<script src="https://connect.soundcloud.com/sdk/sdk-3.3.0.js"></script>
|
||||
<script type="text/javascript" src="/assets/dist/callback.min.js"></script>
|
||||
<meta charset="UTF-8"/>
|
||||
<style>
|
||||
|
||||
@@ -20,6 +20,31 @@ window.addEventListener("load", function() {
|
||||
|
||||
//window.opener.callback(query);
|
||||
window.location.href = "https://accounts.google.com/o/oauth2/v2/auth?client_id=" + client_id + "&response_type=" + response + "&state=" + state + "&redirect_uri=" + redirect + "&scope=" + scope;
|
||||
} else if(query.soundcloud) {
|
||||
/*
|
||||
SC.initialize({
|
||||
client_id: api_key.soundcloud,
|
||||
redirect_uri: 'https://zoff.me/api/oauth'
|
||||
});
|
||||
|
||||
// initiate auth popup
|
||||
console.log("asd ok", api_key.soundcloud);
|
||||
SC.connect().then(function() {
|
||||
return SC.get('/me');
|
||||
}).then(function(me) {
|
||||
console.log(me);
|
||||
//alert('Hello, ' + me.username);
|
||||
}).catch(function(e) {
|
||||
console.log(e);
|
||||
});*/
|
||||
|
||||
var redirect_uri = encodeURIComponent("https://zoff.me/api/oauth");
|
||||
var response_type = "code";
|
||||
var scope = "non-expiring";
|
||||
var state = query.nonce;
|
||||
var url = "https://soundcloud.com/connect?client_id=" + api_key.soundcloud + "&redirect_uri=" + redirect_uri + "&state=" + state + "&display=page&response_type=code&scope=" + scope;
|
||||
//console.log(url);
|
||||
window.location.href = url;
|
||||
} else {
|
||||
var query_parameters = getQueryHash(window.location.hash);
|
||||
window.opener.callback(query_parameters);
|
||||
@@ -27,14 +52,30 @@ window.addEventListener("load", function() {
|
||||
});
|
||||
|
||||
function getQueryHash(url) {
|
||||
var temp_arr = url.substring(1).split("&");
|
||||
var done_obj = {};
|
||||
var splitted;
|
||||
for(var i in temp_arr) {
|
||||
splitted = temp_arr[i].split("=");
|
||||
if(splitted.length == 2) {
|
||||
done_obj[splitted[0]] = splitted[1];
|
||||
if(window.location.search.length > 0) {
|
||||
if(url.substring(url.length - 1) == "#") {
|
||||
url = url.substring(0, url.length - 1);
|
||||
}
|
||||
var temp_arr = url.substring(1).split("&");
|
||||
var done_obj = {};
|
||||
var splitted;
|
||||
for(var i in temp_arr) {
|
||||
splitted = temp_arr[i].split("=");
|
||||
if(splitted.length == 2) {
|
||||
done_obj[splitted[0]] = splitted[1];
|
||||
}
|
||||
}
|
||||
return done_obj;
|
||||
} else {
|
||||
var temp_arr = url.substring(1).split("&");
|
||||
var done_obj = {};
|
||||
var splitted;
|
||||
for(var i in temp_arr) {
|
||||
splitted = temp_arr[i].split("=");
|
||||
if(splitted.length == 2) {
|
||||
done_obj[splitted[0]] = splitted[1];
|
||||
}
|
||||
}
|
||||
return done_obj;
|
||||
}
|
||||
return done_obj;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,8 @@ var chat_active = false;
|
||||
var chat_unseen = false;
|
||||
var blinking = false;
|
||||
var from_frontpage = false;
|
||||
var access_token_data_soundcloud = {};
|
||||
var soundcloud_window;
|
||||
var access_token_data = {};
|
||||
var spotify_authenticated = false;
|
||||
var not_import_html = "";
|
||||
@@ -1081,6 +1083,85 @@ function addDynamicListeners() {
|
||||
},
|
||||
error: function(data) {
|
||||
console.log(data);
|
||||
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
||||
Helper.removeClass("#listImportSoundCloud", "hide");
|
||||
if(data.status == 404) {
|
||||
var nonce = Helper.randomString(29);
|
||||
window.callback = function(data) {
|
||||
access_token_data_soundcloud = data;
|
||||
if(access_token_data_soundcloud.state == nonce){
|
||||
soundcloud_authenticated = true;
|
||||
Helper.ajax({
|
||||
type: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
url: "https://api.soundcloud.com/resolve/?url=" + document.querySelector("#import_soundcloud").value + "&limit=1&client_id=" + api_key.soundcloud + "&oauth_token=" + access_token_data_soundcloud.code + "&format=json&_status_code_map[200]=200",
|
||||
success: function(data){
|
||||
try {
|
||||
var jsonData = JSON.parse(data);
|
||||
var tracks = jsonData.tracks;
|
||||
document.querySelector("#import_soundcloud").value = "";
|
||||
var addList = [];
|
||||
for(var i = 0; i < tracks.length; i++) {
|
||||
var song = tracks[i];
|
||||
var title=song.title;
|
||||
if(title.indexOf(song.user.username) == -1) {
|
||||
title = song.user.username + " - " + title;
|
||||
}
|
||||
if(!song.streamable) {
|
||||
var not_added_song = document.createElement("div");
|
||||
not_added_song.innerHTML = not_import_html;
|
||||
|
||||
not_added_song.querySelector(".extra-add-text").innerText = title;
|
||||
not_added_song.querySelector(".extra-add-text").setAttribute("title", title);
|
||||
not_added_song.querySelector(".extra-button-search").setAttribute("data-text", title);
|
||||
document.querySelector(".not-imported-container").insertAdjacentHTML("beforeend", not_added_song.innerHTML);
|
||||
Helper.removeClass(".not-imported", "hide");
|
||||
continue;
|
||||
}
|
||||
var duration=Math.floor(song.duration / 1000);
|
||||
//var secs=Search.durationToSeconds(duration);
|
||||
var secs = duration;
|
||||
if(longsongs == undefined) longsongs = true;
|
||||
if((longsongs != undefined && !longsongs) || secs<720){
|
||||
|
||||
var id=song.id;
|
||||
//duration = duration.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s");
|
||||
var thumb=song.artwork_url;
|
||||
//var thumb = null;
|
||||
if(thumb == null) thumb = song.waveform_url;
|
||||
|
||||
var songElement = {id: song.id, title: title, duration: secs, source: "soundcloud", thumbnail: thumb};
|
||||
|
||||
addList.push(songElement);
|
||||
}
|
||||
}
|
||||
if(addList.length > 0) {
|
||||
socket.emit("addPlaylist", {channel: chan.toLowerCase(), songs: addList});
|
||||
}
|
||||
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
||||
Helper.removeClass("#listImportSoundCloud", "hide");
|
||||
//{id: song.id, title: enc_title, duration: duration, source: "youtube", thumbnail: "https://img.youtube.com/vi/" + song.id + "/mqdefault.jpg"}
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
||||
Helper.removeClass("#listImportSoundCloud", "hide");
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
access_token_data_soundcloud = {};
|
||||
console.error("States doesn't match");
|
||||
}
|
||||
soundcloud_window.close();
|
||||
window.callback = "";
|
||||
};
|
||||
soundcloud_window = window.open("/api/oauth#soundcloud=true&nonce=" + nonce, "", "width=600, height=600");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user