树洞剪藏#剪藏#树洞剪藏

【开源】别让小鸡吃灰 - TG机器人,下载Youtube、X等网站视频转存到115\阿里云盘等网盘

2024 年 11 月 15 日1 分钟
分享Twitter / XTelegram微博

同步来源:树洞剪藏 源站剪藏 ID:65 原文地址:https://www.nodeseek.com/post-132752-1

打开原文 · 打开源站剪藏快照


【开源】别让小鸡吃灰 - TG机器人,下载Youtube、X等网站视频转存到115\阿里云盘等网盘

NodeSeek beta 日常 技术 情报 测评 交易 拼车 推广

【开源】别让小鸡吃灰 - TG机器人,下载Youtube、X等网站视频转存到115\阿里云盘等网盘

brains 楼主 124days ago edited 105days ago in 技术 #0

不知道为啥Github账号404了 直接上传到网盘了 有需要自取

https://gofile.io/d/KAKat9

最近X总是封号,一封号点赞的小视频就找不到了,正好618买了115网盘的8年会员,于是想用telegram的机器人把Youtube、X、tiktok视频下载到VPS上并转存到网盘里,翻了一圈没有能满足我需求的,于是花了点时间手撸了一个,实现很简单,理论上yt-dlp支持的网站这个脚本都支持

求鸡腿

预览图:

项目地址: https://github.com/Srainc/TBot-DSSC

项目说明:

TBot-DSSC

简介:

通过给Telegram机器发送URL,让服务器下载对应的视频并同步到网盘中

该脚本通过Telegram机器人接收、创建、反馈任务,通过yt-dlp下载视频,通过CloudDrive2添加网盘,通过Rclone对本地数据与网盘进行数据同步

环境需求:

Python >= 3.9

Rclone

CloudDrive2

ffmpeg

环境部署:

Python组件安装

pip install python-telegram-bot tqdm yt-dlp

ffmprg安装

apt install ffmpeg

Rclone安装

curl https://rclone.org/install.sh | sudo bash

CloudDrive2安装

curl -fsSL "https://raw.githubusercontent.com/lonelylose/clouddrive2/main/cd2.sh" | bash -s install

使用说明:

1、使用CloudDrive2添加对应网盘

2、使用Rclone添加CloudDrive2对应的WebDav服务

3、申请Telegram机器人

4、修改Python脚本中的API_TOKEN、DOWNLOAD_DIR、ALLOWED_USER_ID、MOUNT_PATH、RCLONE_NAME字段为对应的值

5、启动脚本

其他信息:

1、API_TOKEN字段需要通过官方机器人 https://t.me/BotFather 申请API后获得

2、ALLOWED_USER_ID字段可以通过 https://t.me/userinfobot 获得

3、可以使用nohup命令或者screen工具进行Python脚本的持久化运行

4、在debian11下正常运行,其它系统请自测

5、CloudDrive2、Rclone的使用方法请自行互联网搜索

免责声明:

1、使用该脚本则默认同意该声明

2、该脚本为个人测试用途,数据无价,请谨慎使用,使用该脚本导致的一切后果开发者不承担责任

16 0 117 引用 回复

1 2 3 4 5 .. 10

brains 楼主 56days ago edited 56days ago #91

保存为 xxx.py

import os import shlex import subprocess import logging from tqdm import tqdm from telegram import Update from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, CallbackContext from telegram.ext.filters import TEXT from urllib.parse import urlparse from datetime import datetime

替换为你的 Telegram 机器人 API Token

API_TOKEN = '1234567890:beTK1P4NtjnVnLs-gtLHgCQJXyoI0gWgRWg'

下载目录

DOWNLOAD_DIR = '/Down'

允许使用的用户 ID

ALLOWED_USER_ID = 1234567890 # 替换为你想允许的用户 ID

网盘挂载路径

MOUNT_PATH = '/115/Server'

Rclone 配置的项目名称 rclone config 可以查看

RCLONE_NAME = '115'

确保下载目录存在

os.makedirs(DOWNLOAD_DIR, exist_ok=True)

配置日志记录

LOGGING_ENABLED = os.getenv('LOGGING_ENABLED', 'true').lower() == 'true' if LOGGING_ENABLED: logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') else: logging.basicConfig(level=logging.CRITICAL) # 只记录严重错误

logger = logging.getLogger(name)

/start 命令的处理函数

async def start(update: Update, context: CallbackContext): if update.message.from_user.id != ALLOWED_USER_ID: await update.message.reply_text('您无权使用此机器人。') return await update.message.reply_text('你好!向我发送视频 URL,我将为您下载该视频。')

处理收到的 URL

async def handle_message(update: Update, context: CallbackContext): if update.message.from_user.id != ALLOWED_USER_ID: await update.message.reply_text('您无权使用此机器人。') return

