mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Merge pull request #433 from zoff-music/feature/export-soundcloud
Feature/export soundcloud
This commit is contained in:
@@ -394,7 +394,7 @@ li.disabled span {
|
|||||||
width: 76%;
|
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;
|
background: #f96200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,9 @@ window.addEventListener("load", function() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
window.opener.callback(query_parameters);
|
window.opener.callback(query_parameters);
|
||||||
} catch(e) {}
|
} catch(e) {
|
||||||
|
window.setTimeout(window.opener.SC_player.connectCallback, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ var List = {
|
|||||||
uris: [],
|
uris: [],
|
||||||
not_found: [],
|
not_found: [],
|
||||||
num_songs: 0,
|
num_songs: 0,
|
||||||
|
found: [],
|
||||||
|
|
||||||
channel_function: function(msg) {
|
channel_function: function(msg) {
|
||||||
if(user_auth_started) {
|
if(user_auth_started) {
|
||||||
@@ -605,6 +606,104 @@ var List = {
|
|||||||
return true;
|
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() {
|
exportToSpotify: function() {
|
||||||
ga('send', 'event', "export", "spotify");
|
ga('send', 'event', "export", "spotify");
|
||||||
|
|
||||||
@@ -768,7 +867,7 @@ var List = {
|
|||||||
Helper.addClass("#playlist_loader_export", "hide");
|
Helper.addClass("#playlist_loader_export", "hide");
|
||||||
}
|
}
|
||||||
if(document.querySelectorAll(".exported-spotify-list").length == 0) {
|
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++) {
|
for(var i = 0; i < List.not_found.length; i++) {
|
||||||
var data = List.not_found[i];
|
var data = List.not_found[i];
|
||||||
@@ -878,7 +977,7 @@ var List = {
|
|||||||
if(num == full_playlist.length - 1){
|
if(num == full_playlist.length - 1){
|
||||||
Helper.log(["All videoes added!"]);
|
Helper.log(["All videoes added!"]);
|
||||||
Helper.log(["url: https://www.youtube.com/playlist?list=" + playlist_id]);
|
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("#playlist_loader_export", "hide");
|
||||||
Helper.addClass(".current_number", "hide");
|
Helper.addClass(".current_number", "hide");
|
||||||
//$(".youtube_export_button").removeClass("hide");
|
//$(".youtube_export_button").removeClass("hide");
|
||||||
|
|||||||
@@ -954,26 +954,15 @@ function addDynamicListeners() {
|
|||||||
|
|
||||||
addListener("click", ".export-soundcloud", function(event) {
|
addListener("click", ".export-soundcloud", function(event) {
|
||||||
this.preventDefault();
|
this.preventDefault();
|
||||||
var nonce = Helper.randomString(29);
|
window.SC_player = SC_player;
|
||||||
Helper.removeClass("#playlist_loader_export", "hide");
|
SC_player.connect({"display":"page"}).then(function() {
|
||||||
Helper.addClass(".soundcloud_export_button", "hide");
|
Helper.removeClass("#playlist_loader_export", "hide");
|
||||||
window.callback = function(data) {
|
Helper.addClass(".soundcloud-export-button", "hide");
|
||||||
access_token_data_soundcloud = data;
|
Helper.removeClass(".exported-list-container", "hide");
|
||||||
if(access_token_data_soundcloud.state == nonce){
|
List.exportToSoundCloud();
|
||||||
soundcloud_authenticated = true;
|
delete window.SC_player;
|
||||||
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");
|
|
||||||
})
|
|
||||||
|
|
||||||
addListener("click", ".export-spotify-auth", function(event){
|
addListener("click", ".export-spotify-auth", function(event){
|
||||||
this.preventDefault();
|
this.preventDefault();
|
||||||
@@ -1042,7 +1031,7 @@ function addDynamicListeners() {
|
|||||||
document.querySelector("#import_soundcloud").focus();
|
document.querySelector("#import_soundcloud").focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*addListener("submit", "#listImportSoundCloud", function(event) {
|
addListener("submit", "#listImportSoundCloud", function(event) {
|
||||||
this.preventDefault();
|
this.preventDefault();
|
||||||
Helper.removeClass(".playlist_loader_soundcloud", "hide");
|
Helper.removeClass(".playlist_loader_soundcloud", "hide");
|
||||||
Helper.addClass("#listImportSoundCloud", "hide");
|
Helper.addClass("#listImportSoundCloud", "hide");
|
||||||
@@ -1097,21 +1086,18 @@ function addDynamicListeners() {
|
|||||||
}
|
}
|
||||||
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
||||||
Helper.removeClass("#listImportSoundCloud", "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) {
|
} catch(e) {
|
||||||
console.error(e);
|
|
||||||
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
||||||
Helper.removeClass("#listImportSoundCloud", "hide");
|
Helper.removeClass("#listImportSoundCloud", "hide");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(data) {
|
error: function(data) {
|
||||||
console.log(data);
|
|
||||||
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
||||||
Helper.removeClass("#listImportSoundCloud", "hide");
|
Helper.removeClass("#listImportSoundCloud", "hide");
|
||||||
toast("If the list is private, you have to add the secret code at the end");
|
toast("If the list is private, you have to add the secret code at the end");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});*/
|
});
|
||||||
|
|
||||||
addListener("submit", "#listImportSpotify", function(event){
|
addListener("submit", "#listImportSpotify", function(event){
|
||||||
this.preventDefault();
|
this.preventDefault();
|
||||||
|
|||||||
@@ -1148,7 +1148,8 @@ var Player = {
|
|||||||
try {
|
try {
|
||||||
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
||||||
SC_player.initialize({
|
SC_player.initialize({
|
||||||
client_id: api_key.soundcloud
|
client_id: api_key.soundcloud,
|
||||||
|
redirect_uri: "https://zoff.me/api/oauth",
|
||||||
});
|
});
|
||||||
sc_initialized = true;
|
sc_initialized = true;
|
||||||
Player.soundcloudReady();
|
Player.soundcloudReady();
|
||||||
@@ -1170,7 +1171,8 @@ var Player = {
|
|||||||
SC_player = SC;
|
SC_player = SC;
|
||||||
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
||||||
SC_player.initialize({
|
SC_player.initialize({
|
||||||
client_id: api_key.soundcloud
|
client_id: api_key.soundcloud,
|
||||||
|
redirect_uri: "https://zoff.me/api/oauth",
|
||||||
});
|
});
|
||||||
sc_initialized = true;
|
sc_initialized = true;
|
||||||
Player.soundcloudReady();
|
Player.soundcloudReady();
|
||||||
@@ -1183,7 +1185,8 @@ var Player = {
|
|||||||
SC_player = SC;
|
SC_player = SC;
|
||||||
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
||||||
SC_player.initialize({
|
SC_player.initialize({
|
||||||
client_id: api_key.soundcloud
|
client_id: api_key.soundcloud,
|
||||||
|
redirect_uri: "https://zoff.me/api/oauth",
|
||||||
});
|
});
|
||||||
sc_initialized = true;
|
sc_initialized = true;
|
||||||
Player.soundcloudReady();
|
Player.soundcloudReady();
|
||||||
@@ -1202,7 +1205,8 @@ var Player = {
|
|||||||
try {
|
try {
|
||||||
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
||||||
SC_player.initialize({
|
SC_player.initialize({
|
||||||
client_id: api_key.soundcloud
|
client_id: api_key.soundcloud,
|
||||||
|
redirect_uri: "https://zoff.me/api/oauth",
|
||||||
});
|
});
|
||||||
sc_initialized = true;
|
sc_initialized = true;
|
||||||
Player.soundcloudReady();
|
Player.soundcloudReady();
|
||||||
@@ -1222,7 +1226,8 @@ var Player = {
|
|||||||
SC_widget = SC;
|
SC_widget = SC;
|
||||||
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
||||||
SC_player.initialize({
|
SC_player.initialize({
|
||||||
client_id: api_key.soundcloud
|
client_id: api_key.soundcloud,
|
||||||
|
redirect_uri: "https://zoff.me/api/oauth",
|
||||||
});
|
});
|
||||||
sc_initialized = true;
|
sc_initialized = true;
|
||||||
Player.soundcloudReady();
|
Player.soundcloudReady();
|
||||||
@@ -1234,7 +1239,8 @@ var Player = {
|
|||||||
SC_widget = SC;
|
SC_widget = SC;
|
||||||
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
if(SC_player != null && SC_player != undefined && SC_widget != null && SC_widget != undefined && !sc_initialized) {
|
||||||
SC_player.initialize({
|
SC_player.initialize({
|
||||||
client_id: api_key.soundcloud
|
client_id: api_key.soundcloud,
|
||||||
|
redirect_uri: "https://zoff.me/api/oauth",
|
||||||
});
|
});
|
||||||
sc_initialized = true;
|
sc_initialized = true;
|
||||||
Player.soundcloudReady();
|
Player.soundcloudReady();
|
||||||
|
|||||||
@@ -267,8 +267,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="white-bg">
|
<li class="white-bg">
|
||||||
<div class="input-field field-settings">
|
<div class="input-field field-settings soundcloud-export-button export-buttons">
|
||||||
<p class="soundcloud-disclaimer">Exporting to SoundCloud is in the works.</p>
|
<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>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="exported-list-container white-bg hide">
|
<li class="exported-list-container white-bg hide">
|
||||||
|
|||||||
Reference in New Issue
Block a user