Skip to content

Instantly share code, notes, and snippets.

@felixgirault
Last active November 23, 2018 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixgirault/b9048dfb41a1382fb0c37ca64514bcb5 to your computer and use it in GitHub Desktop.
Save felixgirault/b9048dfb41a1382fb0c37ca64514bcb5 to your computer and use it in GitHub Desktop.
To save your Deezer collection to a JSON file, open your favorite tracks (like https://www.deezer.com/en/profile/1725967/loved) and run this script in the console.
(async () => {
const keys = [];
const songs = [];
const index = () => {
const rows = $('.datagrid-row');
rows.each((i, el) => {
const row = $(el);
const key = row.attr('data-key');
if (key && !keys.includes(key)) {
keys.push(key);
songs.push({
key,
title: row.find('.cell-title').text(),
artist: row.find('.cell-artist').text(),
album: row.find('.cell-album').text(),
duration: row.find('.cell-duration').text(),
added: row.find('.cell-date').text()
});
}
});
};
const wait = (ms) =>
new Promise((resolve) => {
setTimeout(resolve, ms)
});
const walk = async (cb, step, delay) => {
window.scrollTo(0, step);
await wait(delay);
cb();
let scrollY;
do {
scrollY = window.scrollY
window.scrollBy(0, step);
await wait(delay);
cb();
} while (scrollY !== window.scrollY);
};
const save = () => {
const json = JSON.stringify(songs, null, ' ');
const blob = new Blob([json], {
type : 'application/json'
});
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'deezer-collection.json';
link.style.display = 'none';
document.body.appendChild(link);
link.click();
setTimeout(() => {
document.body.removeChild(link);
URL.revokeObjectURL(url);
}, 0);
};
await walk(index, 500, 200);
save();
})();
@felixgirault
Copy link
Author

Ok this was stupid!
There's a public API: https://api.deezer.com/user/1725967/tracks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment