【发布时间】:2021-03-21 12:02:31
【问题描述】:
我正在尝试制作一个电报机器人,它应该使用 pytube 为用户下载 youtube 视频。 但它会为我而不是用户下载视频...... 它要求提供链接,然后您粘贴一个链接,但机器人会在脚本运行的同一目录中为我下载它,而不是为您下载它!我把它部署在云端看看会发生什么,但我报错了
如何解决它为输入链接的人下载视频的问题?!?
这是我的代码:
def ask_for_link(update,context):
bot.send_message(chat_id=update.effective_chat.id ,text="Please Paste the video link here ... ")
return DOWNLOADER
def Downloader(update,context):
try:
link=str(update.message.text)
Video_Url = YouTube(link)
Video= Video_Url.streams.first()
Video.download()
bot.send_message(chat_id=update.effective_chat.id , text = f"{Video.title} has Downloaded successfully ... ")
quit(update,context)
except Exception:
bot.send_message(chat_id=update.effective_chat.id , text = "Oooops !!! Something Went Wrong ... \n\n ( Make sure that you wrote the link correctly )")
quit(update,context)
DOWNLOADER = 0
YouTube_Downloader_converstation_handler=ConversationHandler(
entry_points=[CommandHandler("YouTubeDownloader", ask_for_link)] ,
states={
DOWNLOADER :[MessageHandler(Filters.text , callback=Downloader )]
},
fallbacks=[CommandHandler("quit" , quit)])
dispatcher.add_handler(YouTube_Downloader_converstation_handler)
【问题讨论】:
标签: python youtube telegram-bot python-telegram-bot pytube