Adicionando skills para tocar mais musicas do artista/album que esta sendo tocado no momento
Some checks failed
Documentation Generator / Build Sphinx documentation (push) Has been cancelled
Some checks failed
Documentation Generator / Build Sphinx documentation (push) Has been cancelled
This commit is contained in:
17
alexa.json
17
alexa.json
@@ -73,6 +73,14 @@
|
|||||||
"Tocar o disco {album} da {artist}"
|
"Tocar o disco {album} da {artist}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "NaviSonicPlayMusicByCurrentAlbum",
|
||||||
|
"slots": [],
|
||||||
|
"samples": [
|
||||||
|
"Tocar mais músicas desse album",
|
||||||
|
"Tocar mais músicas desse disco"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "NaviSonicPlayPlaylist",
|
"name": "NaviSonicPlayPlaylist",
|
||||||
"slots": [
|
"slots": [
|
||||||
@@ -138,6 +146,15 @@
|
|||||||
"Tocar {song} da {artist}"
|
"Tocar {song} da {artist}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "NaviSonicPlayMusicByCurrentArtist",
|
||||||
|
"slots": [],
|
||||||
|
"samples": [
|
||||||
|
"Tocar mais músicas desse artista",
|
||||||
|
"Tocar mais músicas desse grupo",
|
||||||
|
"Tocar mais músicas dessa banda"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "NaviSonicPlayFavouriteSongs",
|
"name": "NaviSonicPlayFavouriteSongs",
|
||||||
"slots": [],
|
"slots": [],
|
||||||
|
|||||||
76
skill/app.py
76
skill/app.py
@@ -341,6 +341,82 @@ class NaviSonicPlayMusicByArtist(AbstractRequestHandler):
|
|||||||
track_details = play_queue.get_next_track()
|
track_details = play_queue.get_next_track()
|
||||||
return controller.start_playback('play', speech, card, track_details, handler_input)
|
return controller.start_playback('play', speech, card, track_details, handler_input)
|
||||||
|
|
||||||
|
def get_current_song_details():
|
||||||
|
current_track = play_queue.get_current_track()
|
||||||
|
return {
|
||||||
|
"title": current_track.title,
|
||||||
|
"artist": current_track.artist,
|
||||||
|
"album": current_track.album,
|
||||||
|
"_sanitized": {
|
||||||
|
"title": sanitise_speech_output(current_track.title),
|
||||||
|
"artist": sanitise_speech_output(current_track.artist),
|
||||||
|
"album": sanitise_speech_output(current_track.album)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NaviSonicPlayMusicByCurrentArtist(AbstractRequestHandler):
|
||||||
|
"""Handle NaviSonicPlayMusicByCurrentArtist Intent
|
||||||
|
|
||||||
|
Plays more music of the current playing Artist
|
||||||
|
"""
|
||||||
|
|
||||||
|
def can_handle(self, handler_input: HandlerInput) -> bool:
|
||||||
|
return is_intent_name('NaviSonicPlayMusicByCurrentArtist')(handler_input)
|
||||||
|
|
||||||
|
def handle(self, handler_input: HandlerInput) -> Response:
|
||||||
|
logger.debug('In NaviSonicPlayMusicByCurrentArtist Handler')
|
||||||
|
|
||||||
|
t = get_current_song_details() #current "T"rack
|
||||||
|
|
||||||
|
artist_lookup = connection.search_artist(t["artist"])
|
||||||
|
artist_album_lookup = connection.albums_by_artist(artist_lookup[0].get('id'))
|
||||||
|
song_id_list = connection.build_song_list_from_albums(artist_album_lookup, min_song_count)
|
||||||
|
play_queue.clear()
|
||||||
|
|
||||||
|
if backgroundProcess is not None:
|
||||||
|
backgroundProcess.terminate()
|
||||||
|
backgroundProcess.join()
|
||||||
|
|
||||||
|
controller.enqueue_songs(connection, play_queue, [song_id_list[0], song_id_list[1]]) # When generating the playlist return the first two tracks.
|
||||||
|
backgroundProcess = Process(target=queue_worker_thread, args=(connection, play_queue, song_id_list[2:])) # Create a thread to enqueue the remaining tracks
|
||||||
|
backgroundProcess.start() # Start the additional thread
|
||||||
|
|
||||||
|
text = f'Tocando mais músicas de {t["_sanitized"]["artist"]}'
|
||||||
|
handler_input.response_builder.speak(text)
|
||||||
|
return handler_input.response_builder.response
|
||||||
|
|
||||||
|
class NaviSonicPlayMusicByCurrentAlbum(AbstractRequestHandler):
|
||||||
|
"""Handle NaviSonicPlayMusicByCurrentAlbum Intent
|
||||||
|
|
||||||
|
Plays more music of the current playing Album
|
||||||
|
"""
|
||||||
|
|
||||||
|
def can_handle(self, handler_input: HandlerInput) -> bool:
|
||||||
|
return is_intent_name('NaviSonicPlayMusicByCurrentAlbum')(handler_input)
|
||||||
|
|
||||||
|
def handle(self, handler_input: HandlerInput) -> Response:
|
||||||
|
logger.debug('In NaviSonicPlayMusicByCurrentAlbum Handler')
|
||||||
|
|
||||||
|
t = get_current_song_details() #current "T"rack
|
||||||
|
|
||||||
|
artist_lookup = connection.search_artist(t["artist"])
|
||||||
|
artist_album_lookup = connection.albums_by_artist(artist_lookup[0].get('id'))
|
||||||
|
result = [album_result for album_result in artist_album_lookup if album_result.get('name').lower() == t["album"].lower()]
|
||||||
|
|
||||||
|
song_id_list = connection.build_song_list_from_albums(result, -1)
|
||||||
|
play_queue.clear()
|
||||||
|
|
||||||
|
if backgroundProcess is not None:
|
||||||
|
backgroundProcess.terminate()
|
||||||
|
backgroundProcess.join()
|
||||||
|
|
||||||
|
controller.enqueue_songs(connection, play_queue, [song_id_list[0], song_id_list[1]]) # When generating the playlist return the first two tracks.
|
||||||
|
backgroundProcess = Process(target=queue_worker_thread, args=(connection, play_queue, song_id_list[2:])) # Create a thread to enqueue the remaining tracks
|
||||||
|
backgroundProcess.start() # Start the additional thread
|
||||||
|
|
||||||
|
text = f'Tocando mais músicas de do album {t["_sanitized"]["album"]}'
|
||||||
|
handler_input.response_builder.speak(text)
|
||||||
|
return handler_input.response_builder.response
|
||||||
|
|
||||||
class NaviSonicPlayAlbumByArtist(AbstractRequestHandler):
|
class NaviSonicPlayAlbumByArtist(AbstractRequestHandler):
|
||||||
"""Handle NaviSonicPlayAlbumByArtist
|
"""Handle NaviSonicPlayAlbumByArtist
|
||||||
|
|||||||
Reference in New Issue
Block a user