Created
December 15, 2018 19:47
-
-
Save nickscript0/d09fe0d2839c33540c5a13af3dc93171 to your computer and use it in GitHub Desktop.
Improvement to export_google_music.js gist
This file contains hidden or 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
// 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