Skip to content

Instantly share code, notes, and snippets.

@plurch
Created August 24, 2020 16:07
Show Gist options
  • Save plurch/97d36e4a96ce6abb8bfda05523defa6c to your computer and use it in GitHub Desktop.
Save plurch/97d36e4a96ce6abb8bfda05523defa6c to your computer and use it in GitHub Desktop.
// Some inspiration from
// https://github.com/patiek/GoMusPlaylistExport/blob/master/exporter.js
(async function() {
async function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let csvContent = '';
const scrolledTo = {}, indexed = {};
do {
const rows = document.querySelectorAll('tr.song-row');
rows.forEach(row => {
const entryId = row.getAttribute('data-id');
if(indexed[entryId]) return;
const entry =
[
entryId,
row.querySelector('td[data-col="index"]').textContent.trim(),
row.querySelector('td[data-col="title"]').textContent.trim(),
row.querySelector('td[data-col="artist"]').textContent.trim(),
row.querySelector('td[data-col="album"]').textContent.trim(),
row.querySelector('td[data-col="duration"]').textContent.trim(),
row.querySelector('td[data-col="play-count"]').textContent.trim()
].map(i => `"${i}"`).join(',');
indexed[entryId] = true;
csvContent += `${entry}\n`;
});
const last = rows[rows.length - 1];
const lastId = last.getAttribute('data-id');
if(scrolledTo[lastId]) {
break;
}
last.scrollIntoView();
scrolledTo[lastId] = true;
await delay(2000);
} while (true);
console.log(csvContent);
console.log(`indexed count: ${Object.keys(indexed).length}`);
const downloadAnchor = document.createElement('a');
const downloadBlob = new Blob([csvContent], {'type': 'text/csv'});
downloadAnchor.href = window.URL.createObjectURL(downloadBlob);
downloadAnchor.download = `${document.querySelector('h2[slot="title"]').textContent}.csv`;
downloadAnchor.click();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment