1

How can I quickly download audio from YouTube by URL or ID and send it to Telegram bot? I've been using youtube-dl to download audio, save it on hosting and after that send it to user. It takes 1-2 minutes to do that. But other bots (like this one @LyBot) do this with the speed of light. How do they do this?

hellcaster
  • 79
  • 1
  • 7

1 Answers1

2

As it says in their documentation "I send audio instantly if it has already been downloaded through me earlier. Otherwise, the download usually takes no more than 10 seconds."

They probably store a file the first time its downloaded by any user so that it can be served instantly for subsequent requests.

ybl
  • 1,510
  • 10
  • 16
  • Oh, yes. I've not noticed that. Thanks. And other question. How do you think they find a particular song in that huge list? Some sort of DB or simply go through every single item? – hellcaster Apr 21 '22 at 07:17
  • 1
    It should be a simple mapping (in any database) of the video id as the primary key (which you see at the end of a YouTube URL) to the file location (local path/S3 path) – ybl Apr 21 '22 at 12:18