feat: timeit in debug log

with_status
WorldObservationLog 4 months ago
parent c84c3818e8
commit cc65d4782a
  1. 4
      src/rip.py
  2. 14
      src/utils.py

@ -22,6 +22,7 @@ task_lock = asyncio.Semaphore(16)
@logger.catch @logger.catch
@timeit
async def rip_song(song: Song, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device, 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): force_save: bool = False, specified_m3u8: str = "", playlist: PlaylistInfo = None):
async with task_lock: async with task_lock:
@ -106,6 +107,7 @@ async def rip_song(song: Song, auth_params: GlobalAuthParams, codec: str, config
@logger.catch @logger.catch
@timeit
async def rip_album(album: Album, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device, async def rip_album(album: Album, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device,
force_save: bool = False): force_save: bool = False):
album_info = await get_album_info(album.id, auth_params.anonymousAccessToken, album.storefront, 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 @logger.catch
@timeit
async def rip_playlist(playlist: Playlist, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device, async def rip_playlist(playlist: Playlist, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device,
force_save: bool = False): force_save: bool = False):
playlist_info = await get_playlist_info_and_tracks(playlist.id, auth_params.anonymousAccessToken, 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 @logger.catch
@timeit
async def rip_artist(artist: Artist, auth_params: GlobalAuthParams, codec: str, config: Config, device: Device, 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): force_save: bool = False, include_participate_in_works: bool = False):
artist_info = await get_artist_info(artist.id, artist.storefront, auth_params.anonymousAccessToken, artist_info = await get_artist_info(artist.id, artist.storefront, auth_params.anonymousAccessToken,

@ -7,6 +7,7 @@ from pathlib import Path
import m3u8 import m3u8
import regex import regex
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from loguru import logger
from src.config import Download from src.config import Download
from src.exceptions import NotTimeSyncedLyricsException from src.exceptions import NotTimeSyncedLyricsException
@ -51,21 +52,14 @@ def chunk(it, size):
def timeit(func): def timeit(func):
async def process(func, *args, **params): async def process(func, *args, **params):
if asyncio.iscoroutinefunction(func): if asyncio.iscoroutinefunction(func):
print('this function is a coroutine: {}'.format(func.__name__))
return await func(*args, **params) return await func(*args, **params)
else: else:
print('this is not a coroutine')
return func(*args, **params) return func(*args, **params)
async def helper(*args, **params): async def helper(*args, **params):
print('{}.time'.format(func.__name__))
start = time.time() start = time.time()
result = await process(func, *args, **params) result = await process(func, *args, **params)
logger.debug(f'{func.__name__}: {time.time() - start}')
# Test normal function route...
# result = await process(lambda *a, **p: print(*a, **p), *args, **params)
print('>>>', time.time() - start)
return result return result
return helper return helper
@ -150,13 +144,15 @@ def playlist_metadata_to_params(playlist: PlaylistInfo):
return {"playlistName": playlist.data[0].attributes.name, return {"playlistName": playlist.data[0].attributes.name,
"playlistCuratorName": playlist.data[0].attributes.curatorName} "playlistCuratorName": playlist.data[0].attributes.curatorName}
def get_path_safe_dict(param: dict): def get_path_safe_dict(param: dict):
new_param = deepcopy(param) new_param = deepcopy(param)
for key, val in new_param.items(): for key, val in new_param.items():
if isinstance(val, str): if isinstance(val, str):
new_param[key] = get_valid_filename(str(val)) new_param[key] = get_valid_filename(str(val))
return new_param return new_param
def get_song_name_and_dir_path(codec: str, config: Download, metadata, playlist: PlaylistInfo = None): def get_song_name_and_dir_path(codec: str, config: Download, metadata, playlist: PlaylistInfo = None):
if playlist: if playlist:
safe_meta = get_path_safe_dict(metadata.model_dump()) safe_meta = get_path_safe_dict(metadata.model_dump())

Loading…
Cancel
Save