Skip to content

Instantly share code, notes, and snippets.

@nickscript0
Created December 15, 2018 19:47
Show Gist options
  • Save nickscript0/d09fe0d2839c33540c5a13af3dc93171 to your computer and use it in GitHub Desktop.
Save nickscript0/d09fe0d2839c33540c5a13af3dc93171 to your computer and use it in GitHub Desktop.
Improvement to export_google_music.js gist
// After running this guy's Google Play Music export https://gist.github.com/dcalacci/7f8853174797c0c56c49
// His export to CSV function doesn't format the lines properly
// Paste the following function in the console and run 'songsToCsv(all_songs)'
function songsToCsv(data) {
const out = [];
const seen = new Set();
const keys = [
'artist', 'album', 'title', 'duration', 'playcount', 'rating'
];
const buildString = d => keys.map(k => `"${d[k].trim()}"`).join(',')
for (const d of data) {
const row = buildString(d);
if (!seen.has(row)) {
out.push(row);
seen.add(row);
}
}
out.unshift(keys.join(','));
copy(out.join('\n'));
console.log(`Copied ${out.length} lines to the clipboard!`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment