music_assistant/testrun.sh
build/
dist/
+venv/
--- /dev/null
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Python: Module",
+ "type": "python",
+ "request": "launch",
+ "module": "music_assistant"
+ },
+ {
+ "name": "Python: Huidige bestand",
+ "type": "python",
+ "request": "launch",
+ "program": "${file}",
+ "console": "integratedTerminal"
+ },
+ {
+ "name": "Python: Attach using Process Id",
+ "type": "python",
+ "request": "attach",
+ "processId": "${command:pickProcess}"
+ }
+ ]
+}
\ No newline at end of file
import re
import aiohttp
+import json
from asyncio_throttle import Throttler
from music_assistant.cache import use_cache
from music_assistant.utils import LOGGER, compare_strings, get_compare_string
) as response:
try:
result = await response.json()
- except aiohttp.client_exceptions.ContentTypeError:
+ except (aiohttp.client_exceptions.ContentTypeError, json.decoder.JSONDecodeError):
LOGGER.error("Failed to retrieve %s", endpoint)
text_result = await response.text()
LOGGER.debug(text_result)
item_id = await self.mass.db.get_database_id(
provider, prov_item_id, MediaType.Artist
)
- if item_id is not None:
+ if item_id is None:
# artist not yet in local database so fetch details
cache_key = f"{self.prov_id}.get_artist.{prov_item_id}"
artist_details = await cached(
item_id = await self.mass.db.get_database_id(
provider, prov_item_id, MediaType.Album
)
- if not item_id:
+ if item_id is None:
# album not yet in local database so fetch details
if not album_details:
cache_key = f"{self.prov_id}.get_album.{prov_item_id}"
item_id = await self.mass.db.get_database_id(
provider, prov_item_id, MediaType.Track
)
- if not item_id:
+ if item_id is None:
# track not yet in local database so fetch details
if not track_details:
cache_key = f"{self.prov_id}.get_track.{prov_item_id}"
db_id = await self.mass.db.get_database_id(
provider, prov_playlist_id, MediaType.Playlist
)
- if not db_id:
+ if db_id is None:
# item not yet in local database so fetch and store details
item_details = await self.get_playlist(prov_playlist_id)
db_id = await self.mass.db.add_playlist(item_details)
db_id = await self.mass.db.get_database_id(
provider, prov_radio_id, MediaType.Radio
)
- if not db_id:
+ if db_id is None:
# item not yet in local database so fetch and store details
item_details = await self.get_radio(prov_radio_id)
db_id = await self.mass.db.add_radio(item_details)
CONNECTION_STATUS_CONNECTED,
CONNECTION_STATUS_DISCONNECTED,
)
+import zeroconf
PROV_ID = "chromecast"
PROV_NAME = "Chromecast"
# cleanup cast object
del player.cc
self.mass.run_task(self.remove_player(player.player_id))
+
# search for available chromecasts
- from pychromecast.discovery import start_discovery, stop_discovery
- def discovered_callback(name):
+ def list_devices():
+ LOGGER.debug("Currently known cast devices:")
+ for uuid, service in listener.services.items():
+ LOGGER.debug(" {} {}".format(uuid, service))
+
+ def add_callback(name):
"""Called when zeroconf has discovered a (new) chromecast."""
discovery_info = listener.services[name]
ip_address, port, uuid, model_name, friendly_name = discovery_info
self.__chromecast_discovered(player_id, discovery_info)
self.__update_group_players()
- listener, browser = start_discovery(discovered_callback)
+ def remove_callback(uuid, name, service):
+ LOGGER.debug("Lost mDNS service for cast device {} {}".format(uuid, service))
+ list_devices()
+
+ def update_callback(uuid, name):
+ LOGGER.debug("Updated mDNS service for cast device {}".format(uuid))
+ list_devices()
+
+ listener = pychromecast.CastListener(add_callback, remove_callback, update_callback)
+ zconf = zeroconf.Zeroconf()
+ browser = pychromecast.discovery.start_discovery(listener, zconf)
+
time.sleep(30) # run discovery for 30 seconds
- stop_discovery(browser)
+ pychromecast.stop_discovery(browser)
LOGGER.debug("Chromecast discovery completed...")
self._discovery_running = False