From 57bcbad4720f5b2565af1b8eaee6c2981f87dbc8 Mon Sep 17 00:00:00 2001 From: "Il'ya (Marshal)" Date: Sun, 20 Feb 2022 00:36:38 +0100 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20tracks=5Fdownload=5Finfo=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?get=5Fdirect=5Flinks=3DTrue=20=D0=B2=20=D0=B0=D1=81=D0=B8=D0=BD?= =?UTF-8?q?=D1=85=D1=80=D0=BE=D0=BD=D0=BD=D0=BE=D0=B9=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generate_async_version.py | 1 + yandex_music/client.py | 2 -- yandex_music/client_async.py | 4 +--- yandex_music/download_info.py | 25 +++++++++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/generate_async_version.py b/generate_async_version.py index 299d084..a3f19ee 100644 --- a/generate_async_version.py +++ b/generate_async_version.py @@ -77,6 +77,7 @@ def gen_client(output_client_filename): 'self.rotor_station_feedback(', 'await self.rotor_station_feedback(' ) + code = code.replace('return DownloadInfo.de_list', 'return await DownloadInfo.de_list_async') code = DISCLAIMER + code with open(output_client_filename, 'w') as f: diff --git a/yandex_music/client.py b/yandex_music/client.py index 904fe12..7cf7aa5 100644 --- a/yandex_music/client.py +++ b/yandex_music/client.py @@ -566,8 +566,6 @@ class Client(YandexMusicObject): result = self._request.get(url, timeout=timeout, *args, **kwargs) - # TODO (MarshalX) fix get_direct_links=True in async version - return DownloadInfo.de_list(result, self, get_direct_links) @log diff --git a/yandex_music/client_async.py b/yandex_music/client_async.py index 68fec87..8b09fc0 100644 --- a/yandex_music/client_async.py +++ b/yandex_music/client_async.py @@ -572,9 +572,7 @@ class ClientAsync(YandexMusicObject): result = await self._request.get(url, timeout=timeout, *args, **kwargs) - # TODO (MarshalX) fix get_direct_links=True in async version - - return DownloadInfo.de_list(result, self, get_direct_links) + return await DownloadInfo.de_list_async(result, self, get_direct_links) @log async def track_supplement( diff --git a/yandex_music/download_info.py b/yandex_music/download_info.py index 19ca5d6..46622a6 100644 --- a/yandex_music/download_info.py +++ b/yandex_music/download_info.py @@ -151,6 +151,31 @@ class DownloadInfo(YandexMusicObject): return downloads_info + @classmethod + async def de_list_async(cls, data: dict, client: 'Client', get_direct_links: bool = False) -> List['DownloadInfo']: + """Десериализация списка объектов. + + Args: + data (:obj:`list`): Список словарей с полями и значениями десериализуемого объекта. + get_direct_links (:obj:`bool`): Получать ли сразу прямые ссылки на загрузку. + client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. + + Returns: + :obj:`list` из :obj:`yandex_music.DownloadInfo`: Варианты загрузки треков. + """ + if not data: + return [] + + downloads_info = list() + for download_info in data: + downloads_info.append(cls.de_json(download_info, client)) + + if get_direct_links: + for info in downloads_info: + await info.get_direct_link_async() + + return downloads_info + # camelCase псевдонимы #: Псевдоним для :attr:`get_direct_link`