run blocking call in executor
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Wed, 6 Jul 2022 21:09:51 +0000 (23:09 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Wed, 6 Jul 2022 21:09:51 +0000 (23:09 +0200)
music_assistant/music_providers/ytmusic.py

index 0f0da013ebda7b4ae1418a63e862e144cae34078..3280d008153af2a09888400e224f930e071b9339 100644 (file)
@@ -674,12 +674,15 @@ class YoutubeMusicProvider(MusicProvider):
             raise MediaNotFoundError("No stream found for this track")
         return stream_format
 
-    @classmethod
-    async def _decipher_signature(cls, ciphered_signature: str, item_id: str):
+    async def _decipher_signature(self, ciphered_signature: str, item_id: str):
         """Decipher the signature, required to build the Stream URL."""
-        embed_url = f"https://www.youtube.com/embed/{item_id}"
-        embed_html = pytube.request.get(embed_url)
-        js_url = pytube.extract.js_url(embed_html)
-        ytm_js = pytube.request.get(js_url)
-        cipher = pytube.cipher.Cipher(js=ytm_js)
-        return cipher.get_signature(ciphered_signature)
+
+        def _decipher():
+            embed_url = f"https://www.youtube.com/embed/{item_id}"
+            embed_html = pytube.request.get(embed_url)
+            js_url = pytube.extract.js_url(embed_html)
+            ytm_js = pytube.request.get(js_url)
+            cipher = pytube.cipher.Cipher(js=ytm_js)
+            return cipher.get_signature(ciphered_signature)
+
+        return await self.mass.loop.run_in_executor(None, _decipher)