Setting up a Google Play Music uploader for Linux Servers

THIS POST HAS BEEN SUPERCEEDED.

I like having an online music server. At home, I use a Logitech Media Server (formerly Squeezebox Server) [1] and run my several O2 Jogglers around the house with the “Squeezeplay OS” [2] images to play music from that server, but when it comes to an Android tablet (or Android phone), there’s not that joined-up thinking from Logitech (although you can just about cobble it together using a few 3rd party apps [3]), but what I do like is the Google Play Music service.

Google Play Music [4] was the first product from the Google Play team after they rebranded to “Google Play”, and I pretty quickly got interested in it. I installed the Google Play Uploader [5] on my home server, and uploaded all my music (apparently, I’m up to 12,000 tracks, but I think there are some duplicates there!) but what to do about the rest of the family? Well, until just recently, it didn’t matter. Jules has no interest in playing music on her phone or tablet, and Daniel, well, he’s 3-and-a-bit.

Since pretty early on, he’s been all over our tech – initially just using whatever apps we had installed on Jules’ and my phones, then Jules’ tablet (I was, and still am, pretty cautious about him using my tablet as it’s an Asus TF300T [6] which cost quite a lot of money, and I keep toying with the idea of installing some other OS – like Firefox OS [7] or Ubuntu Touch [8] on there and can’t if it’s wrecked), and now he’s pretty comfortable with browsing YouTube or the Play Store, although he knows not to click on adverts and can’t install anything that costs anything.

In the last couple of months, since he’s been really learning how to spell, he’s been asking how to spell the names of his favourite films (“Oliver!”, “Frozen” and “The Polar Express” primarily) to get the film clips up in YouTube, or to play snippets from the soundtracks of the films… which got me thinking. I can’t really do much about the films (not yet at least!), but perhaps I could set up Google Play Music with the soundtracks he listens to… but I already have one account sync’ed with Google Play Music from my media server…. how do I get his stuff set up on there?

Essentially, Google Play Music Uploader is a GUI application that can’t be started in the CLI (which kinda makes sense from a simplicity perspective), but as I’m already running one instance of the application on my media server, I can’t start up a second one, so what do I do?

Well, as it turns out, there’s actually a python library for interacting with Google Play Music’s upload and download applications called “gmusicapi” [9], and this couples with a really nice wrapper gives me a CLI utility I can run in a CRON job on my media server.

The wrapper is called gmusicapi-scripts [10], which contains 3 utilities – gmdownload.py, gmsync.py and the key to this – gmupload.py.

You need to install a few libraries. On my Ubuntu 14.04 system, I needed to run:

sudo apt-get install python-pip avconv-tools
sudo pip install gmusicapi
sudo pip install docopt

Once you’ve got this, you can get the tools themselves like this:

git clone https://github.com/thebigmunch/gmusicapi-scripts.git

This will give you a folder called gmusicapi-scripts in which is gmupload.py – the first time you run it, it’ll ask you to visit a web page in order to register the client. Click “OK” to approve the library having access to Google Play Music. This is a pretty spartan page, and ends up with a grey text box containing a string. Copy the contents of that box back into your terminal, and hey-presto, you get it working…

Well, sort of. For me, because I’d not set Daniel up with Google Play Music yet, I needed to set up his account first. I didn’t realise this (I thought, just going to the web page the script points you to will get you access, but it doesn’t because they need to vet which country you’re accessing from…) and the script didn’t tell me that (it just kept saying “Not Subscribed” [11])

Anyway, once it’s done you run

~/gmusicapi-scripts/gmupload.py /path/to/file.mp3

( 1/1) Successfully uploaded /path/to/file.mp3

If you’ve got multiple users, you can rename ~/.local/share/gmusicapi/oauth.cred to ~/.local/share/gmusicapi/SomeOtherName.cred and then run

~/gmusicapi-scripts/gmupload.py -c SomeOtherName /path/to/file.mp3

Subsequent passes will prompt you to authenticate the next account as you go, and then you can rename them as appropriate.

