Last active 1537724331

A gmusicapi script

Steven Smith revised this gist 1537760331. Go to revision

1 file changed, 2 insertions, 2 deletions

getgmusic.py

@@ -9,9 +9,9 @@ for track in c.get_album_info(sys.argv[1], include_tracks=True)["tracks"]:
9 9 print(fn)
10 10 p = subprocess.run(["wget", c.get_stream_url(track["storeId"]), "-O", fn], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
11 11 f = mutagen.File(fn, easy=True)
12 - for x in ["title", "artist", "album"]:
12 + for x in ["title", "artist", "album", "trackNumber"]:
13 13 if track[x]:
14 - f[x] = track[x]
14 + f[x.lower()] = str(track[x]).zfill(2)
15 15 f.save()
16 16 except KeyError:
17 17 print("Error on {artist} - {song}".format(**track))

Steven Smith revised this gist 1537760135. Go to revision

1 file changed, 21 insertions

getgmusic.py(file created)

@@ -0,0 +1,21 @@
1 + #!/usr/bin/env python3
2 + import subprocess,gmusicapi,sys,mutagen,os
3 + c = gmusicapi.Mobileclient()
4 + c.login(os.environ["GMUSICAPI_EMAIL"], os.environ["GMUSICAPI_PASSWORD"], os.environ["GMUSICAPI_MACADDR"])
5 +
6 + for track in c.get_album_info(sys.argv[1], include_tracks=True)["tracks"]:
7 + try:
8 + fn = "{trackNumber:0>2} {artist} - {title}.mp3".format(**track).replace("/", "-")
9 + print(fn)
10 + p = subprocess.run(["wget", c.get_stream_url(track["storeId"]), "-O", fn], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
11 + f = mutagen.File(fn, easy=True)
12 + for x in ["title", "artist", "album"]:
13 + if track[x]:
14 + f[x] = track[x]
15 + f.save()
16 + except KeyError:
17 + print("Error on {artist} - {song}".format(**track))
18 + continue
19 + except IndexError:
20 + print("Error on {artist} - {song} index".format(**track))
21 + continue
Newer Older