Exporting to soundcloud tests

This commit is contained in:
Kasper Rynning-Tønnesen
2018-10-23 12:33:27 +02:00
parent 8f46eabbaf
commit 71f1826435
5 changed files with 89 additions and 12 deletions

View File

@@ -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);
}
}
});

View File

@@ -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");

View File

@@ -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();

View File

@@ -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();

View File

@@ -267,8 +267,10 @@
</div>
</li>
<li class="white-bg">
<div class="input-field field-settings">
<p class="soundcloud-disclaimer">Exporting to SoundCloud is in the works.</p>
<div class="input-field field-settings soundcloud-export-button export-buttons">
<a class="waves-effect btn export-soundcloud" title="Export to SoundCloud">
<img src="https://developers.soundcloud.com/assets/powered_by_large_white-9c2af6a93ad2b1c541f423d9e9045980.png" class="left soundcloud_logo" alt="SoundCloud Logo" />SoundCloud
</a>
</div>
</li>
<li class="exported-list-container white-bg hide">