From 71f1826435efad18ea7f3de6f9f8634e7d85f120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Tue, 23 Oct 2018 12:33:27 +0200 Subject: [PATCH] Exporting to soundcloud tests --- server/public/assets/js/callback.js | 4 +- server/public/assets/js/list.js | 63 +++++++++++++++++++ server/public/assets/js/listeners.js | 10 ++- server/public/assets/js/player.js | 18 ++++-- .../public/partials/channel/panel.handlebars | 6 +- 5 files changed, 89 insertions(+), 12 deletions(-) diff --git a/server/public/assets/js/callback.js b/server/public/assets/js/callback.js index ec09f7e0..c3b6017c 100755 --- a/server/public/assets/js/callback.js +++ b/server/public/assets/js/callback.js @@ -54,7 +54,9 @@ window.addEventListener("load", function() { } try { window.opener.callback(query_parameters); - } catch(e) {} + } catch(e) { + window.setTimeout(window.opener.SC.connectCallback, 1); + } } }); diff --git a/server/public/assets/js/list.js b/server/public/assets/js/list.js index 9db5ac3a..80023d14 100755 --- a/server/public/assets/js/list.js +++ b/server/public/assets/js/list.js @@ -7,6 +7,7 @@ var List = { uris: [], not_found: [], num_songs: 0, + found: [], channel_function: function(msg) { if(user_auth_started) { @@ -605,6 +606,68 @@ var List = { return true; }, + exportToSoundCloud: function(thisSong, i) { + if(thisSong == undefined) { + if(full_playlist.length > 0) { + List.exportToSoundCloud(full_playlist[0], 1); + } + } else if(i != undefined && i == full_playlist.length) { + SC_player.post('/playlists', { + playlist: { + title: decodeURIComponent(channel.toLowerCase()) + ' - Zoff', + tracks: List.found, + sharing: "public" + } + }).then(function(result) { + console.log(result, List.found, List.not_found); + List.found = []; + List.not_found = []; + }); + } else if(thisSong != undefined && i != undefined) { + var isFound = false; + if(thisSong.source == "soundcloud") { + List.found.push({id: thisSong.id}); + List.exportToSoundCloud(full_playlist[i+1], i+1); + } else { + thisSong.title = Helper.replaceForFind(thisSong.title); + SC_player.get('/tracks', { + q: thisSong.title + }).then(function(tracks) { + //$("#results").append(result_html); + //Helper.css(document.querySelector(".search_results .col.s12"), "display", "block"); + for(var y = 0; y < tracks.length; y++) { + var song = tracks[y]; + if(!song.streamable) 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 title=song.title; + if(title.indexOf(song.user.username) == -1) { + title = song.user.username + " - " + title; + } + var id=song.id; + if(similarity(title, thisSong.track) > 0.60) { + List.found.push({id: song.id}); + isFound = true; + break; + } + } + } + if(!isFound) { + List.not_found.push(full_playlist[i].title); + } + List.exportToSoundCloud(full_playlist[i+1], i+1); + }).catch(function(e) { + List.not_found.push(full_playlist[i].title); + List.exportToSoundCloud(full_playlist[i+1], i+1); + }); + } + } + + }, + exportToSpotify: function() { ga('send', 'event', "export", "spotify"); diff --git a/server/public/assets/js/listeners.js b/server/public/assets/js/listeners.js index 19752ccd..199a55ca 100755 --- a/server/public/assets/js/listeners.js +++ b/server/public/assets/js/listeners.js @@ -954,7 +954,7 @@ function addDynamicListeners() { addListener("click", ".export-soundcloud", function(event) { this.preventDefault(); - var nonce = Helper.randomString(29); + /*var nonce = Helper.randomString(29); Helper.removeClass("#playlist_loader_export", "hide"); Helper.addClass(".soundcloud_export_button", "hide"); window.callback = function(data) { @@ -972,8 +972,12 @@ function addDynamicListeners() { soundcloud_window.close(); window.callback = ""; }; - soundcloud_window = window.open("/api/oauth#soundcloud=true&nonce=" + nonce, "", "width=600, height=600"); - }) + soundcloud_window = window.open("/api/oauth#soundcloud=true&nonce=" + nonce, "", "width=600, height=600");*/ + + SC_player.connect({"display":"page"}).then(function() { + List.exportToSoundCloud(); + }); + }); addListener("click", ".export-spotify-auth", function(event){ this.preventDefault(); diff --git a/server/public/assets/js/player.js b/server/public/assets/js/player.js index 022a628c..944cc2f0 100755 --- a/server/public/assets/js/player.js +++ b/server/public/assets/js/player.js @@ -1148,7 +1148,8 @@ var Player = { try { if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) { SC_player.initialize({ - client_id: api_key.soundcloud + client_id: api_key.soundcloud, + redirect_uri: "https://zoff.me/api/oauth", }); sc_initialized = true; Player.soundcloudReady(); @@ -1170,7 +1171,8 @@ var Player = { SC_player = SC; if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) { SC_player.initialize({ - client_id: api_key.soundcloud + client_id: api_key.soundcloud, + redirect_uri: "https://zoff.me/api/oauth", }); sc_initialized = true; Player.soundcloudReady(); @@ -1183,7 +1185,8 @@ var Player = { SC_player = SC; if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) { SC_player.initialize({ - client_id: api_key.soundcloud + client_id: api_key.soundcloud, + redirect_uri: "https://zoff.me/api/oauth", }); sc_initialized = true; Player.soundcloudReady(); @@ -1202,7 +1205,8 @@ var Player = { try { if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) { SC_player.initialize({ - client_id: api_key.soundcloud + client_id: api_key.soundcloud, + redirect_uri: "https://zoff.me/api/oauth", }); sc_initialized = true; Player.soundcloudReady(); @@ -1222,7 +1226,8 @@ var Player = { SC_widget = SC; if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) { SC_player.initialize({ - client_id: api_key.soundcloud + client_id: api_key.soundcloud, + redirect_uri: "https://zoff.me/api/oauth", }); sc_initialized = true; Player.soundcloudReady(); @@ -1234,7 +1239,8 @@ var Player = { SC_widget = SC; if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) { SC_player.initialize({ - client_id: api_key.soundcloud + client_id: api_key.soundcloud, + redirect_uri: "https://zoff.me/api/oauth", }); sc_initialized = true; Player.soundcloudReady(); diff --git a/server/public/partials/channel/panel.handlebars b/server/public/partials/channel/panel.handlebars index b25330d2..8e493051 100755 --- a/server/public/partials/channel/panel.handlebars +++ b/server/public/partials/channel/panel.handlebars @@ -267,8 +267,10 @@
  • -
    -

    Exporting to SoundCloud is in the works.

    +