Skip to content

Commit

Permalink
several fixes
Browse files Browse the repository at this point in the history
fix search
fix chromecast
fix radio
  • Loading branch information
marcelveldt committed Jul 5, 2020
1 parent 3ede6f7 commit fde1fb7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion music_assistant/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async def search(self, searchquery, media_types: List[MediaType]):
if MediaType.Playlist in media_types:
sql_query = ' WHERE name LIKE "%s"' % searchquery
result["playlists"] = [
item async for item in self.library_playlists(sql_query)
item async for item in self.playlists(sql_query)
]
return result

Expand Down
21 changes: 12 additions & 9 deletions music_assistant/http_streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,18 @@ def __get_audio_stream(
""" get audio stream from provider and apply additional effects/processing where/if needed"""
streamdetails = None
# always request the full db track as there might be other qualities available
full_track = self.mass.run_task(
self.mass.music.track(
queue_item.item_id,
queue_item.provider,
lazy=True,
track_details=queue_item,
),
wait_for_result=True,
)
if queue_item.media_type == MediaType.Radio:
full_track = queue_item
else:
full_track = self.mass.run_task(
self.mass.music.track(
queue_item.item_id,
queue_item.provider,
lazy=True,
track_details=queue_item,
),
wait_for_result=True,
)
# sort by quality and check track availability
for prov_media in sorted(
full_track.provider_ids, key=operator.itemgetter("quality"), reverse=True
Expand Down
18 changes: 7 additions & 11 deletions music_assistant/playerproviders/chromecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,19 @@ def list_devices():
for uuid, service in listener.services.items():
LOGGER.debug(" {} {}".format(uuid, service))

def add_callback(name):
def add_callback(uuid, name):
"""Called when zeroconf has discovered a (new) chromecast."""
discovery_info = listener.services[name]
ip_address, port, uuid, model_name, friendly_name = discovery_info
services = listener.services[uuid]
player_id = str(uuid)
if not player_id in self.mass.players._players:
self.__chromecast_discovered(player_id, discovery_info)
self.__chromecast_discovered(player_id, services, zconf)
self.__update_group_players()

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()
Expand All @@ -313,15 +310,14 @@ def update_callback(uuid, name):
LOGGER.debug("Chromecast discovery completed...")
self._discovery_running = False

def __chromecast_discovered(self, player_id, discovery_info):
def __chromecast_discovered(self, player_id, services, zconf):
""" callback when a (new) chromecast device is discovered """
from pychromecast import _get_chromecast_from_host, ChromecastConnectionError

try:
chromecast = _get_chromecast_from_host(
discovery_info, tries=2, timeout=5, retry_wait=5
chromecast = pychromecast.get_chromecast_from_service(
services, zconf, tries=2, retry_wait=5, timeout=5
)
except ChromecastConnectionError:
except pychromecast.ChromecastConnectionError:
LOGGER.warning("Could not connect to device %s" % player_id)
return
player = ChromecastPlayer(self.mass, player_id, self.prov_id)
Expand Down

0 comments on commit fde1fb7

Please sign in to comment.