Skip to content

Instantly share code, notes, and snippets.

@blha303
Last active September 24, 2018 03:38
Show Gist options
  • Save blha303/7ce3edd2783a64254527fb27f34c59a3 to your computer and use it in GitHub Desktop.
Save blha303/7ce3edd2783a64254527fb27f34c59a3 to your computer and use it in GitHub Desktop.
A gmusicapi script
#!/usr/bin/env python3
import subprocess,gmusicapi,sys,mutagen,os
c = gmusicapi.Mobileclient()
c.login(os.environ["GMUSICAPI_EMAIL"], os.environ["GMUSICAPI_PASSWORD"], os.environ["GMUSICAPI_MACADDR"])
for track in c.get_album_info(sys.argv[1], include_tracks=True)["tracks"]:
try:
fn = "{trackNumber:0>2} {artist} - {title}.mp3".format(**track).replace("/", "-")
print(fn)
p = subprocess.run(["wget", c.get_stream_url(track["storeId"]), "-O", fn], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
f = mutagen.File(fn, easy=True)
for x in ["title", "artist", "album", "trackNumber"]:
if track[x]:
f[x.lower()] = str(track[x]).zfill(2)
f.save()
except KeyError:
print("Error on {artist} - {song}".format(**track))
continue
except IndexError:
print("Error on {artist} - {song} index".format(**track))
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment