From 56b0dd2a04ee7b80208ebe82534354313c220cab Mon Sep 17 00:00:00 2001 From: Benny Date: Sat, 26 Aug 2023 13:04:29 +0200 Subject: [PATCH] copy file to other path #282 --- README.md | 2 +- ytdlbot/config.py | 1 + ytdlbot/tasks.py | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b10f6903..6d547053 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 c432d446..21ce655a 100644 --- a/ytdlbot/config.py +++ b/ytdlbot/config.py @@ -64,3 +64,4 @@ 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 a8215c87..94a1e5cf 100644 --- a/ytdlbot/tasks.py +++ b/ytdlbot/tasks.py @@ -13,6 +13,7 @@ import pathlib import random import re +import shutil import subprocess import tempfile import threading @@ -42,6 +43,7 @@ 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()