mirror of
https://github.com/tropicoo/yt-dlp-bot.git
synced 2024-09-20 14:56:09 +08:00
Refactor
This commit is contained in:
parent
e5e53997cb
commit
99edf37523
|
@ -10,8 +10,7 @@ from yt_shared.rabbit.publisher import RmqPublisher
|
|||
from yt_shared.schemas.error import ErrorDownloadGeneralPayload
|
||||
from yt_shared.schemas.media import BaseMedia
|
||||
from yt_shared.schemas.success import SuccessDownloadPayload
|
||||
from yt_shared.utils.common import format_bytes
|
||||
from yt_shared.utils.file import file_size, remove_dir
|
||||
from yt_shared.utils.file import list_files, remove_dir
|
||||
from yt_shared.utils.tasks.tasks import create_task
|
||||
|
||||
from bot.core.handlers.abstract import AbstractDownloadHandler
|
||||
|
@ -110,10 +109,7 @@ class SuccessDownloadHandler(AbstractDownloadHandler):
|
|||
'Cleaning up task "%s": removing download content directory "%s" with files %s',
|
||||
self._body.task_id,
|
||||
root_path,
|
||||
{
|
||||
fn: format_bytes(file_size(os.path.join(root_path, fn)))
|
||||
for fn in os.listdir(root_path)
|
||||
},
|
||||
list_files(root_path),
|
||||
)
|
||||
remove_dir(root_path)
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import yt_dlp
|
|||
from yt_shared.enums import DownMediaType
|
||||
from yt_shared.schemas.media import Audio, DownMedia, Video
|
||||
from yt_shared.utils.common import format_bytes, random_string
|
||||
from yt_shared.utils.file import file_size
|
||||
from yt_shared.utils.file import file_size, list_files
|
||||
|
||||
from worker.core.config import settings
|
||||
from worker.core.exceptions import MediaDownloaderError
|
||||
|
@ -76,7 +76,9 @@ class MediaDownloader:
|
|||
|
||||
self._log.info('Finished downloading %s', url)
|
||||
self._log.debug('Downloaded "%s" meta: %s', url, meta_sanitized)
|
||||
self._log.info('Content of "%s": %s', curr_tmp_dir, current_files)
|
||||
self._log.info(
|
||||
'Content of "%s": %s', curr_tmp_dir, list_files(curr_tmp_dir)
|
||||
)
|
||||
|
||||
destination_dir = os.path.join(
|
||||
self._tmp_downloaded_dest_dir,
|
||||
|
|
|
@ -3,6 +3,8 @@ import os
|
|||
import shutil
|
||||
from typing import Iterable
|
||||
|
||||
from yt_shared.utils.common import format_bytes
|
||||
|
||||
|
||||
def file_cleanup(file_paths: Iterable[str], log: logging.Logger = None) -> None:
|
||||
log = log or logging.getLogger()
|
||||
|
@ -22,3 +24,10 @@ def remove_dir(dir_path: str) -> None:
|
|||
def file_size(filepath: str) -> int:
|
||||
"""Return file size in bytes."""
|
||||
return os.path.getsize(filepath)
|
||||
|
||||
|
||||
def list_files(path: str) -> dict[str, str]:
|
||||
return {
|
||||
filename: format_bytes(file_size(os.path.join(path, filename)))
|
||||
for filename in os.listdir(path)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue