Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GMusicAPI playing IFL
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import, unicode_literals
from builtins import * # noqa
from getpass import getpass
from gmusicapi import Mobileclient
def ask_for_credentials():
"""Make an instance of the api and attempts to login with it.
Return the authenticated api.
"""
# We're not going to upload anything, so the Mobileclient is what we want.
api = Mobileclient()
logged_in = False
attempts = 0
while not logged_in and attempts < 3:
email = input('Email: ')
password = getpass()
logged_in = api.login(email, password, Mobileclient.FROM_MAC_ADDRESS)
attempts += 1
return api
def demonstrate():
"""Demonstrate some api features."""
api = ask_for_credentials()
if not api.is_authenticated():
print("Sorry, those credentials weren't accepted.")
return
print('Successfully logged in.')
print()
station = api.get_station_tracks('IFL')
print('got station')
print()
# Show some info about a song. There is no guaranteed order;
# this is essentially a random song.
song = station[0]
print("Song I see is '{}' by '{}'.".format(song['title'], song['artist']))
song = station[1]
print("Song I see is '{}' by '{}'.".format(song['title'], song['artist']))
song = station[2]
print("Song I see is '{}' by '{}'.".format(song['title'], song['artist']))
song = station[3]
print("Song I see is '{}' by '{}'.".format(song['title'], song['artist']))
song = station[4]
print("Song I see is '{}' by '{}'.".format(song['title'], song['artist']))
song = station[5]
print("Song I see is '{}' by '{}'.".format(song['title'], song['artist']))
# It's good practice to logout when finished.
api.logout()
print('All done!')
if __name__ == '__main__':
demonstrate()
$ pip show gmusicapi
Name: gmusicapi
Version: 10.1.0
Summary: An unofficial api for Google Play Music.
Home-page: http://pypi.python.org/pypi/gmusicapi/
Author: Simon Weber
Author-email: simon@simonmweber.com
License: Copyright (c) 2015, Simon Weber
Location: /home/rektide/.local/lib/python2.7/site-packages
Requires: oauth2client, decorator, proboscis, validictory, mutagen, future, requests, six, gpsoauth, MechanicalSoup, python-dateutil, appdirs, protobuf, mock
@rektide

This comment has been minimized.

Copy link
Owner Author

@rektide rektide commented Jan 9, 2017

Trying to sort out what's going on with simon-weber/gmusicapi#393 and gmusicproxy/gmusicproxy#46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment