Skip to content

Commit

Permalink
Merge pull request #3 from deepaerial/ffmpeg_error_handling
Browse files Browse the repository at this point in the history
Add error logging for ffmpeg exception
  • Loading branch information
deepaerial committed Jul 8, 2023
2 parents b452aff + 6e48726 commit 88f694d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nazarii.oleksiuk@gmail.com>"]
license = "MIT"
Expand Down
27 changes: 17 additions & 10 deletions ytdl_api/downloaders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import tempfile
import logging
from abc import ABC, abstractmethod
from functools import partial
from pathlib import Path
Expand All @@ -18,6 +19,8 @@
from .schemas.responses import VideoInfoResponse
from .types import VideoURL

logger = logging.getLogger()


class IDownloader(ABC):
"""
Expand Down Expand Up @@ -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))

0 comments on commit 88f694d

Please sign in to comment.