From 3b02e7ce34f413bd72214c96bc51bbbf01249725 Mon Sep 17 00:00:00 2001 From: Jordan Shatford Date: Fri, 3 Nov 2023 12:42:04 +1100 Subject: [PATCH] fix(core): issues with initial logging added Signed-off-by: Jordan Shatford --- core/ydcore/config.py | 4 ++-- core/ydcore/downloader.py | 8 ++++---- core/ydcore/innertube.py | 7 ++++--- core/ydcore/manager.py | 2 +- core/ydcore/models.py | 2 +- core/ydcore/search.py | 6 +++--- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/core/ydcore/config.py b/core/ydcore/config.py index e48ae960..f927227d 100644 --- a/core/ydcore/config.py +++ b/core/ydcore/config.py @@ -14,7 +14,7 @@ from .ytdlp import YoutubeDLParams -logger = logging.getLogger(__name__) +logger = logging.getLogger('ydcore') StatusHook: TypeAlias = Callable[[Download], None] @@ -160,7 +160,7 @@ def _progress_hook(self, info: ProgressHookInfo) -> None: eta = info.get('eta') speed = info.get('speed') logger.debug( - 'Downloading ({url}): ' + + f'Downloading ({url}): ' + f'downloaded_bytes={downloaded_bytes}, ' + f'total_bytes={total_bytes}, ' + f'elapsed={elapsed}, eta={eta}, ' + diff --git a/core/ydcore/downloader.py b/core/ydcore/downloader.py index 14a28a5f..a4750a18 100644 --- a/core/ydcore/downloader.py +++ b/core/ydcore/downloader.py @@ -7,7 +7,7 @@ from .models import DownloadStatus -logger = logging.getLogger(__name__) +logger = logging.getLogger('ydcore') def run_downloader(config: DownloadConfig) -> None: @@ -16,13 +16,13 @@ def run_downloader(config: DownloadConfig) -> None: DownloadStatus(state=DownloadState.DOWNLOADING), ) try: - logging.debug(msg=f'Download started: {config.download.video.url}.') + logger.debug(msg=f'Download started: {config.download.video.url}.') downloader.download( # type: ignore [str(config.download.video.url)], ) - logging.debug(msg=f'Download completed: {config.download.video.url}.') + logger.debug(msg=f'Download completed: {config.download.video.url}.') except Exception as e: - logging.error(f'Failed to download: {config.download.video.url} {e}.') + logger.error(f'Failed to download: {config.download.video.url} {e}.') config.on_status_update( DownloadStatus(state=DownloadState.ERROR), ) diff --git a/core/ydcore/innertube.py b/core/ydcore/innertube.py index a7915e4c..c6564a99 100644 --- a/core/ydcore/innertube.py +++ b/core/ydcore/innertube.py @@ -10,7 +10,7 @@ from urllib.request import urlopen -logger = logging.getLogger(__name__) +logger = logging.getLogger('ydcore') _INNERTUBE_BASE_URL = 'https://www.youtube.com/youtubei/v1' @@ -135,9 +135,10 @@ def _call_innertube_api( }, ) logger.debug( - f'Calling innertube API with: url={url} request={request}.', + f'Calling innertube API with: url={url}, ' + + f'data={request.data}, headers={request.headers}.', ) response = urlopen(request, timeout=timeout) response_data = json.loads(response.read().decode('utf-8')) - logger.debug(f'Innertube API responded with: {response_data}.') + logger.debug(f'Innertube API responded to: url={url}.') return response_data diff --git a/core/ydcore/manager.py b/core/ydcore/manager.py index a1062762..bd1e5e87 100644 --- a/core/ydcore/manager.py +++ b/core/ydcore/manager.py @@ -11,7 +11,7 @@ from .models import DownloadInput -logger = logging.getLogger(__name__) +logger = logging.getLogger('ydcore') class DownloadManager: diff --git a/core/ydcore/models.py b/core/ydcore/models.py index 5578508b..14410182 100644 --- a/core/ydcore/models.py +++ b/core/ydcore/models.py @@ -6,7 +6,7 @@ from pydantic import HttpUrl -logger = logging.getLogger(__name__) +logger = logging.getLogger('ydcore') class Channel(BaseModel): diff --git a/core/ydcore/search.py b/core/ydcore/search.py index bfb480eb..f99cbd5a 100644 --- a/core/ydcore/search.py +++ b/core/ydcore/search.py @@ -8,7 +8,7 @@ from .models import Video -logger = logging.getLogger(__name__) +logger = logging.getLogger('ydcore') _YOUTUBE_BASE_URL = 'https://www.youtube.com' @@ -54,12 +54,12 @@ def next(self) -> bool: results, continuation = self._fetch_and_parse() self._results = results self._continuation = continuation - logging.debug( + logger.debug( f'Found {len(results)} results for search: {self._query}.', ) return True else: - logging.debug(f'No more results for search: {self._query}.') + logger.debug(f'No more results for search: {self._query}.') return False def _fetch_and_parse(self) -> tuple[list[Video], str | None]: