Support me on BuyMeACoffee
Thanks to Contributor - @IIlIlIlIIIlllIIlIIlIllIIllIlIIIl - chelaxian
Download private YouTube/videos using a cookie file.
Test free bot - https://t.me/tgytdlp_bot
https://upekshaip.com/projects/-O0t36gRpfJR1p8KB7vU
- First, add your bot to the logging channel and subscription channel. Both are required.
- Star and fork this repository. Then rename the file _config.py to config.py.
- Add your configuration to the config.py file.
sudo apt update
sudo apt install git
git clone https://github.com/upekshaip/tg-ytdlp-bot.git
cd tg-ytdlp-bot
sudo mv _config.py config.py
nano config.py
Edit your configuration before deployment. After your edits, proceed with the Docker build steps below.
YouTube rotates account cookies frequently on open YouTube browser tabs as a security measure. To export cookies that will remain working with yt-dlp, you will need to export cookies in such a way that they are never rotated.
One way to do this is through a private browsing/incognito window:
- Open a new private browsing/incognito window and log into YouTube
- Open a new tab and close the YouTube tab
- Export youtube.com cookies from the browser then close the private browsing/incognito window so the session is never opened in the browser again.
For export you can use browser extension Cookie-Editor
create in project folder subfolder cookies
and place cookie.txt
extracted from YouTube here
cd tg-ytdlp-bot
mkdir cookies
nano cookie.txt
sudo docker build . -t tg-public-bot
sudo docker ps -a
sudo docker run tg-public-bot
(optional) If you want to use /cookies_from_browser
command, after docker deployment you need to enter your docker CMD and install desktop environment (GUI) and Browser into your docker container.
Also you will need download yt-dlp
binary into your Docker container. See (Optional) Preparing yt-dlp
for /cookies_from_browser
If you prefer local deployment rather than docker container, you should use this commands:
sudo apt update
sudo apt install git python3.10 python3-pip python3.10-venv
git clone https://github.com/upekshaip/tg-ytdlp-bot.git
cd tg-ytdlp-bot
sudo mv _config.py config.py
nano config.py
Edit your configuration before deployment.
python3 -m venv venv
source venv/bin/activate
pip install --no-cache-dir -r requirements.txt
pip uninstall urllib3 -y
pip install --no-cache-dir --force-reinstall "urllib3==1.26.20"
pip install --no-deps moviepy==1.0.3
python3 magic.py
spoiler
If you prefer local deployment rather that docker container you also need to install ffmpeg
ffmpeg is essential since yt-dlp relies on it for merging streams (and in some cases for transcoding or extracting thumbnails). To install ffmpeg on a Debian-based system, run:
sudo apt-get update
sudo apt-get install -y ffmpeg
Verify the installation:
ffmpeg -version
spoiler
To use the /cookies_from_browser
command (which extracts cookies from installed browsers on your server), ensure that the yt-dlp binary is set up properly:
-
Download
yt-dlp
Visit the officialyt-dlp
releases page and download the binary for your CPU architecture (e.g.,yt-dlp_x86_64
,yt-dlp_arm
, etc.).
Place the binary executable in thetg-ytdlp-bot
project folder. -
Rename and make it executable
mv yt-dlp_linux yt-dlp chmod +x yt-dlp
-
Create a symbolic link
Create a symlink so thatyt-dlp
can be run from any directory (for example, in/usr/local/bin
):sudo ln -s /full/path/to/tg-ytdlp-bot/yt-dlp /usr/local/bin/yt-dlp
Ensure
/usr/local/bin
is in yourPATH
. Now you can runyt-dlp
directly.
(Also in that case you must install desktop environment (GUI) and any supported by yt-dlp
browser by yourself)
The /audio command downloads audio from a given video URL. It extracts the best available audio track, converts it to MP3, and sends the audio file to the user. After sending, the downloaded file is removed to prevent disk clutter.
Usage example:
/audio https://youtu.be/dQw4w9WgXcQ?si=Vqh0HJVNn_99bhj4
The /format command allows users to set a custom download format for their videos. Users can either supply a custom format string or choose from a preset menu.
Main Menu Options:
- 💻<=4k (best for desktop TG app)
- 📱<=FullHD (best for mobile TG app)
- 📈bestvideo+bestaudio (MAX quality)
- 📉best (no ffmpeg)
- Others – opens a full resolution menu (see below)
- 🎚 custom – for entering a custom format string
- 🔙 Cancel – cancels the selection
Full Resolution Menu (triggered by "Others"):
- 144p (256×144)
- 240p (426×240)
- 360p (640×360)
- 480p (854×480)
- 720p (1280×720)
- 1080p (1920×1080)
- 1440p (2560×1440)
- 2160p (3840×2160)
- 4320p (7680×4320)
- A Back button returns to the main menu.
Usage example:
/format
Then select the desired option from the menu.
- /check_cookie - Check the cookie file.
- /cookies_from_browser - Get cookies from your browser.
- /help - Display help message.
- /start - Start the bot.
- /clean - Clean your working directory.
- /usage - Show your usage statistics.
- /audio - Download audio from a video URL.
- /format - Choose media format options.
- start - Start the bot.
- help - Send help text.
- run_time - Show bot runtime.
- log - Get user logs (e.g.,
/log 10101010
). - broadcast - Broadcast a message to all users (reply to any message with this command).
- clean - Clean the working directory.
- usage - Get all logs.
- check_cookie - Check the cookie file.
- save_as_cookie - Save text as cookie.
- download_cookie - Download the cookie file.
- cookies_from_browser - Get cookies from your browser.
- format - Choose media format options.
- block_user - Block a user (e.g.,
/block_user 10101010
). - unblock_user - Unblock a user (e.g.,
/unblock_user 10101010
). - all_users - Get all users.
- all_blocked - Get all blocked users.
- all_unblocked - Get all unblocked users.
-
https://blabla.blaa
Download the video with its original name.
If it is a playlist, only the first video is downloaded. -
https://blabla.blaa*1*3
Download a specified range of videos from the playlist with their original names. -
https://blabla.blaa*1*3*name
Download a specified range of videos from the playlist with a custom name.
Videos will be named as:name - Part 1
name - Part 2
This bot allows you to download videos and audio, and also work with playlists.
• Simply send a video link and the bot will start downloading.
• For playlists, specify the range of indexes separated by asterisks (e.g. https://example.com*1*4
) to download videos from position 1 to 4.
• You can set a custom playlist name by adding it after the range (e.g. https://example.com*1*4*My Playlist
).
• To change the caption of a video, reply to the video with your message – the bot will send the video with your caption.
• To extract audio from a video, use the /audio command (e.g. /audio https://example.com
).
• Upload a cookie file to download private videos and playlists.
• Check or update your cookie file with /check_cookie, /download_cookie, /save_as_cookie and /cookies_from_browser commands.
• To clean your workspace on server from bad files (e.g. old cookies or media) use /clean command (might be helpfull for get rid of errors).
• See your usage statistics and logs by sending the /usage command.
- Per-user cookie download.
- Per-user database.
- Custom playlist naming.
- MP3 audio download support (/audio command).
To prevent your server from filling up with downloaded files, you can set up a crontab task that runs every 24 hours and deletes all files in user directories (except for cookie.txt
and logs.txt
).
For example, add the following line to your crontab:
0 0 * * * /usr/bin/find /root/Telegram/tg-ytdlp-bot/users -type f ! -name "cookie.txt" ! -name "logs.txt" -delete
Explanation:
0 0 * * *
– Executes the command every day at midnight./usr/bin/find /CHANGE/ME/TO/REAL/PATH/TO/tg-ytdlp-bot/users -type f
– Searches for all files under the users directory.! -name "cookie.txt" ! -name "logs.txt"
– Excludescookie.txt
andlogs.txt
files from deletion.-delete
– Deletes the files found.
Add a custom formatter selector for downloads.Enhance MP3 support.- Add Google Drive support to store files.
Below is an example section for your GitHub README.md that explains how to set up Firebase for your Telegram bot, including creating a Firebase project, setting up a Realtime Database with authentication, and creating a user.
This section describes how to create a Firebase project, set up the Realtime Database with authentication, create a test user, and integrate Firebase into your Telegram bot.
- Go to the Firebase Console and click Add Project (or select an existing project).
- Follow the setup wizard to create your new project.
- After the project is created, navigate to Project Settings and copy your configuration parameters (such as
apiKey
,authDomain
,databaseURL
,projectId
, etc.). These values are required for configuring the connection in your bot.
- In the Firebase Console, select Realtime Database.
- Click Create Database.
- Choose your database location and set the mode. For initial testing, you may choose Test Mode (keep in mind that test mode does not enforce authentication).
- Once your database is created, update its security rules as described in Step 4.
- In the left-hand menu of the Firebase Console, select Authentication.
- Click Get Started.
- Navigate to the Sign-in Method tab and enable the desired provider. For a basic setup, enable Email/Password:
- Click on Email/Password.
- Toggle the switch to Enable.
- After enabling the sign-in method, create a test user manually in the Users tab, or implement user registration in your application.
To restrict access to your database only to authenticated users, update your security rules as follows:
{
"rules": {
// Allow access only to authenticated user with certain email
".read": "auth != null && auth.token.email === '[email protected]'",
".write": "auth != null && auth.token.email === '[email protected]'"
}
}
These rules allow read and write operations only if the request contains a valid idToken
—meaning the user is authenticated.