MCPcopy Create free account
hub / github.com/Borodutch/VideoDownloadBot

github.com/Borodutch/VideoDownloadBot @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
61 symbols 197 edges 36 files ⚖ MIT 0 documented · 0% ● updated 3d ago★ 145

Browse by type

⨍ Functions 45◇ Types & classes 16
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

@VideoDownloadBot

@VideoDownloadBot is a free Telegram bot that downloads videos. Send it a link from YouTube, TikTok, Instagram, X, Facebook, VK, Twitch, Dailymotion, SoundCloud or one of many other sites and it sends the video back in the chat, up to 2 GB. Add it to a group, or mention it in any chat, and it works there too. Reddit and Vimeo links need a login and don't work. Open source (MIT), built on yt-dlp.

How to use: open t.me/VideoDownloadBot, press Start, paste a link.

(videodownloadbot.com is a different bot, not this one.)

Website: videodl.borodutch.com (supported sites, how to use it in chats and groups, FAQ).

Questions

Can it download Instagram videos? Yes. Send it a link to a public Instagram reel or video post and it replies with the video file; a carousel's videos come back together as one album. Stories and posts from private accounts need an Instagram login, so they don't work.

Which Telegram bot downloads videos from YouTube or TikTok links? This one: paste the link into a chat with @VideoDownloadBot. Files up to 2 GB come back as videos you can watch, save or forward, and a link the bot has seen before comes back instantly.

Is it free? Yes. There is no paid plan and no sign-up, and the code is open source under the MIT license. Please download only videos you have the right to save.

How it works

Send it a link (or post one in a group it's in) and it replies with the video. Downloads go through yt-dlp; every sent file's Telegram file_id is kept in SQLite, so the same link (or the same video under another link) is resent instantly. A link cached before posts came back whole has its page read once more first, and gets that old copy, a post's first video alone, only when nothing new can be had for it: when the page can't be read now or shows no video any more, or what it shows fails to download, during a deploy too. It doesn't get it when the deploy's restart stops its job, or after Telegram fails to send one of its files, which may have gone out all the same (a request for the link from another chat that waited on that job still gets it). When it got the old copy because the page itself has nothing now (its site says the video is gone or unavailable, a rate limit and a bot check included, or the page shows no video), the link keeps that copy and its page isn't read again, except once to replace a copy that went out without its size. A link whose download failed, or whose page couldn't be read for something that says nothing about the page (a time limit, a crash), is tried again the next time. A post with several videos (an Instagram carousel, an X post, a page with several <video>s) comes back as one album of up to 10 of them, downloaded at once and resent whole from the cache; its pictures are left out, and a link to a channel, a Pinterest board or another list of links still gets its first video. When Telegram's flood control holds the bot back (a 429, mostly in busy groups), it waits as long as Telegram asks and sends again, up to 5 times and 2 minutes in all, and until the flood is over its messages to that chat go one at a time (the "Downloading…"/"Uploading…" status is skipped rather than waited for), so a finished video is delayed rather than lost. A status the chat doesn't take at all (in a group that lets the bot send videos but not texts, or lost to a server or network error) doesn't stop the download either, and the video still goes out if the chat takes it. In a group where the bot may send nothing at all, Telegram refuses a status the same way, so there each link costs a download, while a chat that refuses the bot outright (it was blocked or removed) still stops the job before its download. Originally developed by MaxiFilippov.

Run

bun install
TOKEN=123:abc bun bot.ts

Needs yt-dlp and ffmpeg on PATH (the Dockerfile ships both). The bot updates yt-dlp to the newest nightly (yt-dlp --update-to nightly) before it starts polling and then daily. A failed update, such as GitHub's 403 once the address the server shares has used up its hourly API limit, is logged and tried again up to six times, 1, 2, 4, 8, 16 and 32 minutes apart (the last just over an hour after the first), while the bot goes on with the yt-dlp it has. A try that hits its 5-minute limit leaves only that last try, 32 minutes later, since every yt-dlp run waits for an update that's running (yt-dlp gives up on a server that doesn't answer within 20 s, so that takes a transfer that trickles or a stuck run). bun test runs the checks.

Environment

  • TOKEN: Telegram bot token
  • BOT_API_URL: Bot API server, default https://api.telegram.org. Point it at a local Bot API server (--local) to upload up to 2000 MB instead of 50 MB
  • COOKIES: Netscape cookies file for yt-dlp (a logged-in YouTube session), default /cookies.txt, skipped if missing. It seeds DATA_DIR/cookies.txt, which keeps the cookies yt-dlp refreshes; replacing COOKIES reseeds it. Each job's yt-dlp runs get a copy of it, which goes back once the job is done (unless YouTube dropped the login or another job saved newer cookies meanwhile), and each of a post's downloads, which may run at once, gets a copy of the job's of its own, since a run writes its file back as it ends; those don't go back. A job's copy leaves Dailymotion's cookies out: yt-dlp keeps the API token it gets there and goes on using it after it expires (about 10 h later), and an ff=on there turns Dailymotion's family filter on, which refuses explicit videos; an expired token saved back failed every Dailymotion link from 2026-10-29 on (#878). Every 6 h the bot opens Watch Later to keep the session in use and checks it's still logged in
  • ADMIN_ID: Telegram user ID that gets a DM when the YouTube login dies
  • STORAGE_CHAT: chat the bot uploads guest-mode videos to before putting them into its guest reply (each upload is deleted right away), default ADMIN_ID (without either, guest downloads fail: a guest message the bot has answered hears so, while a reply that doesn't mention the bot still waiting for its answer gets none)
  • DATA_DIR: where bot.sqlite lives, default ./data (/data in Docker). The old and new containers share it during a deploy, and once it's up the bot doesn't wait for the other one's lock on it, since a wait would hold the whole bot still, so a statement that meets the lock fails at once. For the cache of sent files that costs a request a download at most: a row that can't be read counts as a miss and its link is downloaded again, a file that went out still reaches its chat and every request following its job when its row can't be written, and a dead file_id that can't be forgotten is downloaded again all the same
  • MAX_DOWNLOADS: videos downloaded and sent at once, default 8. With 4, the three long slots were all busy for 88–96% of a day's busiest six hours and long videos waited up to about 3 hours for one; the sites that fill them, adult CDNs at 0.1–1.3 MB/s, are slow per connection (Eporner kept its speed in five downloads at once), so more at once get more done. For the same reason an HLS or DASH download gets 4 of its fragments at once (--concurrent-fragments 4), in the one yt-dlp run its slot has (an HLS download that yt-dlp hands to ffmpeg still gets them one at a time). Long ones (over 10 minutes; some sites take 20–40 minutes for them) get at most MAX_DOWNLOADS − 1 of these slots (the one slot when it's 1), so long downloads never hold every slot. A video that doesn't say how long it is counts as long too, since an HLS/DASH stream or a file of unknown length can take as long, unless it's from Instagram or an X post (not a broadcast or a Space), whose reels and GIFs usually don't say and download in seconds, or yt-dlp says what all of it weighs and that's 100 MB at most. One person's jobs get at most MAX_DOWNLOADS − 1 slots in all (the one slot when it's 1) and, when long videos have more than one slot, all but one of those (6 of 7 with the default), so with three slots or more another person's link, long or short, doesn't wait for theirs; a free slot goes to whoever has the fewest jobs running and, of them, to whoever has the fewest waiting for one (then to the job that asked first), so someone with a few links doesn't wait hours behind the hundreds another person sent days before, and a job waiting for a slot holds none. A link that has to wait for a -J turn or a slot gets a "queued" status in private chats, and in groups when the bot was mentioned (elsewhere a burst of links would turn into a burst of replies against the group's message limit); a second request for the same link follows the job's status where a queued one would show: whatever the job is at when it comes in (queued, downloading or uploading), then each change. On a deploy, the links still waiting in the old container (for -J or for a slot), and long videos whose -J ends then, are told to send the link again (where they would hear they are queued); a short video that finds a free slot still goes. Jobs still waiting or downloading 2 s before the old container exits (the drain waits 15 s) won't finish there: their chats are told the same, where they already show a status or would hear they are queued (skipped, like any status, while the chat is in a flood), rather than keep "Downloading…" (one that still gets a cached copy of its file before the exit has the notice deleted). From then on no job begins a download or an upload, so a video whose -J ends in those 2 s isn't downloaded (a copy cached under its id still goes out), a download that ends then stops there instead of sending its video next to the notice, a download that fails then doesn't read the page again, and a post's job begins none of the downloads still in its line. A video's job whose "Downloading…" is still on its way at the cut, or a job whose page is being read again then, still begins its download, and stops short of the upload like the rest. A job whose upload has begun by then keeps its status, since a local Bot API server finishes an upload by path after the container exits (a second request following it is still told, as its own copy would go out only after the job's), while one that already shows "Uploading…" without having begun it is told like the rest. A request whose final answer is already on its way keeps that answer, and a chat that already got its file while a refresh of an unsized video ran hears nothing (a refresh that hasn't begun its upload doesn't begin it either). A guest-mode reply isn't told at that point and keeps its status, unless its job gets to the download or the upload after it, before the exit: then it hears to send the link again as well. One that doesn't mention the bot and has no answer yet isn't answered "Downloading…" from then on, as its video wouldn't be downloaded, nor told to send the link again, as a group message that didn't mention the bot isn't, and once the drain has begun it isn't answered just because its 30 s are up either (the exit could leave a page without a video showing "Downloading…" for good). yt-dlp's -J, which tells how long the video is, runs before the job takes a slot (up to MAX_DOWNLOADS at once, one person's up to MAX_DOWNLOADS − 1). Once it has its slot, a job sends the cached file if another link to the same video was downloaded meanwhile. The -J reads up to 10 items of a playlist (--playlist-items 1:10), with --flat-playlist, so a playlist of links (a channel, a set, another site's embeds) is listed without reading each link's page; such a playlist is read again as before, -J of its first item alone, and that one video goes out, cached under the link whatever the playlist's other items did. A Pinterest board, whose pins yt-dlp reads whole rather than as links, is a list too, so its first video goes out, taken from that same -J. A post whose items the page has itself (an Instagram carousel, an X post with several videos, a page with several <video>s) goes out as one album (sendMediaGroup) with the post's title and link as its caption. Its pictures aren't videos: yt-dlp lists each as null, says so and exits 1, and the bot takes the videos it printed all the same. A post's stream that can't be downloaded yet and a video yt-dlp says is too big are left out, and with one video left it goes out as any video. The post's job takes one slot like any job (long if any of the videos it downloads is, a cached one going as it is), which downloads the videos one after another, its long ones first, and each of the others that a free slot fits (the person's share and the long lane, as for a job, and never once a deploy's drain has begun; looked for as the job's slot moves on, as another download ends and every 5 s) takes that slot until its download is done. Once the job's own slot has none of its own left, it takes over one of those downloads (a long one first), whose slot is free for whoever waits at once, so a post never waits for a slot beyond its first, never holds more than its person's share, and holds no slot that isn't downloading. A video already cached goes into the album as it is; the downloads all end within the time a job of the post's lane has (each also within its own lane's), and a video that fails, or would take the post's files past 2000 MB together (they all wait on disk for the album), is left out. The post fails only with no video left, as its first one did. The album goes out once all are done, past the deploy cut-off check a single video gets; Telegram takes 2–10 videos (or audio files) in one, and a single file, files of different kinds or an album Telegram refuses (a fresh file i

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 42
Class 12
Interface 3
Method 3
Enum 1

Languages

TypeScript100%

Modules by API surface

src/helpers/updateDownloadRequests.ts5 symbols
src/helpers/report.ts5 symbols
src/helpers/MessageEditor.ts5 symbols
src/models/downloadRequestFunctions.ts4 symbols
src/models/downloadJobFunctions.ts4 symbols
src/models/Url.ts4 symbols
src/helpers/getThumbnailUrl.ts4 symbols
src/models/Chat.ts3 symbols
src/menus/language.ts3 symbols
src/models/DownloadRequest.ts2 symbols
src/models/DownloadJob.ts2 symbols
src/models/Context.ts2 symbols

For agents

$ claude mcp add VideoDownloadBot \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page