From d0ed29e685e7043154973025c8dff00240ba76e6 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Mon, 6 May 2024 21:07:19 +0400 Subject: [PATCH] Optimize extract_info: no process=True for YouTube For YT, processing separate videos greatly increases extract_info time, but unnecessary when obtaining only track title. For Yandex, processing is much faster, and we NEED it to get title. --- backend/ydl_pool.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/ydl_pool.py b/backend/ydl_pool.py index 4cc869b..7dd6511 100644 --- a/backend/ydl_pool.py +++ b/backend/ydl_pool.py @@ -36,6 +36,9 @@ create_ydl_fn = { ydl_fn_keys = create_ydl_fn.keys() +# need process=True for track title in extract_info output +NP_YDLS = {'yandex'} + class Downloader: @@ -51,6 +54,7 @@ class Downloader: } self.cur_ydl: YoutubeDL | None = None + self.cur_site = '' self.progress_cb = progress_cb self.lyrics_cb = lyrics_cb @@ -71,6 +75,7 @@ class Downloader: ydl.params['cookiefile'] = str(cookies) self.cur_ydl = ydl + self.cur_site = site def get_cur_ydl(self) -> YoutubeDL: @@ -86,12 +91,13 @@ class Downloader: Downloader._target_get_playlist_items, self.get_cur_ydl(), url, + self.cur_site in NP_YDLS, ) @staticmethod - def _target_get_playlist_items(ydl: YoutubeDL, url: str) -> list[str]: + def _target_get_playlist_items(ydl: YoutubeDL, url: str, process: bool) -> list[str]: - info = ydl.extract_info(url, download=False, process=True) + info = ydl.extract_info(url, download=False, process=process) if info is None: raise RuntimeError('ydl.extract_info returned None') return [