Created
May 12, 2020 21:54
-
-
Save jrconlin/835295703070a6e0a127ff19e870c925 to your computer and use it in GitHub Desktop.
Google Music Playlist JSON reader
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
# Convert the output of a Google Music Playlist JSON dump to a CSV. | |
# | |
# To get the playlist JSON output: | |
# * Open your browser's dev tools | |
# * Go to the Google Music Playlist you want to dump. | |
# * Search your "Network" calls for `https://play.google.com/music/services/loaduserplaylist` | |
# * Save the JSON returned from that call as `your_playlist.json` | |
# (Note, you can sometimes just re-open that URL in a new tab and dump the page). | |
# | |
# Run this script: `python as_csv.py your_playlist.json > your_playlist.csv` | |
# | |
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | |
# If a copy of the MPL was not distributed with this file, You can obtain one at | |
# https://mozilla.org/MPL/2.0/. | |
import json | |
import os | |
import argparse | |
def args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("data", help="GMusic JSON file") | |
args = parser.parse_args() | |
return args | |
def esc(word): | |
if not word: | |
word = "" | |
word.replace('"', '\\"') | |
word.replace('|','\\|') | |
return word | |
def parse(args): | |
ff = open(args.data) | |
data = json.load(ff) | |
print("Artist|Title|Album|Cover Art") | |
for record in data[1][0]: | |
(guid, title, cover, artist, album, *data) = record | |
print ('"{artist}"|"{title}"|"{album}"|"{cover}"'.format( | |
artist=esc(artist), | |
title=esc(title), | |
album=esc(album), | |
cover=esc(cover), | |
)) | |
if __name__ == "__main__": | |
parse(args()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment