Compare commits

..

1 Commits

Author SHA1 Message Date
nunks 2ee1abd813 customizadas em portugues: interaction model e respostas da skill
Documentation Generator / Build Sphinx documentation (push) Has been cancelled
2025-11-08 12:50:08 -03:00
6 changed files with 90 additions and 116 deletions
+41 -50
View File
@@ -1,7 +1,7 @@
{ {
"interactionModel": { "interactionModel": {
"languageModel": { "languageModel": {
"invocationName": "navisonic", "invocationName": "cafofo music",
"intents": [ "intents": [
{ {
"name": "AMAZON.CancelIntent", "name": "AMAZON.CancelIntent",
@@ -40,8 +40,8 @@
} }
], ],
"samples": [ "samples": [
"play songs by {artist}", "tocar músicas da {artist}",
"play music by {artist}" "tocar músicas do {artist}"
] ]
}, },
{ {
@@ -65,8 +65,12 @@
} }
], ],
"samples": [ "samples": [
"Play the album {album}", "Tocar o album {album}",
"Play the album {album} by {artist}" "Tocar o album {album} do {artist}",
"Tocar o album {album} da {artist}",
"Tocar o disco {album}",
"Tocar o disco {album} do {artist}",
"Tocar o disco {album} da {artist}"
] ]
}, },
{ {
@@ -78,49 +82,42 @@
} }
], ],
"samples": [ "samples": [
"Play the {playlist} playlist", "Tocar a playlist {playlist}"
"Start the {playlist} playlist"
] ]
}, },
{ {
"name": "NaviSonicSongDetails", "name": "NaviSonicSongDetails",
"slots": [], "slots": [],
"samples": [ "samples": [
"What is playing", "O que está tocando",
"Who is singing", "Quem está tocando",
"Who's singing", "Quem está cantando",
"What album is this song on", "Qual o album dessa música",
"What album is this on", "Que banda é essa",
"Which album", "Que musica é essa",
"Which album is this song from", "Que banda é essa"
"Which artist is this",
"What band is this",
"Who sings this song",
"Who sings this",
"What song is this",
"What's playing"
] ]
}, },
{ {
"name": "NaviSonicStarSong", "name": "NaviSonicStarSong",
"slots": [], "slots": [],
"samples": [ "samples": [
"Add this song to my favourites", "Adicionar música aos favoritos",
"Favourite this song", "Adicionar aos favoritos",
"Like this song", "Favoritar essa musica",
"Add this song to my liked songs", "Lembrar dessa música",
"Star this song" "Eu gosto dessa música"
] ]
}, },
{ {
"name": "NaviSonicUnstarSong", "name": "NaviSonicUnstarSong",
"slots": [], "slots": [],
"samples": [ "samples": [
"Remove this song from favourites", "Tirar a música dos favoritos",
"I don't like this song", "Tirar dos favoritos",
"Remove the star from this song", "Desfavoritar a música",
"Delete this song from my favourites", "Esquecer essa música",
"Unstar this song" "Eu não gosto dessa música"
] ]
}, },
{ {
@@ -136,21 +133,18 @@
} }
], ],
"samples": [ "samples": [
"Play the song {song} by the band {artist}", "Tocar a música {song} da banda {artist}",
"Play {song} by the band {artist}", "Tocar {song} da banda {artist}",
"Play {song} by {artist}", "Tocar {song} da {artist}"
"Play the song {song} by the artist {artist}"
] ]
}, },
{ {
"name": "NaviSonicPlayFavouriteSongs", "name": "NaviSonicPlayFavouriteSongs",
"slots": [], "slots": [],
"samples": [ "samples": [
"Play my starred tracks", "Tocar favoritos",
"Play starred tracks", "Tocar meus favoritos",
"Play starred songs", "Tocar minhas músicas favoritas"
"Play my starred songs",
"Play my favourite songs"
] ]
}, },
{ {
@@ -162,29 +156,26 @@
} }
], ],
"samples": [ "samples": [
"Play {genre} songs", "Tocar {genre}"
"Play {genre} music"
] ]
}, },
{ {
"name": "NaviSonicPlayMusicRandom", "name": "NaviSonicPlayMusicRandom",
"slots": [], "slots": [],
"samples": [ "samples": [
"Play a selection of music", "Tocar seleção aleatória",
"Play a mix of tracks", "Tocar qualquer coisa",
"Play a mix of songs", "Tocar mix",
"Play random music", "Tocar músicas aleatórias"
"Play random songs"
] ]
}, },
{ {
"name": "NaviSonicRandomiseQueue", "name": "NaviSonicRandomiseQueue",
"slots": [], "slots": [],
"samples": [ "samples": [
"randomise the queue",
"randomise",
"shuffle", "shuffle",
"shuffle the queue" "shuffle na lista",
"mistura tudo"
] ]
} }
], ],
@@ -212,4 +203,4 @@
] ]
} }
} }
} }
+1 -3
View File
@@ -3491,9 +3491,7 @@ embedded in the URI</p>
<span class="sig-name descname"><span class="pre">ping</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="headerlink" href="#asknavidrome.subsonic_api.SubsonicConnection.ping" title="Link to this definition">#</a></dt> <span class="sig-name descname"><span class="pre">ping</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="headerlink" href="#asknavidrome.subsonic_api.SubsonicConnection.ping" title="Link to this definition">#</a></dt>
<dd><p>Ping a Subsonic API server</p> <dd><p>Ping a Subsonic API server</p>
<p>Verify the connection to a Subsonic compatible API server <p>Verify the connection to a Subsonic compatible API server
is working. Enhanced logging has been added to examine the is working</p>
HTTP response returned from the server to assist with troubleshooting
connection issues.</p>
<dl class="field-list simple"> <dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt> <dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>True if the connection works, False if it does not</p> <dd class="field-odd"><p>True if the connection works, False if it does not</p>
+1 -1
View File
File diff suppressed because one or more lines are too long
+35 -26
View File
@@ -42,7 +42,7 @@ logger.addHandler(handler)
# Get service configuration # Get service configuration
# #
logger.info('AskNavidrome 0.10!') logger.info('AskNavidrome 0.9!')
logger.debug('Getting configuration from the environment...') logger.debug('Getting configuration from the environment...')
try: try:
@@ -222,7 +222,7 @@ class LaunchRequestHandler(AbstractRequestHandler):
logger.debug('In LaunchRequestHandler') logger.debug('In LaunchRequestHandler')
connection.ping() connection.ping()
speech = sanitise_speech_output('Ready!') speech = sanitise_speech_output('Simbora!')
handler_input.response_builder.speak(speech).ask(speech) handler_input.response_builder.speak(speech).ask(speech)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -311,7 +311,8 @@ class NaviSonicPlayMusicByArtist(AbstractRequestHandler):
artist_lookup = connection.search_artist(artist.value) artist_lookup = connection.search_artist(artist.value)
if artist_lookup is None: if artist_lookup is None:
text = sanitise_speech_output(f"I couldn't find the artist {artist.value} in the collection.") #text = sanitise_speech_output(f"I couldn't find the artist {artist.value} in the collection.")
text = sanitise_speech_output(f"Não achei o artista {artist.value} na nossa coleção.")
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -328,7 +329,8 @@ class NaviSonicPlayMusicByArtist(AbstractRequestHandler):
backgroundProcess = Process(target=queue_worker_thread, args=(connection, play_queue, song_id_list[2:])) # Create a thread to enqueue the remaining 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 backgroundProcess.start() # Start the additional thread
speech = sanitise_speech_output(f'Playing music by: {artist.value}') #speech = sanitise_speech_output(f'Playing music by: {artist.value}')
speech = sanitise_speech_output(f'Tocando músicas de: {artist.value}')
logger.info(speech) logger.info(speech)
card = {'title': 'AskNavidrome', card = {'title': 'AskNavidrome',
@@ -371,7 +373,8 @@ class NaviSonicPlayAlbumByArtist(AbstractRequestHandler):
artist_lookup = connection.search_artist(artist.value) artist_lookup = connection.search_artist(artist.value)
if artist_lookup is None: if artist_lookup is None:
text = sanitise_speech_output(f"I couldn't find the artist {artist.value} in the collection.") #text = sanitise_speech_output(f"I couldn't find the artist {artist.value} in the collection.")
text = sanitise_speech_output(f"Não achei o artista {artist.value} na nossa coleção.")
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -384,7 +387,8 @@ class NaviSonicPlayAlbumByArtist(AbstractRequestHandler):
result = [album_result for album_result in artist_album_lookup if album_result.get('name').lower() == album.value.lower()] result = [album_result for album_result in artist_album_lookup if album_result.get('name').lower() == album.value.lower()]
if not result: if not result:
text = sanitise_speech_output(f"I couldn't find an album called {album.value} by {artist.value} in the collection.") #text = sanitise_speech_output(f"I couldn't find an album called {album.value} by {artist.value} in the collection.")
text = sanitise_speech_output(f"Não achei na nossa coleção um disco chamado {album.value} de {artist.value}.")
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -398,7 +402,8 @@ class NaviSonicPlayAlbumByArtist(AbstractRequestHandler):
backgroundProcess = Process(target=queue_worker_thread, args=(connection, play_queue, song_id_list[2:])) # Create a thread to enqueue the remaining 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 backgroundProcess.start() # Start the additional thread
speech = sanitise_speech_output(f'Playing {album.value} by: {artist.value}') #speech = sanitise_speech_output(f'Playing {album.value} by: {artist.value}')
speech = sanitise_speech_output(f'Tocando o álbum {album.value} de: {artist.value}')
logger.info(speech) logger.info(speech)
card = {'title': 'AskNavidrome', card = {'title': 'AskNavidrome',
'text': speech 'text': speech
@@ -414,7 +419,8 @@ class NaviSonicPlayAlbumByArtist(AbstractRequestHandler):
result = connection.search_album(album.value) result = connection.search_album(album.value)
if result is None: if result is None:
text = sanitise_speech_output(f"I couldn't find the album {album.value} in the collection.") #text = sanitise_speech_output(f"I couldn't find the album {album.value} in the collection.")
text = sanitise_speech_output(f"Não achei o disco {album.value} na nossa coleção.")
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -428,7 +434,7 @@ class NaviSonicPlayAlbumByArtist(AbstractRequestHandler):
backgroundProcess = Process(target=queue_worker_thread, args=(connection, play_queue, song_id_list[2:])) # Create a thread to enqueue the remaining 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 backgroundProcess.start() # Start the additional thread
speech = sanitise_speech_output(f'Playing {album.value}') speech = sanitise_speech_output(f'Tocando o disco {album.value}')
logger.info(speech) logger.info(speech)
card = {'title': 'AskNavidrome', card = {'title': 'AskNavidrome',
'text': speech 'text': speech
@@ -461,7 +467,8 @@ class NaviSonicPlaySongByArtist(AbstractRequestHandler):
artist_lookup = connection.search_artist(artist.value) artist_lookup = connection.search_artist(artist.value)
if artist_lookup is None: if artist_lookup is None:
text = sanitise_speech_output(f"I couldn't find the artist {artist.value} in the collection.") #text = sanitise_speech_output(f"I couldn't find the artist {artist.value} in the collection.")
text = sanitise_speech_output(f"Não achei o artista {artist.value} na nossa coleção.")
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -476,7 +483,8 @@ class NaviSonicPlaySongByArtist(AbstractRequestHandler):
song_dets = [item.get('id') for item in song_list if item.get('artistId') == artist_id] song_dets = [item.get('id') for item in song_list if item.get('artistId') == artist_id]
if not song_dets: if not song_dets:
text = sanitise_speech_output(f"I couldn't find a song called {song.value} by {artist.value} in the collection.") #text = sanitise_speech_output(f"I couldn't find a song called {song.value} by {artist.value} in the collection.")
text = sanitise_speech_output(f"Não achei uma música chamada {song.value} de {artist.value} na nossa coleção.")
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -484,7 +492,7 @@ class NaviSonicPlaySongByArtist(AbstractRequestHandler):
play_queue.clear() play_queue.clear()
controller.enqueue_songs(connection, play_queue, song_dets) controller.enqueue_songs(connection, play_queue, song_dets)
speech = sanitise_speech_output(f'Playing {song.value} by {artist.value}') speech = sanitise_speech_output(f'Tocando {song.value} de {artist.value}')
logger.info(speech) logger.info(speech)
card = {'title': 'AskNavidrome', card = {'title': 'AskNavidrome',
'text': speech 'text': speech
@@ -520,7 +528,7 @@ class NaviSonicPlayPlaylist(AbstractRequestHandler):
playlist_id = connection.search_playlist(playlist.value) playlist_id = connection.search_playlist(playlist.value)
if playlist_id is None: if playlist_id is None:
text = sanitise_speech_output("I couldn't find the playlist " + str(playlist.value) + ' in the collection.') text = sanitise_speech_output("Não achei a playlist " + str(playlist.value) + ' na nossa coleção.')
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -534,7 +542,7 @@ class NaviSonicPlayPlaylist(AbstractRequestHandler):
backgroundProcess = Process(target=queue_worker_thread, args=(connection, play_queue, song_id_list[2:])) # Create a thread to enqueue the remaining 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 backgroundProcess.start() # Start the additional thread
speech = sanitise_speech_output('Playing playlist ' + str(playlist.value)) speech = sanitise_speech_output('Tocando a playlist ' + str(playlist.value))
logger.info(speech) logger.info(speech)
card = {'title': 'AskNavidrome', card = {'title': 'AskNavidrome',
'text': speech 'text': speech
@@ -569,7 +577,7 @@ class NaviSonicPlayMusicByGenre(AbstractRequestHandler):
song_id_list = connection.build_song_list_from_genre(genre.value, min_song_count) song_id_list = connection.build_song_list_from_genre(genre.value, min_song_count)
if song_id_list is None: if song_id_list is None:
text = sanitise_speech_output(f"I couldn't find any {genre.value} songs in the collection.") text = sanitise_speech_output(f"Não achei nada do estilo {genre.value} na nossa coleção.")
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -583,7 +591,7 @@ class NaviSonicPlayMusicByGenre(AbstractRequestHandler):
backgroundProcess = Process(target=queue_worker_thread, args=(connection, play_queue, song_id_list[2:])) # Create a thread to enqueue the remaining 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 backgroundProcess.start() # Start the additional thread
speech = sanitise_speech_output(f'Playing {genre.value} music') speech = sanitise_speech_output(f'Tocando músicas do estilo {genre.value}')
logger.info(speech) logger.info(speech)
card = {'title': 'AskNavidrome', card = {'title': 'AskNavidrome',
'text': speech 'text': speech
@@ -615,7 +623,8 @@ class NaviSonicPlayMusicRandom(AbstractRequestHandler):
song_id_list = connection.build_random_song_list(min_song_count) song_id_list = connection.build_random_song_list(min_song_count)
if song_id_list is None: if song_id_list is None:
text = sanitise_speech_output("I couldn't find any songs in the collection.") #text = sanitise_speech_output("I couldn't find any songs in the collection.")
text = sanitise_speech_output("Não achei nenhuma música na nossa coleção. Estranho.")
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -629,7 +638,7 @@ class NaviSonicPlayMusicRandom(AbstractRequestHandler):
backgroundProcess = Process(target=queue_worker_thread, args=(connection, play_queue, song_id_list[2:])) # Create a thread to enqueue the remaining 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 backgroundProcess.start() # Start the additional thread
speech = sanitise_speech_output('Playing random music') speech = sanitise_speech_output('Tocando qualquer coisa aleatória')
logger.info(speech) logger.info(speech)
card = {'title': 'AskNavidrome', card = {'title': 'AskNavidrome',
'text': speech 'text': speech
@@ -661,7 +670,7 @@ class NaviSonicPlayFavouriteSongs(AbstractRequestHandler):
song_id_list = connection.build_song_list_from_favourites() song_id_list = connection.build_song_list_from_favourites()
if song_id_list is None: if song_id_list is None:
text = sanitise_speech_output("You don't have any favourite songs in the collection.") text = sanitise_speech_output("Você não tem nada nos favoritos.")
handler_input.response_builder.speak(text).ask(text) handler_input.response_builder.speak(text).ask(text)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -675,7 +684,7 @@ class NaviSonicPlayFavouriteSongs(AbstractRequestHandler):
backgroundProcess = Process(target=queue_worker_thread, args=(connection, play_queue, song_id_list[2:])) # Create a thread to enqueue the remaining 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 backgroundProcess.start() # Start the additional thread
speech = sanitise_speech_output('Playing your favourite tracks.') speech = sanitise_speech_output('Tocando suas músicas favoritas.')
logger.info(speech) logger.info(speech)
card = {'title': 'AskNavidrome', card = {'title': 'AskNavidrome',
'text': speech 'text': speech
@@ -903,8 +912,7 @@ class NextPlaybackHandler(AbstractRequestHandler):
"""Handle NextIntent""" """Handle NextIntent"""
def can_handle(self, handler_input: HandlerInput) -> bool: def can_handle(self, handler_input: HandlerInput) -> bool:
return (is_intent_name('AMAZON.NextIntent')(handler_input) or return is_intent_name('AMAZON.NextIntent')(handler_input)
is_request_type('PlaybackController.NextCommandIssued')(handler_input))
def handle(self, handler_input: HandlerInput) -> Response: def handle(self, handler_input: HandlerInput) -> Response:
logger.debug('In NextPlaybackHandler') logger.debug('In NextPlaybackHandler')
@@ -921,8 +929,7 @@ class PreviousPlaybackHandler(AbstractRequestHandler):
"""Handle PreviousIntent""" """Handle PreviousIntent"""
def can_handle(self, handler_input: HandlerInput) -> bool: def can_handle(self, handler_input: HandlerInput) -> bool:
return (is_intent_name('AMAZON.PreviousIntent')(handler_input) or return is_intent_name('AMAZON.PreviousIntent')(handler_input)
is_request_type('PlaybackController.PreviousCommandIssued')(handler_input))
def handle(self, handler_input: HandlerInput) -> Response: def handle(self, handler_input: HandlerInput) -> Response:
logger.debug('In PreviousPlaybackHandler') logger.debug('In PreviousPlaybackHandler')
@@ -989,7 +996,8 @@ class SystemExceptionHandler(AbstractExceptionHandler):
if get_request_type(handler_input) == 'IntentRequest': if get_request_type(handler_input) == 'IntentRequest':
logger.error(f'Intent Name Was: {get_intent_name(handler_input)}') logger.error(f'Intent Name Was: {get_intent_name(handler_input)}')
speech = sanitise_speech_output("Sorry, I didn't get that. Can you please say it again!!") #speech = sanitise_speech_output("Sorry, I didn't get that. Can you please say it again!!")
speech = sanitise_speech_output("Foi mal, não entendi. Pode repetir!!")
handler_input.response_builder.speak(speech).ask(speech) handler_input.response_builder.speak(speech).ask(speech)
return handler_input.response_builder.response return handler_input.response_builder.response
@@ -1015,7 +1023,8 @@ class GeneralExceptionHandler(AbstractExceptionHandler):
if get_request_type(handler_input) == 'IntentRequest': if get_request_type(handler_input) == 'IntentRequest':
logger.error(f'Intent Name Was: {get_intent_name(handler_input)}') logger.error(f'Intent Name Was: {get_intent_name(handler_input)}')
speech = sanitise_speech_output("Sorry, I didn't get that. Can you please say it again!!") #speech = sanitise_speech_output("Sorry, I didn't get that. Can you please say it again!!")
speech = sanitise_speech_output("Foi mal, não entendi. Pode repetir!!")
handler_input.response_builder.speak(speech).ask(speech) handler_input.response_builder.speak(speech).ask(speech)
return handler_input.response_builder.response return handler_input.response_builder.response
Executable → Regular
+3 -15
View File
@@ -42,19 +42,7 @@ def start_playback(mode: str, text: str, card_data: dict, track_details: Track,
:return: Amazon Alexa Response class :return: Amazon Alexa Response class
:rtype: Response :rtype: Response
""" """
metadata = AudioItemMetadata(
title=track_details.title,
subtitle=track_details.artist,
art=display.Image(
content_description=track_details.title,
sources=[
display.ImageInstance(
url='https://github.com/navidrome/navidrome/raw/master/resources/logo-192x192.png'
)
]
)
)
if mode == 'play': if mode == 'play':
# Starting playback # Starting playback
logger.debug('In start_playback() - play mode') logger.debug('In start_playback() - play mode')
@@ -79,7 +67,7 @@ def start_playback(mode: str, text: str, card_data: dict, track_details: Track,
url=track_details.uri, url=track_details.uri,
offset_in_milliseconds=track_details.offset, offset_in_milliseconds=track_details.offset,
expected_previous_token=None), expected_previous_token=None),
metadata=metadata metadata=add_screen_background(card_data) if card_data else None
) )
) )
).set_should_end_session(True) ).set_should_end_session(True)
@@ -107,7 +95,7 @@ def start_playback(mode: str, text: str, card_data: dict, track_details: Track,
# if the Previous intent is used # if the Previous intent is used
offset_in_milliseconds=0, offset_in_milliseconds=0,
expected_previous_token=track_details.previous_id), expected_previous_token=track_details.previous_id),
metadata=metadata metadata=None
) )
) )
).set_should_end_session(True) ).set_should_end_session(True)
+9 -21
View File
@@ -40,41 +40,29 @@ class SubsonicConnection:
self.api_version, self.api_version,
False) False)
self.logger.debug('Connecting to Navidrome.....') self.logger.debug('Connected to Navidrome')
def ping(self) -> bool: def ping(self) -> bool:
"""Ping a Subsonic API server """Ping a Subsonic API server
Verify the connection to a Subsonic compatible API server Verify the connection to a Subsonic compatible API server
is working. Enhanced logging has been added to examine the is working
HTTP response returned from the server to assist with troubleshooting
connection issues.
:return: True if the connection works, False if it does not :return: True if the connection works, False if it does not
:rtype: bool :rtype: bool
""" """
self.logger.debug('In function ping()') self.logger.debug('In function ping()')
http_request = self.conn._getRequest('ping.view') status = self.conn.ping()
try:
http_request_result = self.conn._doInfoReq(http_request)
except Exception as e:
self.logger.error('Failed to connect to Navidrome: %s', e, exc_info=True)
return False
self.logger.debug('ping() response from server: %s', http_request_result) if status:
status = http_request_result.get('status') # Success
if status == 'ok':
self.logger.info('Successfully connected to Navidrome') self.logger.info('Successfully connected to Navidrome')
return True
elif status == 'failed':
err = http_request_result.get('error', {})
self.logger.error('Failed to connect to Navidrome: code=%s msg=%s',
err.get('code'), err.get('message'))
return False
else: else:
self.logger.error('Unexpected error when connecting to Navidrome: %r', status) # Fail
return False self.logger.error('Failed to connect to Navidrome')
return self.conn.ping()
def scrobble(self, track_id: str, time: int) -> None: def scrobble(self, track_id: str, time: int) -> None:
"""Scrobble the given track """Scrobble the given track