From cc65d4782ab690e8085ee37addff2885d56a7dfa Mon Sep 17 00:00:00 2001 From: WorldObservationLog Date: Wed, 22 May 2024 13:47:27 +0800 Subject: [PATCH] feat: timeit in debug log --- src/rip.py | 4 ++++ src/utils.py | 14 +++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/rip.py b/src/rip.py index 2b6396d..c99c004 100644 --- a/src/rip.py +++ b/src/rip.py @@ -22,6 +22,7 @@ task_lock = asyncio.Semaphore(16) @logger.catch +@timeit async def rip_song(song: Song, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device, force_save: bool = False, specified_m3u8: str = "", playlist: PlaylistInfo = None): async with task_lock: @@ -106,6 +107,7 @@ async def rip_song(song: Song, auth_params: GlobalAuthParams, codec: str, config @logger.catch +@timeit async def rip_album(album: Album, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device, force_save: bool = False): album_info = await get_album_info(album.id, auth_params.anonymousAccessToken, album.storefront, @@ -125,6 +127,7 @@ async def rip_album(album: Album, auth_params: GlobalAuthParams, codec: str, con @logger.catch +@timeit async def rip_playlist(playlist: Playlist, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device, force_save: bool = False): playlist_info = await get_playlist_info_and_tracks(playlist.id, auth_params.anonymousAccessToken, @@ -143,6 +146,7 @@ async def rip_playlist(playlist: Playlist, auth_params: GlobalAuthParams, codec: @logger.catch +@timeit async def rip_artist(artist: Artist, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device, force_save: bool = False, include_participate_in_works: bool = False): artist_info = await get_artist_info(artist.id, artist.storefront, auth_params.anonymousAccessToken, diff --git a/src/utils.py b/src/utils.py index cc478ef..8ecb4b5 100644 --- a/src/utils.py +++ b/src/utils.py @@ -7,6 +7,7 @@ from pathlib import Path import m3u8 import regex from bs4 import BeautifulSoup +from loguru import logger from src.config import Download from src.exceptions import NotTimeSyncedLyricsException @@ -51,21 +52,14 @@ def chunk(it, size): def timeit(func): async def process(func, *args, **params): if asyncio.iscoroutinefunction(func): - print('this function is a coroutine: {}'.format(func.__name__)) return await func(*args, **params) else: - print('this is not a coroutine') return func(*args, **params) async def helper(*args, **params): - print('{}.time'.format(func.__name__)) start = time.time() result = await process(func, *args, **params) - - # Test normal function route... - # result = await process(lambda *a, **p: print(*a, **p), *args, **params) - - print('>>>', time.time() - start) + logger.debug(f'{func.__name__}: {time.time() - start}') return result return helper @@ -150,13 +144,15 @@ def playlist_metadata_to_params(playlist: PlaylistInfo): return {"playlistName": playlist.data[0].attributes.name, "playlistCuratorName": playlist.data[0].attributes.curatorName} + def get_path_safe_dict(param: dict): new_param = deepcopy(param) for key, val in new_param.items(): - if isinstance(val, str): + if isinstance(val, str): new_param[key] = get_valid_filename(str(val)) return new_param + def get_song_name_and_dir_path(codec: str, config: Download, metadata, playlist: PlaylistInfo = None): if playlist: safe_meta = get_path_safe_dict(metadata.model_dump())