Skip to content

Commit

Permalink
Working version (kinda) of Google Music integration
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerego committed Feb 3, 2017
1 parent 83c9856 commit c251786
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ I'm assuming that you are starting with the Raspian Minimal Linux distribution.

1. Make sure your Raspberry Pi is up to date with the latest packages & firmware with `sudo apt-get update; sudo apt-get dist-upgrade`
2. Enable I2C by executing `sudo raspi-config` as described in Adafruit's tutorial: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
3. Add the necessary Python and GStreamer dependencies using the command: `sudo apt-get install wiringpi python-bottle python-protobuf python-requests python-oauth2client python-httplib2 python-setuptools python-pip python-dev python-dateutil python-smbus gstreamer0.10-x gstreamer-tools gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-bad python-gst0.10`
3. Add the necessary Python and GStreamer dependencies using the command: `sudo apt-get install wiringpi python-bottle python-requests python-oauth2client python-httplib2 python-setuptools python-pip python-dev python-dateutil python-smbus gstreamer0.10-x gstreamer-tools gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly python-gst0.10`
4. Install hack-clock via `wget https://github.com/deckerego/hack-clock/releases/download/2.0.0/python-hackclock_2.0.1-1_all.deb; sudo dpkg -i python-hackclock_2.0.1-1_all.deb`
5. Tweak `/etc/hack-clock.conf` and `/etc/default/hack-clock` to fit your needs (GPIO pins, correct weather station, etc.). A list of observed weather stations is available at http://forecast.weather.gov/stations.php
6. Reboot your Pi to re-load modules and start the IDE web server
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ X-Python-Version: >= 2.7

Package: python-hackclock
Architecture: all
Depends: ${misc:Depends}, ${python:Depends}, ntp, python-bottle, python-requests, python-protobuf, python-httplib2, python-oauth2client, wiringpi, python-setuptools, python-pip, python-dev, python-dateutil, python-smbus, gstreamer0.10-x, gstreamer-tools, gstreamer0.10-plugins-base, gstreamer0.10-plugins-good, gstreamer0.10-plugins-bad, python-gst0.10
Depends: ${misc:Depends}, ${python:Depends}, ntp, python-bottle, python-requests, python-httplib2, python-oauth2client, wiringpi, python-setuptools, python-pip, python-dev, python-dateutil, python-smbus, gstreamer0.10-x, gstreamer-tools, gstreamer0.10-plugins-base, gstreamer0.10-plugins-good, gstreamer0.10-plugins-bad, python-gst0.10
Description: A hackable alarm clock for the Raspberry Pi
10 changes: 6 additions & 4 deletions lib/hackclock/runapp/Libs/GoogleMusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
class GoogleMusic:
__username = configuration.get('google_username')
__password = configuration.get('google_password')
__track_prefetch = 10
__track_prefetch = 25
__client = None

def __init__(self):
self.__client = Mobileclient()
self.__client.login(username, password, Mobileclient.FROM_MAC_ADDRESS)
self.__client.login(self.__username, self.__password, Mobileclient.FROM_MAC_ADDRESS)

def __del__(self):
if self.__client:
Expand All @@ -28,6 +28,8 @@ def radioPlaylist(self, station_id = 'IFL'):
logger.error("Client is not authenticated!")
return []

tracklist = client.get_station_tracks(station_id, num_tracks=track_prefetch)
tracklist = self.__client.get_station_tracks(station_id, num_tracks=self.__track_prefetch)
logger.info("Received tracks: %r" % str(tracklist))

trackidlist = [track['id'] for track in tracklist if 'id' in track]
return [client.get_stream_url(trackid, quality='low') for trackid in trackidlist]
return [self.__client.get_stream_url(trackid, quality='low') for trackid in trackidlist]
2 changes: 1 addition & 1 deletion srv/hackclock/views/blocks/js/generators/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Blockly.Python['google_music_radio'] = function(block) {
Blockly.Python.definitions_['import_speaker'] = 'from hackclock.runapp.Libs.GStreamer import Speaker';
Blockly.Python.definitions_['import_googlemusic'] = 'from hackclock.runapp.Libs.GoogleMusic import GoogleMusic';
Blockly.Python.definitions_['init_speaker'] = 'speaker = Speaker()';
Blockly.Python.definitions_['init_googlemusic'] = 'google_music = GoogleMusic(speaker)';
Blockly.Python.definitions_['init_googlemusic'] = 'google_music = GoogleMusic()';

return ['google_music.radioPlaylist()', Blockly.Python.ORDER_NONE];
};
Expand Down
34 changes: 34 additions & 0 deletions tests/googlemusic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#/bin/python

print "Loading Libraries"
from GoogleMusic import GoogleMusic
import pygst
pygst.require('0.10')
import gst

def on_tag(bus, msg):
taglist = msg.parse_tag()
print 'on_tag:'
for key in taglist.keys():
print '\t%s = %s' % (key, taglist[key])

print "Initializing Google Music"
music = GoogleMusic()

print "Fetching Playlist"
playlist = music.radioPlaylist()
print playlist

print "Initializing Player"
player = gst.element_factory_make("playbin", "player")
player.set_state(gst.STATE_READY)
player.set_property('uri', playlist[0])
player.set_state(gst.STATE_PLAYING)

print "Monitoring Bus"
bus = player.get_bus()
bus.enable_sync_message_emission()
bus.add_signal_watch()
bus.connect('message::tag', on_tag)

raw_input('Press enter to stop playing...')

0 comments on commit c251786

Please sign in to comment.