url = update.message.text chat_id = update.message.chat_id

解析 URL 中的域名

domain = urlparse(url).netloc domain_dir = os.path.join(DOWNLOAD_DIR, domain)

确保域名对应的目录存在

os.makedirs(domain_dir, exist_ok=True) current_date = datetime.now().strftime('%Y-%m-%d')

download_command = f'yt-dlp -o {shlex.quote(domain_dir + "/%(title).30s_" + current_date + ".%(ext)s")} {shlex.quote(url)}'

发送下载开始消息

await update.message.reply_text(f'开始下载:{url}')

try:

运行 yt-dlp 命令并捕获输出

process = subprocess.Popen(shlex.split(download_command), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, encoding='utf-8')

progress_message = await update.message.reply_text('下载进度:0%') last_progress = 0

while True: output = process.stdout.readline() if output == '' and process.poll() is not None: break if output: logger.info(output.strip())

解析进度信息

if '[download]' in output and '%' in output: progress = output.split('%')[0].split()[-1].strip() try: progress = float(progress) if progress >= last_progress + 10: last_progress = progress await progress_message.edit_text(f'下载进度:{progress}%') except ValueError: pass

捕获下载过程中的错误信息

stderr_output = process.stderr.read() if process.returncode == 0: await update.message.reply_text('下载完成!') logger.info(f'Download complete for {url}')

同步文件到115:/115/Server

sync_command = f'rclone move {shlex.quote(DOWNLOAD_DIR)} {RCLONE_NAME}:{shlex.quote(MOUNT_PATH)}' sync_process = subprocess.run(shlex.split(sync_command), capture_output=True, text=True)

if sync_process.returncode == 0: await update.message.reply_text('文件同步完成!') logger.info('File sync complete') else: await update.message.reply_text(f'文件同步错误:{sync_process.stderr.strip()}') logger.error(f'File sync error: {sync_process.stderr.strip()}')

else: await update.message.reply_text(f'Error: {stderr_output.strip()}') logger.error(f'Error: {stderr_output.strip()}') except Exception as e: await update.message.reply_text(f'Error: {str(e)}') logger.error(f'Exception occurred: {str(e)}')

def main(): application = ApplicationBuilder().token(API_TOKEN).build() application.add_handler(CommandHandler("start", start)) application.add_handler(MessageHandler(TEXT, handle_message)) # 更正后的过滤器

运行机器人

application.run_polling()

if name == 'main': main()

0 0 引用 回复

亚历山大锤 124days ago #1

支持

无欲无求,清心寡欲!收想收的小鸡鸡,玩好玩的小鸡鸡!

0 0 引用 回复

miaowmint 124days ago #2

点个star

TG联系 @miaowmint

0 0 引用 回复

sunpma 124days ago #3

bd

博客 · 导航 · 探针 · 电报 · 中文博客RSS频道

0 0 引用 回复

wu 124days ago #4

不错👍

0 0 引用 回复

dilidili 124days ago #5

绑定

✈️ TG联系我 |✉️ 站内PM |❤️ 免费图床

长期出小红卡余额,谷歌汇率多0.1

0 0 引用 回复

tian866 124days ago #6

bd

0 0 引用 回复

xy Dev 124days ago #7

前排支持

✈️ TG机器人 || ✉️ PM站内 || ⛱️ 阿里欧克之针 || ⚛️ IP质量体检脚本 || ✅ 改版解锁检测脚本

0 0 引用 回复

Tionmon 124days ago #8

bd

0 0 引用 回复

dayvs 124days ago #9

支持

| ✉️站内私信 |

0 0 引用 回复

hide3110 124days ago #10

给大佬点赞👍

0 0 引用 回复

1 2 3 4 5 .. 10

内容 预览 对照

支持 markdown语法

鼓励友善发言,禁止人身攻击

xxxxxxxxxx

1

1 ​

AC娘

洋葱头

小黄鸡

发布评论

88

等级 Lv 4 鸡腿 1907 关注 0 通知 0

主题帖 10 评论数 290 粉丝 2 收藏 182 发帖

快捷功能区 推荐阅读 管理记录 幸运抽奖 邀请好友 合作商家 友站链接

所有版块 日常 技术 情报 测评 交易 曝光 拼车 生活 贴图 推广 内版 Dev 无意义 沙盒

📈用户数目📈

目前论坛共有22061位seeker

🎉欢迎新用户🎉

huotuchensha

alanlu

onvo

无欲无求

相关网站 LowEndTalk LowEndSpirit HostLoc ServerHunter

站内导航 关于本站 隐私协议 RSS订阅 sitemap

商业推广 商家申请规则 Premium Provider 合作商家展示

其他平台 电报频道 电报群组

联系我们

Copyright © 2022 - 2024 All rights Reserved

相关文章