MusicManager — Music Manager API client

class MusicManager(username=None, uploader_id=None, *, session=None, token=None, token_handler=<class 'google_music.token_handlers.FileTokenHandler'>, token_handler_kwargs=None)[source]

API wrapper class to access Google Music Music Manager functionality.

>>> from google_music import MusicManager
>>> mm = MusicManager('username')
Parameters
  • username (str, Optional) – Your Google Music username. Used to store OAuth tokens for multiple accounts separately.

  • uploader_id (str, Optional) – A unique uploader ID. Default: MAC address and username used.

  • session (GoogleMusicSession, Optional) – A session compatible with GoogleMusicSession.

  • token (dict, Optional) – An OAuth token compatible with oauthlib.

  • token_handler (TokenHandler, Optional) – A token handler class compatible with TokenHandler for dumping and loading the OAuth token.

  • token_handler_kwargs (dict, Optional) – Keyword arguments to pass to the token_handler class. These become attributes on the class instance.

property uploader_id

The uploader ID of the MusicManager instance.

property uploader_name

The uploader name of the MusicManager instance.

download(song)[source]

Download a song from a Google Music library.

Parameters

song (dict) – A song dict.

Returns

Song content as bytestring, suggested filename.

Return type

tuple

quota()[source]

Get the uploaded track count and allowance.

Returns

Number of uploaded tracks, number of tracks allowed.

Return type

tuple

songs(*, uploaded=True, purchased=True)[source]

Get a listing of Music Library songs.

Returns

Song dicts.

Return type

list

songs_iter(*, continuation_token=None, export_type=1)[source]

Get a paged iterator of Music Library songs.

Parameters
  • continuation_token (str, Optional) – The token of the page to return. Default: Not sent to get first page.

  • export_type (int, Optional) – The type of tracks to return. 1 for all tracks, 2 for promotional and purchased. Default: 1

Yields

list – Song dicts.

upload(song, *, album_art_path=None, no_sample=False)[source]

Upload a song to a Google Music library.

Parameters
  • song (os.PathLike or str or audio_metadata.Format) – The path to an audio file or an instance of audio_metadata.Format.

  • album_art_path (os.PathLike or str, Optional) – The relative filename or absolute filepath to external album art.

  • no_sample (bool, Optional) – Don’t generate an audio sample from song; send empty audio sample. Default: Create an audio sample using ffmpeg/avconv.

Returns

A result dict with keys: 'filepath', 'success', 'reason', and 'song_id' (if successful).

Return type

dict