[1] Logitech Media Server (formerly Squeezebox Server): http://www.mysqueezebox.com/download
[2] “Squeezeplay OS”: http://birdslikewires.co.uk/articles/squeezeplay-os
[3] a few 3rd party apps: I got it working on my TF300T by combining https://play.google.com/store/apps/details?id=de.bluegaspode.squeezeplayer and https://play.google.com/store/apps/details?id=de.cedata.android.squeezecommander
[4] Google Play Music: https://play.google.com/music
[5] Google Play Uploader: https://play.google.com/music/listen?u=0#/manager
[6] TF300T: http://en.wikipedia.org/wiki/Asus_Transformer_Pad_TF300T
[7] Firefox OS: https://www.mozilla.org/en-US/firefox/os/
[8] Ubuntu Touch: http://www.ubuntu.com/tablet
[9] “gmusicapi”: https://github.com/simon-weber/Unofficial-Google-Music-API
[10] gmusicapi-scripts: https://github.com/thebigmunch/gmusicapi-scripts
[11] “Not Subscribed”: I raised a bug, but the lead developer said it seemed obvious to him that you have to set it up first… not disputing that for the first pass, but a nice message would have been good :) https://github.com/thebigmunch/gmusicapi-scripts/issues/22

JonTheNiceGuy

He/Him. Husband and father. Linux advocating geek. Co-Host on the AdminAdmin Podcast, occasional conference speaker.

8 thoughts to “Setting up a Google Play Music uploader for Linux Servers”

  1. This is exactly what I was looking for.
    Question: do you think this would work in a Arch Linux ARM based system? I’m referring to the “confirmation page” part.
    If I drop additional *.mp3 files in the local server will I be able to have a cron job sync everything or do I have to manually use the upload.py script?

    1. Hey Paolo! Thanks for dropping in on this. So, you get pointed to a URL, which you can browse to from any machine (much like the DropBox cli, or any other OAuth systems) but it doesn’t need to be on the same box.

      Regarding the files, I’m sure you could do something with inotify or the cronjob you mentioned, but I’m not sure how well that works. I just run it by hand whenever something new needs loading! If you get something cool working, please get back in touch :)

      Jon

  2. Ho Jon, thanks for replying back.
    I played around a bit with the RPi today but due to a series of circumstances (some of which foreseeable, others not so much) I decided to start from scratch again.
    I now have everything installed on the Pi but I need to do all other steps.
    I’ll try the cron jobs way and report back.

  3. Hi Jon
    I dropped Arch Linux ARM in favor of Raspbian Lite: too many problems even before playing with the gmusicapi (2014 *.img as a starting base, only way possible if you don’t have any other linux based system around, an update of the distro introduces many things I lost too much time to figure out and my Raspberry doesn’t even boot anymore after!).
    Now, with Raspbian is a lot easier but I’m still having a lot of issues mainly due to my lack of experience with git and mercurial cloning.
    In addition, it looks to me you need a lot more packages to make the whole thing work: python 3.4 was required, as well as mutagen.
    Also the gmusicapi-wrapper was mandatory.

    Could you please help me out a bit in getting this right?
    I was able to clone all repositories but I don’t know if I have to install them..?
    All the cloned files from the repos have to be merged into one single directory?

    I actually copied the gmusicapi-wrapper.py file in the gmusicapi_script folder to bypass a “not found” issue, but what about mutagen??

    pi@raspberrypi:~/gmusicapi-scripts/gmusicapi_scripts $ ./gmupload.py “/tmp/Bombay\ Bicycle\ Club/”
    Traceback (most recent call last):
    File “./gmupload.py”, line 50, in
    from gmusicapi_wrapper import MusicManagerWrapper
    File “/home/pi/gmusicapi-scripts/gmusicapi_scripts/gmusicapi_wrapper.py”, line 10, in
    import mutagen
    ImportError: No module named ‘mutagen’

    Thanks in advance

    1. Awesome. Now all I need to do is to understand Docker! :)

      I had a quick look at that Gitlab, and I can’t see how to dig into what that actually produces, but again, that might be because I don’t understand Docker. Anyway, thanks for the post – that’s really useful!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.