Last active 1551993911

A script to upload music to Google Play Music

S Smith revised this gist 1552029910. Go to revision

1 file changed, 24 insertions, 6 deletions

gmusicupload.py

@@ -2,26 +2,44 @@
2 2 from gmusicapi import Musicmanager # pip install gmusicapi
3 3 from glob import glob
4 4 from argparse import ArgumentParser
5 + from sys import stderr
6 + from urllib.parse import quote_plus
5 7
6 8 m = Musicmanager()
7 9 if not m.login():
8 10 m.perform_oauth()
9 11 m.login()
10 12
13 + def upload(path):
14 + uploaded,matched,not_uploaded = m.upload(path)
15 + completed_ids = set()
16 + for fn,_id in uploaded.items():
17 + completed_ids.add(_id)
18 + for fn,_id in matched.items():
19 + completed_ids.add(_id)
20 + for fn,_id in not_uploaded.items():
21 + print("{} not uploaded: {}".format(fn,_id), file=stderr)
22 + return completed_ids
23 +
11 24 def main():
12 25 parser = ArgumentParser()
13 26 parser.add_argument("files", nargs="+", help="Files to upload")
14 27 args = parser.parse_args()
28 + completed_ids = set()
15 29 for file in args.files:
16 30 if '*' in file:
17 31 for subfile in glob(file):
18 - print("Starting on {}...".format(subfile), end="\r")
19 - m.upload(subfile)
20 - print("Completed {} ".format(subfile))
32 + completed_ids.update(upload(subfile))
33 + else:
34 + completed_ids.update(upload(file))
35 + all_songs = {song["id"]:song for song in m.get_uploaded_songs() if song["id"] in completed_ids}
36 + albums = set()
37 + for _id in completed_ids:
38 + if _id[0] == "T": # gmusic track
39 + print("https://play.google.com/music/m/{}".format(_id))
21 40 else:
22 - print("Starting on {}...".format(file), end="\r")
23 - m.upload(file)
24 - print("Completed {} ".format(file))
41 + albums.add("https://play.google.com/music/listen#/album///" + quote_plus(all_songs[_id]["album"]))
42 + print("\n".join(albums))
25 43
26 44 if __name__ == "__main__":
27 45 main()

Steven Smith revised this gist 1473318142. Go to revision

1 file changed, 27 insertions

gmusicupload.py(file created)

@@ -0,0 +1,27 @@
1 + #!/usr/bin/env python3
2 + from gmusicapi import Musicmanager # pip install gmusicapi
3 + from glob import glob
4 + from argparse import ArgumentParser
5 +
6 + m = Musicmanager()
7 + if not m.login():
8 + m.perform_oauth()
9 + m.login()
10 +
11 + def main():
12 + parser = ArgumentParser()
13 + parser.add_argument("files", nargs="+", help="Files to upload")
14 + args = parser.parse_args()
15 + for file in args.files:
16 + if '*' in file:
17 + for subfile in glob(file):
18 + print("Starting on {}...".format(subfile), end="\r")
19 + m.upload(subfile)
20 + print("Completed {} ".format(subfile))
21 + else:
22 + print("Starting on {}...".format(file), end="\r")
23 + m.upload(file)
24 + print("Completed {} ".format(file))
25 +
26 + if __name__ == "__main__":
27 + main()
Newer Older