View on GitHub

GMusic Proxy

Stream Google Play Music To Any Device

GMusicProxy - Google Play Music Proxy

“Let’s stream Google Play Music using any media-player”

GitHub release (latest SemVer) Python Versions

contributors:

License: GPL v3

About

This program permits the use of Google Play Music with All Access subscription with any music player that is able to stream MP3 files and to manage playlists (e.g., MPD server, VLC, …). It can work also with a free account without All Access extras.

Google has a music service with the possibility to stream all the available music using an All Access subscription. The Google-way to listen your collection and the stations is by means of Android devices, web browser, or Chromecast devices to integrate with TVs or HiFi audio systems. These devices are typically closed or limited in someway. Many people use music-systems based on Raspberry-PIs, MPD, or other software and GMP provide an integration point.

The project is based on the great Unofficial Google Play Music API by Simon Weber: it already permits to create URLs to stream the tracks as regular MP3 but they expire in 1 minute! Keeping this proxy running, it can generate persistent local URLs that never expire and that can be used in any media-player.

This project is not supported nor endorsed by Google. Its aim is not the abuse of the service but the one to improve the access to it. The maintainers are not responsible for misuse.

Features

URL-based interface

The only way to use the service is to query the proxy by means of properly formatted HTTP requests over the configured TCP port. Such URLs can be used directly in music programs or in scripts or in any browser. A URL looks like this: http://host:port/command?param_1=value&param_2=value. Validation on submitted values is minimal, please be aware.

Consider that any song, album, artist, playlist or station got a unique ID in Google Music API but there are many methods to discover them.

Here a list of the supported requests (with some restricted by the availability of a All Access subscription):

Common request options

The proxy supports common options for responses:

Note: these parameters are not valid for get_song.

Examples:

# request XSPF/XML format
curl http://[gmp host|ip]:9999/get_all_playlists?format=xsfp
# request shuffled output
curl http://[gmp host|ip]:9999/get_all_playlists?shuffle=yes
# Return playlist with 10 items
curl http://[gmp host|ip]:9999/get_all_playlists?num_tracks=10

Output Format

Beginning with version 2.2.0, Accept headers should be the preferred way to request a specific output format. e.g. for JSON:

curl -H 'Accept: application/json' http://[gmp host|ip]:9999/get_all_playlists

The format parameter can be used to generate output in the following formats:

Changelog

Support

Issues

Feel free to open bug reports (complete of verbose output produced with options --debug and --log) on GitHub, to fork the project and to make pull requests for your contributions.

Setup

Requirements

Installation

The following instructions have a Debian/Ubuntu GNU/Linux system as reference: nevertheless they work on any other GNU/Linux system using the right substitute of apt-get. It is known to work also on Mac OS X and Windows systems.

In order to build/install GMusicProxy, the following should work on Ubuntu/Debian based systems:

sudo apt install python3 python3-dev git
git clone https://github.com/gmusicproxy:/gmusicproxy.git
cd gmusicproxy
virtualenv -p python3.8 venv
. venv/bin/activate
pip install -r requirements.txt
python GMusicProxy

Usage

With the service running on a computer on the LAN, it can be used by any others of the same network.

To use the proxy, you first need to login via OAuth2. If you haven’t authorized gmusicapi yet (or the credentials were revoked or deleted), when you first launch GMusicProxy, your browser will open letting you login and authorize gmusicapi. If no browser is available, the URL printed out can be used to login. After this, OAuth2 credentials (not your email and password) are cached to disk so future uses don’t require you to login again.

Another useful information would be the device ID of an Android/iOS device registered in your account: you can discover it using the option --list-devices on the command-line. As default a fake-id, based on the mac address of the main network card of the server running the service, is used.

You can provide such necessary information, as well as other options, on the command-line of the program or using a configuration file.

Command-line

Here a list of the supported options on the command-line:

Config file

All the command-line options can be specified in a configuration file. An example of configuration with the strictly required options could look like this:

email = my.email@gmail.com
password = my-secret-password
device-id = 54bbd32a309a34ef

When the proxy is launched, it searches for a file named gmusicproxy.cfg in the XDG-compliant folders like /home/USER/.config/ or /etc/xdg/. It is possible to specify an arbitrary config file on the command-line using the option --config.

Examples of integration

MPD

You can copy any M3U list generated by the proxy in the playlists registered inside MPD. MPD usually keeps the playlists inside the folder specified by playlist_directory in its configuration file mpd.conf.

curl -s 'http://localhost:9999/get_by_search?type=album&artist=Queen&title=Greatest%20Hits' > /var/lib/mpd/playlists/queen.m3u
mpc load queen
mpc play

You can also request a fresh list of songs from a station and add them to the current playlist.

mpc clear
curl -s 'http://localhost:9999/get_new_station_by_search?type=artist&artist=Queen&num_tracks=100' | grep -v "^#" | while read url; do mpc add "$url"; done
mpc play

You can add an XSPF playlist to mpd, which provides better metadata:

mpc load "http://localhost:9999/get_top_songs?format=xspf"

VLC

You can listen any generated playlist using VLC from command-line.

vlc 'http://localhost:9999/get_by_search?type=album&artist=Rolling%20Stones&title=tattoo&exact=no'

With the addition of XSPF playlists, better metadata is provided:

vlc 'http://localhost:9999/get_top_songs?format=xspf'

You can automatically choose at random one registered station.

curl -s 'http://localhost:9999/get_all_stations?format=text&only_url=yes' | sort -R | head -n1 | vlc -

Docker

Official Docker builds are available on Docker Hub. To build and run the Docker container, follow these steps:

docker build -t gmusicproxy:latest .
# Note that OAuth is the preferred login method 
# You may need to run interactively (-it) in order to
# establish your credentials.
# Replace /path/for/oauthcreds with a directory for oauth token storage
docker run -it -p 9999:9999 -v /path/for/oauthcreds:/root/.local/share/gmusicapi gmusicproxy:latest
# Once OAuth is established, run normally:
docker run -v /path/for/oauthcreds:/root/.local/share/gmusicapi -p 9999:9999 gmusicproxy:latest

Other Docker Examples

Running as daemon

docker run -d -p 9999:9999 -v /path/for/oauthcreds:/root/.local/share/gmusicapi gmusicproxy/gmusicproxy:VERSION

Running on port 80 with a different Host/IP in the URLs. Note the required -T argument

docker run -p 80:9999 -v /path/for/oauthcreds:/root/.local/share/gmusicapi gmusicproxy/gmusicproxy:VERSION -T 80