Last active
October 11, 2024 23:45
-
-
Save Thomasvdam/3208bd212ce71dd0bf66db52ac6e9ac8 to your computer and use it in GitHub Desktop.
Copy SoundCloud playlist items from one to another.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Configuration | |
const WAIT_OPEN_PLAYLIST_POPUP = 1000; | |
const WAIT_AFTER_ADD_PLAYLIST = 1500; | |
const TARGET_PLAYLIST_NAME = 'To Do'; | |
// Should the new playlist be in reverse order? | |
const REVERSE = false; | |
// Should liked items be skipped? | |
const SKIP_LIKED = true; | |
// Implementation | |
const delta = REVERSE ? -1 : 1; | |
const nextIndex = (index) => index + delta; | |
const listItems = Array.from(document.querySelectorAll('.sc-button-group.sc-button-group-small')); | |
const addItemToPlaylist = (index) => { | |
const node = listItems[index]; | |
if (!node) { | |
console.log('Done with all currently loaded items.'); | |
return; | |
} | |
if (SKIP_LIKED) { | |
const hasLikedButton = node.querySelector('.sc-button-like.sc-button-selected'); | |
if (hasLikedButton) { | |
console.log('Already liked index: ', index); | |
setTimeout(() => { | |
addItemToPlaylist(nextIndex(index)); | |
}, 0); | |
return; | |
} | |
} | |
node.querySelector('.sc-button-more').click(); | |
document.querySelector('button.sc-button-addtoset').click(); | |
setTimeout(() => { | |
const playlistRow = Array.from(document.querySelectorAll('.addToPlaylistList__item')).find(node => node.querySelector(`[title="${TARGET_PLAYLIST_NAME}"]`)); | |
const playListButton = playlistRow.querySelector('button.addToPlaylistButton:not(.sc-button-selected)'); | |
if (!playListButton) { | |
console.log('Already added index: ', index); | |
setTimeout(() => { | |
addItemToPlaylist(nextIndex(index)); | |
}, 0); | |
return; | |
} | |
playListButton.click(); | |
console.log('Added index: ', index); | |
setTimeout(() => { | |
addItemToPlaylist(nextIndex(index)); | |
}, WAIT_AFTER_ADD_PLAYLIST); | |
}, WAIT_OPEN_PLAYLIST_POPUP); | |
}; | |
if (REVERSE) { | |
addItemToPlaylist(listItems.length - 1); | |
} else { | |
addItemToPlaylist(0); | |
} |
With these few changes got it to work.
const WAIT_OPEN_PLAYLIST_POPUP = 1500; // Increased the wait time
const WAIT_AFTER_ADD_PLAYLIST = 2000; // Increased the wait time
const TARGET_PLAYLIST_NAME = 'my playlist'; // Changed name to an already saved playlist
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you from the bottom of my heart