From d3c41ec3651a64a169b6529a410ca0d80e4de20d Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 6 Jul 2022 23:09:51 +0200 Subject: [PATCH] run blocking call in executor --- music_assistant/music_providers/ytmusic.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/music_assistant/music_providers/ytmusic.py b/music_assistant/music_providers/ytmusic.py index 0f0da013..3280d008 100644 --- a/music_assistant/music_providers/ytmusic.py +++ b/music_assistant/music_providers/ytmusic.py @@ -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) -- 2.34.1