-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from deckerego/gmusic
Google Music and Bug Fixes
- Loading branch information
Showing
18 changed files
with
255 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ Source: hackclock | |
Maintainer: DeckerEgo <[email protected]> | ||
Section: python | ||
Priority: optional | ||
Build-Depends: python-all (>= 2.6.6-3), debhelper (>= 7.4.3) | ||
Build-Depends: python-setuptools (>= 2.6.6-3), debhelper (>= 7.4.3) | ||
Standards-Version: 3.9.1 | ||
X-Python-Version: >= 2.7 | ||
|
||
|
||
|
||
Package: python-hackclock | ||
Architecture: all | ||
Depends: ${misc:Depends}, ${python:Depends}, ntp, python-bottle, 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 |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
{ | ||
"default_editor": "/blocks/edit", | ||
"disable_editor_button": false, | ||
"buttons_gpio": [23, 24], | ||
"switches_gpio": [25], | ||
"weather_station": "KGPI", | ||
"ifttt_maker_key": "", | ||
"google_username": "", | ||
"google_password": "", | ||
"python_file": "/home/pi/hack-clock/run_clock.py", | ||
"blocks_file": "/home/pi/hack-clock/blocks_clock.xml", | ||
"audio_files": "/home/pi/hack-clock/audio", | ||
"backup_files": "/home/pi/hack-clock/backups", | ||
"lesson_files": "/home/pi/hack-clock/lessons", | ||
"webapp_files": "/srv/hackclock", | ||
"file_filter": ["README.md", ".DS_Store"], | ||
"buttons_gpio": [23, 24], | ||
"switches_gpio": [25] | ||
"file_filter": ["README.md", ".DS_Store"] | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from gmusicapi import Mobileclient | ||
from gmusicapi import exceptions | ||
import logging | ||
from hackclock.config import configuration | ||
import json | ||
|
||
logger = logging.getLogger('google_music') | ||
|
||
console = logging.StreamHandler() | ||
console.setLevel(logging.WARNING) | ||
logger.addHandler(console) | ||
|
||
class AudioStream: | ||
__username = configuration.get('google_username') | ||
__password = configuration.get('google_password') | ||
__track_prefetch = 15 | ||
__client = None | ||
__playlist = [] | ||
|
||
def __init__(self, station_id = 'IFL'): | ||
self.__client = Mobileclient() | ||
self.__client.login(self.__username, self.__password, Mobileclient.FROM_MAC_ADDRESS) | ||
self.__playlist = self.__fetchTrackIDs(station_id) | ||
|
||
def __del__(self): | ||
if self.__client: | ||
self.__client.logout() | ||
|
||
def __fetchTrackIDs(self, station_id): | ||
if not self.__client or not self.__client.is_authenticated(): | ||
logger.error("Client is not authenticated!") | ||
return [] | ||
|
||
tracklist = self.__client.get_station_tracks(station_id, num_tracks=self.__track_prefetch) | ||
logger.info("Received tracks: %r" % json.dumps(tracklist)) | ||
|
||
songids = [track['id'] for track in tracklist if 'id' in track] | ||
nautids = [track['nid'] for track in tracklist if 'nid' in track] | ||
|
||
return songids + nautids | ||
|
||
def pop(self): | ||
while self.__playlist: | ||
try: | ||
track_id = self.__playlist.pop() | ||
stream_url = self.__client.get_stream_url(track_id, quality='low') | ||
return stream_url | ||
except(exceptions.CallFailure): | ||
logger.warning("Failed to fetch Stream URL for ID %s" % trackid) | ||
|
||
raise IndexError("pop from empty list") | ||
|
||
def reverse(self): | ||
# Reverse just returns itself, since the playlist is already chaos | ||
return self | ||
|
||
def __len__(self): | ||
return len(self.__playlist) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
bitstring>=3.1.3 | ||
wiringpi2>=2.23.1 | ||
gmusicapi>=10.1.0 |
This file contains 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
This file contains 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
Oops, something went wrong.