skip to Main Content

I’m trying to make a telegram bot that is supposed to download youtube videos using pytube for the user.
but it downloads the videos for me instead of the user …
It asks for the link and then you paste a link but the bot downloads it for me in the same directory that the script is running instead of downloading it for you! I deployed it on the cloud to see what will happen but I gave an error

How can I fix it that it downloads videos for the person who enters the link ?!?

Here is my code :


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 ... nn ( 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)


2

Answers


  1. The method Video.download() downloads the video and saves it locally.

    If you want the user to have the video than you have to send it to them (and if you want, you can delete the file afterwards)

    For more information on how to send a video you can see the method send_video or send_document on the official documentation of the python-telegram-bot library

    One thing to note: According to Telegram official APIs (source)

    Bots can currently send files of any type of up to 50 MB in size

    Login or Signup to reply.
  2. its not possible to download any type of file to user computer(until or unless he/she do it herself/himself) because of security propose if a bot can download a file in user system it will be a big security loop hole because then you can easily get into anyone system just by downloading a small script in user computer(hope i cleared my point).you can provide video to user which can later be downloaded by user manually

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search