small fixes
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 15 Sep 2020 21:42:13 +0000 (23:42 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 15 Sep 2020 21:42:13 +0000 (23:42 +0200)
stability, consistency

music_assistant/__main__.py
music_assistant/database.py
music_assistant/http_streamer.py
music_assistant/player_manager.py
music_assistant/providers/chromecast/__init__.py
music_assistant/providers/chromecast/player.py
music_assistant/utils.py

index 6868b79f1f3be55a23afb25a736c5b7bd7b467b5..befb278769fd33402a3d22500424abae7de5dae2 100755 (executable)
@@ -2,6 +2,8 @@
 import argparse
 import logging
 import os
+import platform
+import webbrowser
 
 from aiorun import run
 from music_assistant.mass import MusicAssistant
@@ -57,15 +59,19 @@ def main():
     mass = MusicAssistant(data_dir)
 
     # run UI in browser on windows and macos only
-    # if platform.system() in ["Windows", "Darwin"]:
-    #     import webbrowser
-    #     webbrowser.open(f"http://localhost:{mass.web.http_port}")
+    if platform.system() in ["Windows", "Darwin"]:
+        webbrowser.open(mass.web.internal_url)
 
     def on_shutdown(loop):
         logger.info("shutdown requested!")
         loop.run_until_complete(mass.async_stop())
 
-    run(mass.async_start(), use_uvloop=True, shutdown_callback=on_shutdown)
+    run(
+        mass.async_start(),
+        use_uvloop=True,
+        shutdown_callback=on_shutdown,
+        executor_workers=32,
+    )
 
 
 if __name__ == "__main__":
index c5f3609668223774984c2575ecb412712ef6ece2..0ed0bd8d00ba8e0ecaaa327a8c49202f2bcb9f30 100755 (executable)
@@ -1048,7 +1048,9 @@ class Database:
         for key, value in external_ids.items():
             sql_query = """INSERT or REPLACE INTO external_ids
                 (item_id, media_type, key, value) VALUES(?,?,?,?);"""
-            await db_conn.execute(sql_query, (item_id, int(media_type), key, value))
+            await db_conn.execute(
+                sql_query, (item_id, int(media_type), str(key), value)
+            )
 
     async def __async_get_external_ids(
         self, item_id: int, media_type: MediaType, db_conn: sqlite3.Connection
@@ -1131,7 +1133,7 @@ class Database:
             sql_query = "SELECT (item_id) FROM external_ids \
                     WHERE media_type=? AND key=? AND value=?;"
             for db_row in await db_conn.execute_fetchall(
-                sql_query, (int(media_item.media_type), key, value)
+                sql_query, (int(media_item.media_type), str(key), value)
             ):
                 if db_row:
                     return db_row[0]
index db3c4e8b2c183c715e5c6b3f189654f19c3724ce..70c780d0225e48e241945acdaa4dd762b5646275 100755 (executable)
@@ -16,6 +16,7 @@ import threading
 import urllib
 from contextlib import suppress
 
+import aiohttp
 import pyloudnorm
 import soundfile
 from aiohttp import web
@@ -71,7 +72,11 @@ class HTTPStreamer:
         # let the streaming begin!
         try:
             await asyncio.gather(bg_task)
-        except (asyncio.CancelledError, asyncio.TimeoutError) as exc:
+        except (
+            asyncio.CancelledError,
+            aiohttp.ClientConnectionError,
+            asyncio.TimeoutError,
+        ) as exc:
             cancelled.set()
             raise exc  # re-raise
         return resp
@@ -112,7 +117,11 @@ class HTTPStreamer:
         # let the streaming begin!
         try:
             await asyncio.gather(bg_task)
-        except (asyncio.CancelledError, asyncio.TimeoutError) as exc:
+        except (
+            asyncio.CancelledError,
+            aiohttp.ClientConnectionError,
+            asyncio.TimeoutError,
+        ) as exc:
             cancelled.set()
             raise exc  # re-raise
         return resp
index 1796cd744eb603616b795b45b09010a8b29b87a5..591770a1ba8086fe48408a9f6ba3fa67b7881592 100755 (executable)
@@ -461,7 +461,7 @@ class PlayerManager:
         gain_correct = round(gain_correct, 2)
         LOGGER.debug(
             "Loudness level for track %s/%s is %s - calculated replayGain is %s",
-            id,
+            provider_id,
             item_id,
             track_loudness,
             gain_correct,
index feace0291da2393d5345eec575ecfad6033a4531..ac7177c8b1accca2d1f0ae77c75e8c893fe54420 100644 (file)
@@ -72,7 +72,7 @@ class ChromecastProvider(PlayerProvider):
         pychromecast.stop_discovery(self._browser)
         # stop cast socket clients
         for player in self._players.values():
-            await player.async_disconnect()
+            player.disconnect()
 
     async def async_cmd_play_uri(self, player_id: str, uri: str):
         """
index d39b645878de5b232b52e2ac1eefe5ef512fc6f2..81facca8da2ca75399819c817c54c347a21632d6 100644 (file)
@@ -186,7 +186,7 @@ class ChromecastPlayer:
         chromecast.mz_controller = mz_controller
         self._chromecast.start()
 
-    async def async_disconnect(self):
+    def disconnect(self):
         """Disconnect Chromecast object if it is set."""
         if self._chromecast is None:
             return
@@ -194,7 +194,7 @@ class ChromecastPlayer:
             "[%s] Disconnecting from chromecast socket", self._cast_info.friendly_name
         )
         self._available = False
-        self.mass.add_job(self._chromecast.disconnect)
+        self._chromecast.disconnect()
         self._invalidate()
 
     def _invalidate(self):
index 3a16feab329347b9fe636341992f46ac6fef4277..691fb20510f4891891ded99906875c3512a17d65 100755 (executable)
@@ -298,7 +298,7 @@ def create_tempfile():
     return tempfile.NamedTemporaryFile(buffering=0)
 
 
-class CustomIntEnum(Enum):
+class CustomIntEnum(int, Enum):
     """Base for IntEnum with some helpers."""
 
     # when serializing we prefer the string (name) representation