Last active
January 9, 2017 01:41
-
-
Save rektide/98e894c86bb1eeb5f3b40405e16d718e to your computer and use it in GitHub Desktop.
GMusicAPI playing IFL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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: [email protected] | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to sort out what's going on with simon-weber/gmusicapi#393 and gmusicproxy/gmusicproxy#46