搭建私人youtube下载器并上传到电报BOT

1. 搭建下载器

查看
GitHub

2.上传到电报BOT

mport os
import telepot
from telepot.loop import MessageLoop

# Replace with your bot's token and chat_id
BOT_TOKEN = '填写'
CHAT_ID = '填写'

def find_latest_video(directory):
    video_files = [f for f in os.listdir(directory) if f.endswith(('.mp4', '.avi', '.mkv', '.mov'))]
    if not video_files:
        return None
    video_files.sort(key=lambda x: os.path.getmtime(os.path.join(directory, x)), reverse=True)
    return os.path.join(directory, video_files[0])

def send_video(bot, chat_id, video_path):
    with open(video_path, 'rb') as video:
        bot.sendVideo(chat_id, video)

def main():
    directory = '/path/to/downloads'       # 下载路径
    latest_video = find_latest_video(directory)

    if latest_video:
        print(f"Latest video found: {latest_video}")
        bot = telepot.Bot(BOT_TOKEN)
        send_video(bot, CHAT_ID, latest_video)
        print("Video sent successfully")
    else:
        print("No video files found in the specified directory")

if __name__ == '__main__':
    main()

3. 定时

crontab -e

*/15 * * * * /usr/bin/python3 /root/py/xz.py 2>&1 | tee /root/py/xz.log     # 15分钟执行一次并生成日志

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注