Merge pull request #433 from zoff-music/feature/export-soundcloud

Feature/export soundcloud
This commit is contained in:
Kasper Rynning-Tønnesen
2018-10-23 13:33:16 +02:00
committed by GitHub
6 changed files with 132 additions and 37 deletions

View File

@@ -394,7 +394,7 @@ li.disabled span {
width: 76%;
}
.import-soundcloud, .import-soundcloud:active, .import-soundcloud:visited, .export-soundcloud:visited {
.import-soundcloud, .import-soundcloud:active, .import-soundcloud:visited, .export-soundcloud, .export-soundcloud:visited, .exported-soundcloud-list {
background: #f96200;
}

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_player.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,104 @@ var List = {
return true;
},
exportToSoundCloud: function(thisSong, i) {
if(i >= full_playlist.length) {
if(List.found.length == 0) {
for(var x = 0; x < List.not_found.length; x++) {
var data = List.not_found[x];
var not_added_song = document.createElement("div");
not_added_song.innerHTML = not_export_html;
not_added_song.querySelector(".extra-add-text").setAttribute("value", data);
not_added_song.querySelector(".extra-add-text").setAttribute("title", data);
document.querySelector(".not-exported-container").insertAdjacentHTML("beforeend", not_added_song.innerHTML);
}
Helper.removeClass(".not-exported", "hide");
Helper.addClass(".current_number", "hide");
Helper.addClass("#playlist_loader_export", "hide");
Helper.addClass(".exported-list-container", "hide");
List.found = [];
List.not_found = [];
} else {
SC_player.post('/playlists', {
playlist: {
title: chan.toLowerCase() + " - Zoff",
tracks: List.found,
description: "Playlist exported from https://zoff.me/" + Helper.encodeChannelName(chan.toLowerCase()),
}
}).then(function(result) {
for(var x = 0; x < List.not_found.length; x++) {
var data = List.not_found[x];
var not_added_song = document.createElement("div");
not_added_song.innerHTML = not_export_html;
not_added_song.querySelector(".extra-add-text").setAttribute("value", data);
not_added_song.querySelector(".extra-add-text").setAttribute("title", data);
document.querySelector(".not-exported-container").insertAdjacentHTML("beforeend", not_added_song.innerHTML);
}
Helper.addClass(".current_number", "hide");
Helper.addClass("#playlist_loader_export", "hide");
Helper.addClass(".exported-list-container", "hide");
document.querySelector(".exported-list").insertAdjacentHTML("beforeend", "<a target='_blank' class='btn light exported-playlist exported-soundcloud-list' href='" + result.permalink_url + "'>" + result.title + "</a>");
Helper.removeClass(".not-exported", "hide");
toast("List exported!");
List.found = [];
List.not_found = [];
}).catch(function(error) {
console.log(error);
});
}
} else if(thisSong == undefined) {
if(full_playlist.length > 0) {
List.exportToSoundCloud(full_playlist[0], 0);
}
} else if(thisSong != undefined && i != undefined) {
var isFound = false;
Helper.removeClass(".current_number", "hide");
document.querySelector(".current_number").innerText = (i) + " of " + (full_playlist.length);
if(thisSong.source == "soundcloud") {
List.found.push({id: parseInt(thisSong.id)});
List.exportToSoundCloud(full_playlist[i+1], i+1);
} else {
var _title = thisSong.title;
_title = Helper.replaceForFind(_title);
SC_player.get('/tracks', {
q: _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;
}
title = title.toLowerCase();
var id=song.id;
if(similarity(title, _title) > 0.60) {
List.found.push({id: parseInt(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");
@@ -768,7 +867,7 @@ var List = {
Helper.addClass("#playlist_loader_export", "hide");
}
if(document.querySelectorAll(".exported-spotify-list").length == 0) {
document.querySelector(".exported-list").insertAdjacentHTML("beforeend", "<a target='_blank' class='btn light exported-playlist exported-spotify-list' href='https://open.spotify.com/user/" + user_id + "/playlist/"+ playlist_id + "'>" + chan + "</a>");
document.querySelector(".exported-list").insertAdjacentHTML("beforeend", "<a target='_blank' class='btn light green lighten exported-playlist exported-spotify-list' href='https://open.spotify.com/user/" + user_id + "/playlist/"+ playlist_id + "'>" + chan + "</a>");
}
for(var i = 0; i < List.not_found.length; i++) {
var data = List.not_found[i];
@@ -878,7 +977,7 @@ var List = {
if(num == full_playlist.length - 1){
Helper.log(["All videoes added!"]);
Helper.log(["url: https://www.youtube.com/playlist?list=" + playlist_id]);
document.querySelector(".exported-list").insertAdjacentHTML("beforeend", "<a target='_blank' class='btn light exported-playlist' href='https://www.youtube.com/playlist?list=" + playlist_id + "'>" + chan + "</a>");
document.querySelector(".exported-list").insertAdjacentHTML("beforeend", "<a target='_blank' class='btn light red exported-playlist' href='https://www.youtube.com/playlist?list=" + playlist_id + "'>" + chan + "</a>");
Helper.addClass("#playlist_loader_export", "hide");
Helper.addClass(".current_number", "hide");
//$(".youtube_export_button").removeClass("hide");

View File

@@ -954,26 +954,15 @@ function addDynamicListeners() {
addListener("click", ".export-soundcloud", function(event) {
this.preventDefault();
var nonce = Helper.randomString(29);
Helper.removeClass("#playlist_loader_export", "hide");
Helper.addClass(".soundcloud_export_button", "hide");
window.callback = function(data) {
access_token_data_soundcloud = data;
if(access_token_data_soundcloud.state == nonce){
soundcloud_authenticated = true;
Helper.removeClass("#playlist_loader_export", "hide");
Helper.addClass(".soundcloud_export_button", "hide");
} else {
access_token_data_soundcloud = {};
console.error("States doesn't match");
Helper.addClass("#playlist_loader_export", "hide");
Helper.removeClass(".soundcloud_export_button", "hide");
}
soundcloud_window.close();
window.callback = "";
};
soundcloud_window = window.open("/api/oauth#soundcloud=true&nonce=" + nonce, "", "width=600, height=600");
})
window.SC_player = SC_player;
SC_player.connect({"display":"page"}).then(function() {
Helper.removeClass("#playlist_loader_export", "hide");
Helper.addClass(".soundcloud-export-button", "hide");
Helper.removeClass(".exported-list-container", "hide");
List.exportToSoundCloud();
delete window.SC_player;
});
});
addListener("click", ".export-spotify-auth", function(event){
this.preventDefault();
@@ -1042,7 +1031,7 @@ function addDynamicListeners() {
document.querySelector("#import_soundcloud").focus();
});
/*addListener("submit", "#listImportSoundCloud", function(event) {
addListener("submit", "#listImportSoundCloud", function(event) {
this.preventDefault();
Helper.removeClass(".playlist_loader_soundcloud", "hide");
Helper.addClass("#listImportSoundCloud", "hide");
@@ -1097,21 +1086,18 @@ function addDynamicListeners() {
}
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(data) {
console.log(data);
Helper.addClass(".playlist_loader_soundcloud", "hide");
Helper.removeClass("#listImportSoundCloud", "hide");
toast("If the list is private, you have to add the secret code at the end");
}
});
});*/
});
addListener("submit", "#listImportSpotify", 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">