-
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.
Changed Google Music to have its stream act more like a list, since t…
…he URLs expire in 60s
- Loading branch information
Showing
9 changed files
with
63 additions
and
45 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 |
---|---|---|
@@ -1,35 +1,58 @@ | ||
from gmusicapi import Mobileclient | ||
from GStreamer import Speaker | ||
from gmusicapi import exceptions | ||
import logging | ||
from hackclock.config import configuration | ||
import json | ||
|
||
logger = logging.getLogger('google_music') | ||
|
||
console = logging.StreamHandler() | ||
console.setLevel(logging.INFO) | ||
console.setLevel(logging.WARNING) | ||
logger.addHandler(console) | ||
|
||
class GoogleMusic: | ||
class AudioStream: | ||
__username = configuration.get('google_username') | ||
__password = configuration.get('google_password') | ||
__track_prefetch = 25 | ||
__track_prefetch = 15 | ||
__client = None | ||
__playlist = [] | ||
|
||
def __init__(self): | ||
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 radioPlaylist(self, station_id = 'IFL'): | ||
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" % str(tracklist)) | ||
logger.info("Received tracks: %r" % json.dumps(tracklist)) | ||
|
||
trackidlist = [track['id'] for track in tracklist if 'id' in track] | ||
return [self.__client.get_stream_url(trackid, quality='low') for trackid in trackidlist] | ||
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
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 was deleted.
Oops, something went wrong.
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,4 +1,5 @@ | ||
#!/bin/sh | ||
|
||
amixer set PCM -- 100% | ||
speaker-test -c 2 | ||
rm ~/.asoundrc | ||
amixer set Master -- 100% | ||
speaker-test -c2 -twav |