diff --git a/README.md b/README.md index b10f690..6d54705 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ You can configure all the following environment variables: * FREE_DOWNLOAD: free download count per day * TOKEN_PRICE: token price per 1 USD * GOOGLE_API_KEY: YouTube API key, required for YouTube video subscription. - +* RCLONE_PATH: rclone path to upload files to cloud storage ## 3.2 Set up init data If you only need basic functionality, you can skip this step. diff --git a/ytdlbot/config.py b/ytdlbot/config.py index c432d44..21ce655 100644 --- a/ytdlbot/config.py +++ b/ytdlbot/config.py @@ -64,3 +64,4 @@ TOKEN_PRICE = os.getenv("BUY_UNIT", 20) # one USD=20 credits RATE_LIMIT = os.getenv("RATE_LIMIT", 20) SS_YOUTUBE = os.getenv("SS_YOUTUBE", "https://ytdlbot.dmesg.app?token=123456") +RCLONE_PATH = os.getenv("RCLONE") diff --git a/ytdlbot/tasks.py b/ytdlbot/tasks.py index a8215c8..94a1e5c 100644 --- a/ytdlbot/tasks.py +++ b/ytdlbot/tasks.py @@ -13,6 +13,7 @@ import os import pathlib import random import re +import shutil import subprocess import tempfile import threading @@ -42,6 +43,7 @@ from config import ( ENABLE_QUEUE, ENABLE_VIP, OWNER, + RCLONE_PATH, RATE_LIMIT, WORKERS, ) @@ -278,6 +280,11 @@ def ytdl_normal_download(client: Client, bot_msg: typing.Union[types.Message, ty bot_msg.edit_text("Download success!✅") + # setup rclone environment var to back up the downloaded file + if RCLONE_PATH: + for item in os.listdir(temp_dir.name): + logging.info("Copying %s to %s", item, RCLONE_PATH) + shutil.copy(os.path.join(temp_dir.name, item), RCLONE_PATH) temp_dir.cleanup()