From 79ff67b41050c4431724fc72c4196ae90f582f7b Mon Sep 17 00:00:00 2001 From: Taras Terletskyi <888784+tropicoo@users.noreply.github.com> Date: Sat, 5 Nov 2022 22:20:27 +0200 Subject: [PATCH] Update README --- {assets => .assets}/download_failed.png | Bin {assets => .assets}/download_success.png | Bin .dockerignore | 2 +- README.md | 10 ++++++++-- bot/core/bot/launcher.py | 12 ++++++------ bot/core/config/schema.py | 4 ++-- bot/core/handlers/success.py | 2 +- bot/core/tasks/upload.py | 2 +- bot/core/workers/success.py | 2 +- envs/.env_common | 2 +- worker/core/video_service.py | 4 ++-- 11 files changed, 23 insertions(+), 17 deletions(-) rename {assets => .assets}/download_failed.png (100%) rename {assets => .assets}/download_success.png (100%) diff --git a/assets/download_failed.png b/.assets/download_failed.png similarity index 100% rename from assets/download_failed.png rename to .assets/download_failed.png diff --git a/assets/download_success.png b/.assets/download_success.png similarity index 100% rename from assets/download_success.png rename to .assets/download_success.png diff --git a/.dockerignore b/.dockerignore index 8401777..d253994 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,7 +4,7 @@ Dockerfile.base LICENSE README.md -assets +.assets docker-compose.yml pyproject.toml diff --git a/README.md b/README.md index 17d7aef..0482fb2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## yt-dlp-bot Simple and reliable YouTube Download Telegram Bot. -![frames](assets/download_success.png) +![frames](.assets/download_success.png) ## 😂 Features * Download videos from any [yt-dlp](https://github.com/yt-dlp/yt-dlp) supported website @@ -51,11 +51,17 @@ After pasting video URL(s) bot will send you appropriate message whether they we 1. If you want to change `yt-dlp` download options, go to the `worker/ytdl_opts` directory, copy content from `default.py` to `user.py` and modify as you wish by checking [available options](https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L180). +2. Default max simultaneous video downloads by worker service is 2. Change the `MAX_SIMULTANEOUS_DOWNLOADS` + variable in `envs/.env_worker` to desired value but keep in mind `yt-dlp` may glitch when the value is high. +3. Worker service (particularly the FFmpeg process) makes a JPEG thumbnail from the video. It's needed when + you choose to upload the video to the Telegram chat. By default, it tries to make it on the 10th second + of the video, but if the video is shorter, it will make it on `video length / 2` time point because the FFmpeg + process will error out. Change the `THUMBNAIL_FRAME_SECOND` variable if needed in the `envs/.env_worker` file. ## 🛑 Failed download If your URL can't be downloaded for some reason, you will see this -![frames](assets/download_failed.png) +![frames](.assets/download_failed.png) ## Access - **API**: default port `1984` and no auth. Port can be changed in `docker-compose.yml` diff --git a/bot/core/bot/launcher.py b/bot/core/bot/launcher.py index e75bbd6..e1e7ef9 100644 --- a/bot/core/bot/launcher.py +++ b/bot/core/bot/launcher.py @@ -10,14 +10,14 @@ from core.workers.manager import RabbitWorkerManager from yt_shared.rabbit import get_rabbitmq from yt_shared.utils.tasks.tasks import create_task -REGEX_NOT_START_WITH_SLASH = r'^[^/]' - class BotLauncher: """Bot launcher which parses configuration file, creates bot with camera instances and finally starts the bot. """ + REGEX_NOT_START_WITH_SLASH = r'^[^/]' + def __init__(self) -> None: """Constructor.""" self._log = logging.getLogger(self.__class__.__name__) @@ -45,7 +45,7 @@ class BotLauncher: cb.on_message, filters=filters.user(list(self._bot.allowed_users.keys())) & filters.chat(list(self._bot.allowed_users.keys())) - & filters.regex(REGEX_NOT_START_WITH_SLASH), + & filters.regex(self.REGEX_NOT_START_WITH_SLASH), ), ) @@ -55,7 +55,7 @@ class BotLauncher: self._rabbit_mq.register(), task_name=task_name, logger=self._log, - exception_message='Task %s raised an exception', + exception_message='Task "%s" raised an exception', exception_message_args=(task_name,), ) @@ -67,7 +67,7 @@ class BotLauncher: YtdlpNewVersionNotifyTask(bot=self._bot).run(), task_name=task_name, logger=self._log, - exception_message='Task %s raised an exception', + exception_message='Task "%s" raised an exception', exception_message_args=(task_name,), ) @@ -75,7 +75,7 @@ class BotLauncher: """Start telegram bot and related processes.""" await self._bot.start() - self._log.info('Starting %s bot', (await self._bot.get_me()).first_name) + self._log.info('Starting "%s" bot', (await self._bot.get_me()).first_name) await self._bot.send_startup_message() await self._start_tasks() await self._bot.run_forever() diff --git a/bot/core/config/schema.py b/bot/core/config/schema.py index de44e3b..f951731 100644 --- a/bot/core/config/schema.py +++ b/bot/core/config/schema.py @@ -43,7 +43,7 @@ class UserSchema(BaseUserSchema): return False -def change_type(values: list[int]) -> list[BaseUserSchema]: +def _change_type(values: list[int]) -> list[BaseUserSchema]: return [BaseUserSchema(id=id_) for id_ in values] @@ -54,7 +54,7 @@ class ApiSchema(RealBaseModel): silent: StrictBool video_caption: VideoCaptionSchema - _transform_chat_ids = validator('upload_to_chat_ids', pre=True)(change_type) + _transform_chat_ids = validator('upload_to_chat_ids', pre=True)(_change_type) class TelegramSchema(RealBaseModel): diff --git a/bot/core/handlers/success.py b/bot/core/handlers/success.py index b88db5c..ce4caa7 100644 --- a/bot/core/handlers/success.py +++ b/bot/core/handlers/success.py @@ -50,7 +50,7 @@ class SuccessHandler(AbstractHandler): ).run(), task_name=task_name, logger=self._log, - exception_message='Task %s raised an exception', + exception_message='Task "%s" raised an exception', exception_message_args=(task_name,), ) diff --git a/bot/core/tasks/upload.py b/bot/core/tasks/upload.py index d8ea828..b9b4cc4 100644 --- a/bot/core/tasks/upload.py +++ b/bot/core/tasks/upload.py @@ -154,7 +154,7 @@ class UploadTask(AbstractTask): self._save_cache_to_db(video), task_name=db_cache_task_name, logger=self._log, - exception_message='Task %s raised an exception', + exception_message='Task "%s" raised an exception', exception_message_args=(db_cache_task_name,), ) diff --git a/bot/core/workers/success.py b/bot/core/workers/success.py index 6b4595d..6342e97 100644 --- a/bot/core/workers/success.py +++ b/bot/core/workers/success.py @@ -20,6 +20,6 @@ class SuccessResultWorker(AbstractResultWorker): self.HANDLER_CLS(body=body, bot=self._bot).handle(), task_name=task_name, logger=self._log, - exception_message='Task %s raised an exception', + exception_message='Task "%s" raised an exception', exception_message_args=(task_name,), ) diff --git a/envs/.env_common b/envs/.env_common index b64c51e..9170d2d 100644 --- a/envs/.env_common +++ b/envs/.env_common @@ -18,5 +18,5 @@ RABBITMQ_PORT=5672 REDIS_HOST=yt_redis -LOG_LEVEL=DEBUG +LOG_LEVEL=INFO TMP_DOWNLOAD_PATH=/tmp/download_tmpfs diff --git a/worker/core/video_service.py b/worker/core/video_service.py index 3cf64a7..86bb3f7 100644 --- a/worker/core/video_service.py +++ b/worker/core/video_service.py @@ -102,7 +102,7 @@ class VideoService: self._copy_file_to_storage(video), task_name=task_name, logger=self._log, - exception_message='Task %s raised an exception', + exception_message='Task "%s" raised an exception', exception_message_args=(task_name,), ) @@ -113,7 +113,7 @@ class VideoService: MakeThumbnailTask(thumb_path, file_path, duration=duration).run(), task_name=MakeThumbnailTask.__class__.__name__, logger=self._log, - exception_message='Task %s raised an exception', + exception_message='Task "%s" raised an exception', exception_message_args=(MakeThumbnailTask.__class__.__name__,), )