~vesto/geemusic

265425cfcf0e1c23c5cac2df4002ebd21aaeee40 — Dublin Anondson 4 years ago 5f1a829 + bbb79a8
Merge pull request #7 from stevenleeg/master

merging in latest fixes. 
3 files changed, 24 insertions(+), 12 deletions(-)

M geemusic/controllers.py
M geemusic/intents/playback.py
M geemusic/utils/music.py
M geemusic/controllers.py => geemusic/controllers.py +0 -9
@@ 41,15 41,6 @@ def index():
@app.route("/alexa/stream/<song_id>")
def redirect_to_stream(song_id):
    stream_url = api.get_google_stream_url(song_id)
    # Scrobble if Last.fm is setup
    if environ.get('LAST_FM_ACTIVE'):
        from .utils import last_fm
        song_info = api.get_song_data(song_id)
        last_fm.scrobble(
            song_info['title'],
            song_info['artist'],
            environ['LAST_FM_SESSION_KEY']
        )

    app.logger.debug('URL is %s' % stream_url)
    req = requests.get(stream_url, stream=False)

M geemusic/intents/playback.py => geemusic/intents/playback.py +14 -0
@@ 1,6 1,7 @@
from flask import render_template
from flask_ask import statement, audio
from geemusic import ask, queue, app, api
from os import environ
import json




@@ 40,6 41,19 @@ def nearly_finished():

@ask.on_playback_finished()
def finished():
    # Scrobble if Last.fm is setup
    if environ.get('LAST_FM_ACTIVE'):
        song_info = queue.current_track()

        if song_info is not None and 'title' in song_info and 'artist' in song_info:
            from ..utils import last_fm

            last_fm.scrobble(
                song_info['title'],
                song_info['artist'],
                environ['LAST_FM_SESSION_KEY']
            )

    queue.next()
    return empty_response()


M geemusic/utils/music.py => geemusic/utils/music.py +10 -3
@@ 95,10 95,13 @@ class GMusicWrapper(object):
            if score < 70:
                return False
            for song_id, song in self.library.items():
                if 'artist' in song and song['artist'].lower() == likely_artist.lower():
                if 'artist' in song and song['artist'].lower() == likely_artist.lower() and 'artistId' in song:
                    if not search['topTracks']:  # First entry
                        # Copy artist details from the first song into the general artist response
                        search['artistArtRef'] = song['artistArtRef'][0]['url']
                        try:
                            search['artistArtRef'] = song['artistArtRef'][0]['url']
                        except KeyError:
                            pass
                        search['name'] = song['artist']
                        search['artistId'] = song['artistId']
                    search['topTracks'].append(song)


@@ 135,7 138,11 @@ class GMusicWrapper(object):
                        if not search['tracks']:  # First entry
                            search['albumArtist'] = song['albumArtist']
                            search['name'] = song['album']
                            search['albumId'] = song['albumId']
                            try:
                                search['albumId'] = song['albumId']
                            except KeyError:
                                pass

                        search['tracks'].append(song)
            if not search['tracks']:
                return False