diff --git a/README.md b/README.md index 6e987cd..bb065a1 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ You can choose to become 'VIP' if you really need large traffic. And also, you c 8. support sending as file or streaming as video 9. supports celery worker distribution - faster than before. 10. subscriptions to YouTube Channels +11. cache mechanism - for the same video you'll only have to download once. ![](assets/2.jpeg) @@ -102,7 +103,7 @@ you can configure all the following environment variables: * APP_ID: **REQUIRED**, get it from https://core.telegram.org/ * APP_HASH: **REQUIRED** * TOKEN: **REQUIRED** -* REDIS: **REQUIRED if you need VIP mode** ⚠️ Don't publish your redis server on the internet. ⚠️ +* REDIS: **REQUIRED if you need VIP mode and cache** ⚠️ Don't publish your redis server on the internet. ⚠️ * OWNER: owner username * QUOTA: quota in bytes @@ -127,6 +128,7 @@ you can configure all the following environment variables: * GOOGLE_API_KEY: YouTube API key, required for YouTube video subscription. * AUDIO_FORMAT: audio format, default is m4a. You can set to any known and supported format for ffmpeg. For example,`mp3`, `flac`, etc. ⚠️ m4a is the fastest. Other formats may affect performance. +* ARCHIVE_ID: group or channel id/username. All downloads will send to this group first and then forward to end user. ## 3.2 Set up init data @@ -134,7 +136,7 @@ If you only need basic functionality, you can skip this step. ### 3.2.1 Create MySQL db -Required for VIP, settings, YouTube subscription and notification. +Required for VIP, settings, YouTube subscription. ```shell docker-compose up -d diff --git a/ytdlbot/config.py b/ytdlbot/config.py index 253c3c2..9f4860c 100644 --- a/ytdlbot/config.py +++ b/ytdlbot/config.py @@ -51,4 +51,5 @@ MYSQL_HOST = os.getenv("MYSQL_HOST") MYSQL_USER = os.getenv("MYSQL_USER", "root") MYSQL_PASS = os.getenv("MYSQL_PASS", "root") -AUDIO_FORMAT = os.getenv("AUDIO_FORMAT", "m4a") \ No newline at end of file +AUDIO_FORMAT = os.getenv("AUDIO_FORMAT", "m4a") +ARCHIVE_ID = os.getenv("ARCHIVE_ID") diff --git a/ytdlbot/tasks.py b/ytdlbot/tasks.py index 46c35e0..63a66e7 100644 --- a/ytdlbot/tasks.py +++ b/ytdlbot/tasks.py @@ -26,7 +26,8 @@ from pyrogram import idle from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from client_init import create_app -from config import AUDIO_FORMAT, BROKER, ENABLE_CELERY, ENABLE_VIP, WORKERS +from config import (ARCHIVE_ID, AUDIO_FORMAT, BROKER, ENABLE_CELERY, + ENABLE_VIP, WORKERS) from constant import BotText from db import Redis from downloader import (edit_text, sizeof_fmt, tqdm_progress, upload_hook, @@ -257,6 +258,8 @@ def ytdl_normal_download(bot_msg, client, url): cap = f"`{filename}`\n\n{url}\n\nInfo: {meta['width']}x{meta['height']} {size} {meta['duration']}s" \ f"\n{remain}\n{worker}" settings = get_user_settings(str(chat_id)) + if ARCHIVE_ID: + chat_id = ARCHIVE_ID if settings[2] == "document": logging.info("Sending as document") res_msg = client.send_document(chat_id, video_path, @@ -284,6 +287,8 @@ def ytdl_normal_download(bot_msg, client, url): unique = get_unique_clink(clink, settings) red.add_send_cache(unique, res_msg.chat.id, res_msg.message_id) red.update_metrics("video_success") + if ARCHIVE_ID: + client.forward_messages(bot_msg.chat.id, ARCHIVE_ID, res_msg.message_id) bot_msg.edit_text('Download success!✅') else: client.send_chat_action(chat_id, 'typing')