diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e758f0..bec926e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.2.3] - 2023-07-08 +### Changed +- Add stderr logging in case of exception raised by ffmpeg. + ## [1.2.2] - 2023-07-01 -## Fixed +### Fixed - Changed `pytube` src package to quickfix `pytube.exceptions.RegexMatchError` error. ## [1.2.1] - 2023-06-23 -## Changed +### Changed - Added error handler for `pytube.exceptions.RegexMatchError` error. diff --git a/Dockerfile b/Dockerfile index f01d5e2..b5712b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,9 +35,11 @@ CMD ["poetry", "run", "uvicorn", "ytdl_api.asgi:app", "--host", "0.0.0.0", "--po ############ Test ################### FROM dev as test +WORKDIR /app/ COPY --from=project-base /app/.venv /app/.venv +COPY ./tests /app/tests RUN poetry install -CMD ["pytest", "--cov-report", "html"] +CMD ["poetry", "run", "pytest", "/app/", "--cov", "--cov-report", "html"] ############ Prod ################### FROM project-base as prod RUN poetry install --without dev diff --git a/docker-compose.yaml b/docker-compose.yaml index 2c7a01d..b868290 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -17,3 +17,22 @@ services: tty: true networks: - default + ytdl-api-testing: + container_name: "ytdl-api-pytest" + build: + context: . + target: test + env_file: + - .env + volumes: + - "./ytdl_api/:/app/ytdl_api" + networks: + - default + deploy: + resources: + limits: + cpus: '0.50' + memory: 220M + reservations: + cpus: '0.25' + memory: 20M diff --git a/pyproject.toml b/pyproject.toml index 74f13e2..c941f12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,7 @@ target-version = "py310" [tool.poetry] name = "ytdl-api" -version = "1.2.2" +version = "1.2.3" description = "API for web-based youtube-dl client" authors = ["Nazar Oleksiuk "] license = "MIT" diff --git a/ytdl_api/downloaders.py b/ytdl_api/downloaders.py index 87cabea..36a17a4 100644 --- a/ytdl_api/downloaders.py +++ b/ytdl_api/downloaders.py @@ -1,5 +1,6 @@ import asyncio import tempfile +import logging from abc import ABC, abstractmethod from functools import partial from pathlib import Path @@ -18,6 +19,8 @@ from .schemas.responses import VideoInfoResponse from .types import VideoURL +logger = logging.getLogger() + class IDownloader(ABC): """ @@ -143,16 +146,20 @@ def download( # Converting to chosen format converted_file_path = directory_to_download_to / download.storage_filename asyncio.run(self.on_converting_callback(download)) - out, err = ( - ffmpeg.concat( - ffmpeg.input(downloaded_streams_file_paths["video"].as_posix()), - ffmpeg.input(downloaded_streams_file_paths["audio"].as_posix()), - a=1, - v=1, + try: + out, err = ( + ffmpeg.concat( + ffmpeg.input(downloaded_streams_file_paths["video"].as_posix()), + ffmpeg.input(downloaded_streams_file_paths["audio"].as_posix()), + a=1, + v=1, + ) + .output(converted_file_path.as_posix()) + .overwrite_output() + .run(capture_stdout=True, capture_stderr=True) ) - .output(converted_file_path.as_posix()) - .overwrite_output() - .run(capture_stdout=True, capture_stderr=True) - ) + except ffmpeg.Error as e: + logger.exception(e) + logger.error(e.stderr) # Finshing donwload process asyncio.run(self.on_finish_callback(download, converted_file_path))