Skip to content

Commit

Permalink
fix(core): issues with initial logging added
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Shatford <[email protected]>
  • Loading branch information
jordanshatford committed Nov 3, 2023
1 parent 6c4fa9d commit 3b02e7c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/ydcore/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .ytdlp import YoutubeDLParams


logger = logging.getLogger(__name__)
logger = logging.getLogger('ydcore')


StatusHook: TypeAlias = Callable[[Download], None]
Expand Down Expand Up @@ -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}, ' +
Expand Down
8 changes: 4 additions & 4 deletions core/ydcore/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .models import DownloadStatus


logger = logging.getLogger(__name__)
logger = logging.getLogger('ydcore')


def run_downloader(config: DownloadConfig) -> None:
Expand All @@ -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),
)
7 changes: 4 additions & 3 deletions core/ydcore/innertube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion core/ydcore/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .models import DownloadInput


logger = logging.getLogger(__name__)
logger = logging.getLogger('ydcore')


class DownloadManager:
Expand Down
2 changes: 1 addition & 1 deletion core/ydcore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import HttpUrl


logger = logging.getLogger(__name__)
logger = logging.getLogger('ydcore')


class Channel(BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions core/ydcore/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .models import Video


logger = logging.getLogger(__name__)
logger = logging.getLogger('ydcore')


_YOUTUBE_BASE_URL = 'https://www.youtube.com'
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 3b02e7c

Please sign in to comment.