gp.py

Google Play Music integration via gmusicapi.

class clay.gp.Artist(artist_id, name)[source]

Model that represents an artist.

__init__(artist_id, name)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__weakref__

list of weak references to the object (if defined)

classmethod from_data(data, many=False)[source]

Construct and return one or many Artist instances from Google Play Music API response.

id

Artist ID.

class clay.gp.LikedSongs[source]

A local model that represents the songs that a user liked and displays them as a faux playlist.

This mirrors the “liked songs” generated playlist feature of the Google Play Music apps.

__init__()[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__weakref__

list of weak references to the object (if defined)

add_liked_song(song)[source]

Add a liked song to the list.

remove_liked_song(song)[source]

Remove a liked song from the list

tracks

Get a sorted list of liked tracks.

class clay.gp.Playlist(playlist_id, name, tracks)[source]

Model that represents remotely stored (Google Play Music) playlist.

__init__(playlist_id, name, tracks)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__weakref__

list of weak references to the object (if defined)

classmethod from_data(data, many=False)[source]

Construct and return one or many Playlist instances from Google Play Music API response.

id

Playlist ID.

class clay.gp.SearchResults(tracks, artists)[source]

Model that represents search results including artists & tracks.

__init__(tracks, artists)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__weakref__

list of weak references to the object (if defined)

classmethod from_data(data)[source]

Construct and return SearchResults instance from raw data.

get_artists()[source]

Return found artists.

get_tracks()[source]

Return found tracks.

class clay.gp.Station(station_id, name)[source]

Model that represents specific station on Google Play Music.

__init__(station_id, name)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__weakref__

list of weak references to the object (if defined)

classmethod from_data(data, many=False)[source]

Construct and return one or many Station instances from Google Play Music API response.

get_tracks()[source]

Return a list of tracks in this station.

id

Station ID.

load_tracks()[source]

Fetch tracks related to this station and populate it with Track instances.

load_tracks_async(**kwargs)

Inner function.

class clay.gp.Track(source, data)[source]

Model that represents single track from Google Play Music.

__eq__(other)[source]

x.__eq__(y) <==> x==y

__init__(source, data)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__repr__()

x.__str__() <==> str(x)

__str__() <==> str(x)[source]
__weakref__

list of weak references to the object (if defined)

add_to_my_library()[source]

Add a track to my library.

add_to_my_library_async(**kwargs)

Inner function.

create_station(**kwargs)[source]

Inner function.

create_station_async(**kwargs)

Inner function.

filename

Return a filename for this track.

classmethod from_data(data, source, many=False)[source]

Construct and return one or many Track instances from Google Play Music API response.

get_artist_art_filename(**kwargs)[source]

Inner function.

get_url(callback)[source]

Gets playable stream URL for this track.

“callback” is called with “(url, error)” args after URL is fetched.

Keep in mind this URL is valid for a limited time.

id

Return ID for this track.

rate_song(rating)[source]

Rate the song either 0 (no thumb), 1 (down thumb) or 5 (up thumb).

remove_from_my_library()[source]

Remove a track from my library.

remove_from_my_library_async(**kwargs)

Inner function.

class clay.gp._GP[source]

Interface to gmusicapi.Mobileclient. Implements asynchronous API calls, caching and some other perks.

Singleton.

__init__()[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__weakref__

list of weak references to the object (if defined)

_make_call_proxy(func)[source]

Return a function that wraps fn and logs args & return values.

add_to_my_library(track)[source]

Add a track to my library.

get_all_tracks(**kwargs)[source]

Inner function.

get_all_tracks_async(**kwargs)

Inner function.

get_all_user_playlist_contents(**kwargs)[source]

Inner function.

get_all_user_playlist_contents_async(**kwargs)

Inner function.

get_all_user_station_contents(**kwargs)[source]

Inner function.

get_all_user_station_contents_async(**kwargs)

Inner function.

get_authtoken()[source]

Return currently active auth token.

get_cached_tracks_map()[source]

Return a dictionary of tracks where keys are strings with track IDs and values are Track instances.

get_stream_url(stream_id)[source]

Returns playable stream URL of track by id.

get_stream_url_async(**kwargs)

Inner function.

get_track_by_id(any_id)[source]

Return track by id or store_id.

invalidate_caches()[source]

Clear cached tracks & playlists & stations.

is_authenticated

Return True if user is authenticated on Google Play Music, false otherwise.

is_subscribed

Return True if user is subscribed on Google Play Music, false otherwise.

login(**kwargs)[source]

Inner function.

login_async(**kwargs)

Inner function.

remove_from_my_library(track)[source]

Remove a track from my library.

search(query)[source]

Find tracks and return an instance of SearchResults.

search_async(**kwargs)

Inner function.

use_authtoken(**kwargs)[source]

Inner function.

use_authtoken_async(**kwargs)

Inner function.

clay.gp.asynchronous(func)[source]

Decorates a function to become asynchronous.

Once called, runs original function in a new Thread.

Must be called with a ‘callback’ argument that will be called once thread with original function finishes. Receives two args: result and error.

  • “result” contains function return value or None if there was an exception.
  • “error” contains None or Exception if there was one.
clay.gp.synchronized(func)[source]

Decorates a function to become thread-safe by preventing it from being executed multiple times before previous calls end.

Lock is acquired on entrance and is released on return or Exception.