2021-08-29 02:19:49 +00:00
|
|
|
# ytdlbot
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
[![docker image](https://github.com/tgbot-collection/ytdlbot/actions/workflows/builder.yaml/badge.svg)](https://github.com/tgbot-collection/ytdlbot/actions/workflows/builder.yaml)
|
|
|
|
|
2021-08-30 14:06:32 +00:00
|
|
|
YouTube Download Bot🚀
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2021-05-04 04:01:53 +00:00
|
|
|
Download videos from YouTube and other platforms through a Telegram Bot
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
-----
|
|
|
|
|
2021-05-23 14:25:15 +00:00
|
|
|
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
|
2021-05-04 04:01:53 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
Can't deploy? Fork to your personal account and deploy it there!
|
|
|
|
|
2021-08-29 02:19:49 +00:00
|
|
|
# Usage
|
2021-05-04 04:01:53 +00:00
|
|
|
|
|
|
|
[https://t.me/benny_ytdlbot](https://t.me/benny_ytdlbot)
|
|
|
|
|
2021-08-29 02:19:49 +00:00
|
|
|
Send link directly to the bot. Any
|
2022-01-02 13:49:03 +00:00
|
|
|
Websites [supported by youtube-dl](https://ytdl-org.github.io/youtube-dl/supportedsites.html) will also work.
|
2021-05-04 04:01:53 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
# Limitations of my bot
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
I don't have unlimited servers and bandwidth, so I have to make some restrictions.
|
2022-02-07 11:50:07 +00:00
|
|
|
|
2022-02-01 02:10:34 +00:00
|
|
|
* 10 GiB one-way traffic per 24 hours for each user
|
2022-02-07 11:50:07 +00:00
|
|
|
* maximum 5 minutes streaming conversion support
|
2022-02-04 04:25:10 +00:00
|
|
|
* maximum 3 subscriptions
|
2021-08-29 02:19:49 +00:00
|
|
|
|
|
|
|
You can choose to become 'VIP' if you really need large traffic. And also, you could always deploy your own bot.
|
|
|
|
|
|
|
|
# Features
|
|
|
|
|
|
|
|
![](assets/1.jpeg)
|
2021-05-05 04:07:03 +00:00
|
|
|
|
2021-08-29 02:19:49 +00:00
|
|
|
1. fast download and upload.
|
|
|
|
2. ads free
|
|
|
|
3. support progress bar
|
|
|
|
4. audio conversion
|
|
|
|
5. playlist support
|
|
|
|
6. VIP support
|
2021-12-07 13:32:06 +00:00
|
|
|
7. support different video resolutions
|
|
|
|
8. support sending as file or streaming as video
|
2022-01-02 13:49:03 +00:00
|
|
|
9. supports celery worker distribution - faster than before.
|
2022-02-04 04:25:10 +00:00
|
|
|
10. subscriptions to YouTube Channels
|
2022-04-18 19:28:20 +00:00
|
|
|
11. cache mechanism - download once for the same video.
|
2021-12-07 13:32:06 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
![](assets/2.jpeg)
|
2021-05-05 04:07:03 +00:00
|
|
|
|
2021-05-04 05:36:28 +00:00
|
|
|
# How to deploy?
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2021-12-07 13:32:06 +00:00
|
|
|
You can deploy this bot on any platform that supports Python.
|
2021-08-30 14:42:54 +00:00
|
|
|
|
|
|
|
## Heroku
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
Use the button above! It should work like a magic but with limited functionalities.
|
2021-08-30 14:42:54 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
## Run natively on your machine
|
2021-08-29 02:19:49 +00:00
|
|
|
|
|
|
|
1. clone code
|
|
|
|
2. install ffmpeg
|
2021-05-05 06:10:08 +00:00
|
|
|
3. install Python 3.6+
|
|
|
|
4. pip3 install -r requirements.txt
|
2021-08-29 02:19:49 +00:00
|
|
|
5. set environment variables `TOKEN`, `APP_ID` and `APP_HASH`, and more if you like.
|
2022-01-02 13:49:03 +00:00
|
|
|
6. `python3 ytdl_bot.py`
|
2021-05-05 04:07:03 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
## Docker
|
2021-08-30 14:42:54 +00:00
|
|
|
|
|
|
|
Some functions, such as VIP, ping will be disabled.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
docker run -e APP_ID=111 -e APP_HASH=111 -e TOKEN=370FXI bennythink/ytdlbot
|
|
|
|
```
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
# Complete deployment guide for docker-compose
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
* contains every functionality
|
|
|
|
* compatible with amd64, arm64 and armv7l
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
## 1. get docker-compose.yml
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
Download `docker-compose.yml` file to a directory
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
## 2. create data directory
|
2021-08-29 02:19:49 +00:00
|
|
|
|
|
|
|
```shell
|
2022-01-02 13:49:03 +00:00
|
|
|
mkdir data
|
|
|
|
mkdir env
|
2021-08-29 02:19:49 +00:00
|
|
|
```
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
## 3. configuration
|
|
|
|
|
|
|
|
### 3.1. set environment variables
|
2021-08-29 02:19:49 +00:00
|
|
|
|
|
|
|
```shell
|
2022-01-02 13:49:03 +00:00
|
|
|
vim env/ytdl.env
|
2021-08-29 02:19:49 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
you can configure all the following environment variables:
|
2021-12-07 13:32:06 +00:00
|
|
|
|
2022-02-07 11:50:07 +00:00
|
|
|
* PYRO_WORKERS: number of workers for pyrogram, default is 100
|
2022-03-10 13:46:02 +00:00
|
|
|
* WORKERS: workers count for celery
|
2022-02-07 11:50:07 +00:00
|
|
|
* APP_ID: **REQUIRED**, get it from https://core.telegram.org/
|
2021-08-29 02:19:49 +00:00
|
|
|
* APP_HASH: **REQUIRED**
|
|
|
|
* TOKEN: **REQUIRED**
|
2022-02-08 02:04:54 +00:00
|
|
|
* REDIS: **REQUIRED if you need VIP mode and cache** ⚠️ Don't publish your redis server on the internet. ⚠️
|
2021-10-30 06:27:43 +00:00
|
|
|
|
2021-08-29 02:19:49 +00:00
|
|
|
* OWNER: owner username
|
|
|
|
* QUOTA: quota in bytes
|
|
|
|
* EX: quota expire time
|
|
|
|
* MULTIPLY: vip quota comparing to normal quota
|
|
|
|
* USD2CNY: exchange rate
|
2022-01-02 13:49:03 +00:00
|
|
|
* VIP: VIP mode, default: disable
|
2021-08-29 02:19:49 +00:00
|
|
|
* AFD_LINK
|
|
|
|
* COFFEE_LINK
|
|
|
|
* COFFEE_TOKEN
|
|
|
|
* AFD_TOKEN
|
|
|
|
* AFD_USER_ID
|
2021-10-30 06:27:43 +00:00
|
|
|
|
|
|
|
* AUTHORIZED_USER: users that could use this bot, user_id, separated with `,`
|
2021-12-07 13:32:06 +00:00
|
|
|
* REQUIRED_MEMBERSHIP: group or channel username, user must join this group to use the bot. Could be use with
|
|
|
|
above `AUTHORIZED_USER`
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
* ENABLE_CELERY: Distribution mode, default: disable. You'll can setup workers in different locations.
|
|
|
|
* MYSQL_HOST: you'll have to setup MySQL if you enable VIP mode
|
|
|
|
* MYSQL_USER
|
|
|
|
* MYSQL_PASS
|
2022-02-07 11:50:07 +00:00
|
|
|
* GOOGLE_API_KEY: YouTube API key, required for YouTube video subscription.
|
|
|
|
* AUDIO_FORMAT: audio format, default is m4a. You can set to any known and supported format for ffmpeg. For
|
|
|
|
example,`mp3`, `flac`, etc. ⚠️ m4a is the fastest. Other formats may affect performance.
|
2022-04-18 19:28:20 +00:00
|
|
|
* ARCHIVE_ID: group or channel id/username. All downloads will send to this group first and then forward to end user.
|
|
|
|
**Inline button will be lost during the forwarding.**
|
2022-01-02 13:49:03 +00:00
|
|
|
|
|
|
|
## 3.2 Set up init data
|
|
|
|
|
2022-02-07 11:50:07 +00:00
|
|
|
If you only need basic functionality, you can skip this step.
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
### 3.2.1 Create MySQL db
|
|
|
|
|
2022-02-08 02:04:54 +00:00
|
|
|
Required for VIP, settings, YouTube subscription.
|
2022-02-07 11:50:07 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
```shell
|
|
|
|
docker-compose up -d
|
|
|
|
docker-compose exec mysql bash
|
|
|
|
|
|
|
|
mysql -u root -p
|
|
|
|
|
2022-02-07 11:50:07 +00:00
|
|
|
> create database ytdl;
|
2022-01-02 13:49:03 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### 3.2.2 Setup flower db in `ytdlbot/ytdlbot/data`
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2022-02-07 11:50:07 +00:00
|
|
|
Required if you enable celery and want to monitor the workers.
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
```shell
|
|
|
|
{} ~ python3
|
|
|
|
Python 3.9.9 (main, Nov 21 2021, 03:22:47)
|
|
|
|
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
|
|
|
|
Type "help", "copyright", "credits" or "license" for more information.
|
|
|
|
>>> import dbm;dbm.open("flower","n");exit()
|
2021-08-29 02:19:49 +00:00
|
|
|
```
|
2022-01-02 13:49:03 +00:00
|
|
|
|
|
|
|
### 3.2.3 Setup instagram cookies
|
|
|
|
|
2022-02-07 11:50:07 +00:00
|
|
|
Required if you want to support instagram.
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
You can use this extension
|
|
|
|
[Get cookies.txt](https://chrome.google.com/webstore/detail/get-cookiestxt/bgaddhkoddajcdgocldbbfleckgcbcid)
|
|
|
|
to get instagram cookies
|
|
|
|
|
|
|
|
```shell
|
|
|
|
vim data/instagram.com_cookies.txt
|
|
|
|
# paste your cookies
|
|
|
|
```
|
|
|
|
|
|
|
|
## 3.3 Tidy docker-compose.yml
|
|
|
|
|
|
|
|
In `flower` service section, you may want to change your basic authentication username password and publish port.
|
|
|
|
|
2022-01-03 02:26:03 +00:00
|
|
|
You can also limit CPU and RAM usage by adding an `deploy' key:
|
|
|
|
|
|
|
|
```docker
|
|
|
|
deploy:
|
|
|
|
resources:
|
|
|
|
limits:
|
|
|
|
cpus: '0.5'
|
|
|
|
memory: 1500M
|
|
|
|
```
|
|
|
|
|
|
|
|
Be sure to use `--compatibility` when deploying.
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
## 4. run
|
|
|
|
|
|
|
|
### 4.1. standalone mode
|
|
|
|
|
|
|
|
If you only want to run the mode without any celery worker and VIP mode, you can just start `ytdl` service
|
|
|
|
|
|
|
|
```shell
|
|
|
|
docker-compose up -d ytdl
|
|
|
|
```
|
|
|
|
|
|
|
|
### 4.2 VIP mode
|
|
|
|
|
2022-02-07 11:50:07 +00:00
|
|
|
You'll have to start MySQL and redis to support VIP mode, subscription and settings.
|
2022-01-02 13:49:03 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
docker-compose up -d mysql redis ytdl
|
|
|
|
```
|
|
|
|
|
|
|
|
### 4.3 Celery worker mode
|
|
|
|
|
|
|
|
Firstly, set `ENABLE_CELERY` to true. And then, on one machine:
|
|
|
|
|
|
|
|
```shell
|
2021-08-29 02:19:49 +00:00
|
|
|
docker-compose up -d
|
|
|
|
```
|
2021-05-04 04:01:53 +00:00
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
On the other machine:
|
|
|
|
|
|
|
|
```shell
|
2022-02-07 11:50:07 +00:00
|
|
|
docker-compose -f worker.yml up -d
|
2022-01-02 13:49:03 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
**⚠️ Bear in mind don't publish redis directly on the internet! You can use WireGuard to wrap it up.**
|
|
|
|
|
2021-05-05 06:10:08 +00:00
|
|
|
# Command
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2022-06-26 04:27:08 +00:00
|
|
|
```
|
2021-08-16 11:45:36 +00:00
|
|
|
start - Let's start
|
2022-02-04 04:25:10 +00:00
|
|
|
about - What's this bot?
|
2021-08-16 11:45:36 +00:00
|
|
|
ping - Bot running status
|
2022-02-04 04:25:10 +00:00
|
|
|
help - Help
|
2021-08-16 11:45:36 +00:00
|
|
|
ytdl - Download video in group
|
|
|
|
vip - Join VIP
|
|
|
|
terms - View Terms of Service
|
2021-12-07 13:32:06 +00:00
|
|
|
settings - Set your preference
|
2022-01-20 13:01:58 +00:00
|
|
|
direct - Download file directly
|
2022-02-04 04:25:10 +00:00
|
|
|
sub - Subscribe to YouTube Channel
|
|
|
|
unsub - Unsubscribe from YouTube Channel
|
2022-02-09 05:47:44 +00:00
|
|
|
sub_count - Check subscription status, owner only.
|
2022-03-12 05:32:05 +00:00
|
|
|
uncache - Delete cache for this link
|
2021-05-05 04:07:03 +00:00
|
|
|
```
|
2021-05-05 06:10:08 +00:00
|
|
|
|
2022-01-04 13:33:03 +00:00
|
|
|
# Test data
|
|
|
|
|
|
|
|
## Test video
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2021-05-05 06:10:08 +00:00
|
|
|
https://www.youtube.com/watch?v=BaW_jenozKc
|
|
|
|
|
2022-01-04 13:33:03 +00:00
|
|
|
## Test Playlist
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2021-08-24 11:56:13 +00:00
|
|
|
https://www.youtube.com/playlist?list=PL1Hdq7xjQCJxQnGc05gS4wzHWccvEJy0w
|
|
|
|
|
2022-01-04 13:33:03 +00:00
|
|
|
## Test m3u8
|
|
|
|
|
|
|
|
https://dmesg.app/m3u8/prog_index.m3u8
|
|
|
|
|
2022-04-18 19:28:20 +00:00
|
|
|
## test twitter
|
|
|
|
https://twitter.com/nitori_sayaka/status/1526199729864200192
|
|
|
|
https://twitter.com/BennyThinks/status/1475836588542341124
|
|
|
|
|
2022-01-02 13:49:03 +00:00
|
|
|
# Donation
|
|
|
|
|
|
|
|
* [Buy me a coffee](https://www.buymeacoffee.com/bennythink)
|
|
|
|
* [Afdian](https://afdian.net/@BennyThink)
|
|
|
|
|
2021-05-04 04:01:53 +00:00
|
|
|
# License
|
2021-08-29 02:19:49 +00:00
|
|
|
|
2021-05-04 04:01:53 +00:00
|
|
|
Apache License 2.0
|