ytdlbot/README.md

330 lines
8.5 KiB
Markdown
Raw Normal View History

2021-08-29 10:19:49 +08:00
# ytdlbot
2022-01-02 21:49:03 +08: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)
YouTube Download Bot🚀🎬⬇
2021-08-29 10:19:49 +08:00
This Telegram bot allows you to download videos from YouTube and other supported websites, including Instagram!
2021-05-04 12:01:53 +08:00
2023-04-16 20:27:24 +08:00
<details> <summary>Deploy to heroku</summary>
<a href="https://heroku.com/deploy"><img src="https://www.herokucdn.com/deploy/button.svg" alt="Deploy to Heroku"></a>
2021-05-04 12:01:53 +08:00
2023-04-07 04:33:24 +08:00
If you are having trouble deploying, you can fork the project to your personal account and deploy it from there.
2022-09-05 18:22:21 +08:00
**Starting November 28, 2022, free Heroku Dynos, free Heroku Postgres, and free Heroku Data for Redis® plans will no
longer be available.**
2022-08-26 23:11:39 +08:00
[Heroku Announcement](https://devcenter.heroku.com/articles/free-dyno-hours)
2023-04-16 20:27:24 +08:00
</details>
2022-01-02 21:49:03 +08:00
2021-08-29 10:19:49 +08:00
# Usage
2021-05-04 12:01:53 +08:00
[https://t.me/benny_ytdlbot](https://t.me/benny_ytdlbot)
2021-08-29 10:19:49 +08:00
Send link directly to the bot. Any
Websites [supported by yt-dlp](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md) will work t0o.
2021-05-04 12:01:53 +08:00
2022-01-02 21:49:03 +08:00
# Limitations of my bot
2021-08-29 10:19:49 +08:00
2023-04-16 20:27:24 +08:00
Due to limitations on servers and bandwidth, there are some restrictions on this free service.
2022-02-07 19:50:07 +08:00
2023-06-23 17:08:34 +08:00
* Each user is limited to 20 free downloads per 24-hour period
* Maximum of three subscriptions allowed for YouTube channels.
2021-08-29 10:19:49 +08:00
2023-04-16 20:27:24 +08:00
If you need more downloads, you can purchase additional tokens. Additionally, you have the option of deploying your
own bot. See below instructions.
2021-08-29 10:19:49 +08:00
# Features
1. fast download and upload.
2. ads free
3. support progress bar
4. audio conversion
5. playlist download
6. payment support: afdian, buy me a coffee, Telegram Payment and Tron(TRX)
7. different video resolutions
8. sending as file or streaming as video
9. celery worker distribution - faster than before.
2022-02-04 12:25:10 +08:00
10. subscriptions to YouTube Channels
2022-04-19 03:28:20 +08:00
11. cache mechanism - download once for the same video.
12. instagram posts
2023-04-16 20:27:24 +08:00
# Screenshots
## Normal download
![](assets/1.jpeg)
## Instagram download
![](assets/instagram.png)
## celery
2022-01-02 21:49:03 +08:00
![](assets/2.jpeg)
2021-05-04 13:36:28 +08:00
# How to deploy?
2021-08-29 10:19:49 +08:00
2023-04-07 04:33:24 +08:00
This bot can be deployed on any platform that supports Python.
2021-08-30 22:42:54 +08:00
2022-01-02 21:49:03 +08:00
## Run natively on your machine
2021-08-29 10:19:49 +08:00
2023-04-07 04:33:24 +08:00
To deploy this bot, follow these steps:
1. Install bot dependencies
2023-12-10 00:10:39 +08:00
* Install Python 3.8 or a later version, FFmpeg.
* (optional)Aria2 and add it to the PATH.
2. Clone the code from the repository and cd into it.
* ```Bash
git clone https://github.com/tgbot-collection/ytdlbot
```
* ```Bash
cd ytdlbot/
```
3. Creating a virtual environment and installing required modules in Python.
* ```Python
python -m venv venv
```
* ```Bash
source venv/bin/activate # Linux
#or
.\venv\Scripts\activate # Windows
```
* ```Python
pip install --upgrade pip
```
* ```Python
pip install -r requirements.txt
```
4. Set the environment variables `TOKEN`, `APP_ID`, `APP_HASH`, and any others that you may need.
* Change values in ytdlbot/config.py or
* Use export APP_ID=111 APP_HASH=111 TOKEN=123
5. Finally, run the bot with
* ```Python
python ytdl_bot.py
```
2022-01-02 21:49:03 +08:00
## Docker
2021-08-30 22:42:54 +08:00
One line command to run the bot
2021-08-30 22:42:54 +08:00
```shell
docker run -e APP_ID=111 -e APP_HASH=111 -e TOKEN=370FXI bennythink/ytdlbot
```
2022-01-02 21:49:03 +08:00
# Complete deployment guide for docker-compose
2021-08-29 10:19:49 +08:00
2022-01-02 21:49:03 +08:00
* contains every functionality
* compatible with amd64 and arm64
2021-08-29 10:19:49 +08:00
2022-01-02 21:49:03 +08:00
## 1. get docker-compose.yml
2021-08-29 10:19:49 +08:00
2022-01-02 21:49:03 +08:00
Download `docker-compose.yml` file to a directory
2021-08-29 10:19:49 +08:00
2022-01-02 21:49:03 +08:00
## 2. create data directory
2021-08-29 10:19:49 +08:00
```shell
2022-01-02 21:49:03 +08:00
mkdir data
mkdir env
2021-08-29 10:19:49 +08:00
```
2022-01-02 21:49:03 +08:00
## 3. configuration
### 3.1. set environment variables
2021-08-29 10:19:49 +08:00
```shell
2022-01-02 21:49:03 +08:00
vim env/ytdl.env
2021-08-29 10:19:49 +08:00
```
2023-04-07 04:33:24 +08:00
You can configure all the following environment variables:
2022-03-10 21:46:02 +08:00
* WORKERS: workers count for celery
2023-04-07 04:33:24 +08:00
* PYRO_WORKERS: number of workers for pyrogram, default is 100
2022-02-07 19:50:07 +08:00
* APP_ID: **REQUIRED**, get it from https://core.telegram.org/
2021-08-29 10:19:49 +08:00
* APP_HASH: **REQUIRED**
* TOKEN: **REQUIRED**
2022-02-08 10:04:54 +08:00
* REDIS: **REQUIRED if you need VIP mode and cache** ⚠️ Don't publish your redis server on the internet. ⚠️
2023-04-07 04:33:24 +08:00
* EXPIRE: token expire time, default: 1 day
* ENABLE_VIP: enable VIP mode
2021-08-29 10:19:49 +08:00
* OWNER: owner username
2023-04-07 04:33:24 +08:00
* AUTHORIZED_USER: only authorized users can use the bot
* REQUIRED_MEMBERSHIP: group or channel username, user must join this group to use the bot
* ENABLE_CELERY: celery mode, default: disable
* ENABLE_QUEUE: celery queue
* BROKER: celery broker, should be redis://redis:6379/0
* MYSQL_HOST:MySQL host
* MYSQL_USER: MySQL username
* MYSQL_PASS: MySQL password
* AUDIO_FORMAT: default audio format
* ARCHIVE_ID: forward all downloads to this group/channel
* IPv6 = os.getenv("IPv6", False)
* ENABLE_FFMPEG = os.getenv("ENABLE_FFMPEG", False)
* PROVIDER_TOKEN: stripe token on Telegram payment
* PLAYLIST_SUPPORT: download playlist support
2023-09-18 04:04:29 +08:00
* M3U8_SUPPORT: download m3u8 files support
2023-04-07 04:33:24 +08:00
* ENABLE_ARIA2: enable aria2c download
* FREE_DOWNLOAD: free download count per day
* TOKEN_PRICE: token price per 1 USD
2022-02-07 19:50:07 +08:00
* GOOGLE_API_KEY: YouTube API key, required for YouTube video subscription.
2023-08-26 19:04:29 +08:00
* RCLONE_PATH: rclone path to upload files to cloud storage
* TMPFILE_PATH: tmpfile path(file download path)
* TRONGRID_KEY: TronGrid key, better use your own key to avoid rate limit
* TRON_MNEMONIC: Tron mnemonic, the default one is on nile testnet.
2022-01-02 21:49:03 +08:00
## 3.2 Set up init data
2022-02-07 19:50:07 +08:00
If you only need basic functionality, you can skip this step.
2022-01-02 21:49:03 +08:00
### 3.2.1 Create MySQL db
Required for VIP(Download token), settings, YouTube subscription.
2022-02-07 19:50:07 +08:00
2022-01-02 21:49:03 +08:00
```shell
docker-compose up -d
docker-compose exec mysql bash
mysql -u root -p
2022-02-07 19:50:07 +08:00
> create database ytdl;
2022-01-02 21:49:03 +08:00
```
### 3.2.2 Setup flower db in `ytdlbot/ytdlbot/data`
2021-08-29 10:19:49 +08:00
2022-02-07 19:50:07 +08:00
Required if you enable celery and want to monitor the workers.
2022-01-02 21:49:03 +08: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 10:19:49 +08:00
```
2022-01-02 21:49:03 +08:00
## 3.3 Tidy docker-compose.yml
In `flower` service section, you may want to change your basic authentication username password and publish port.
You can also limit CPU and RAM usage by adding a `deploy` key, use `--compatibility` when deploying.
2022-01-03 10:26:03 +08:00
```docker
deploy:
resources:
limits:
cpus: '0.5'
memory: 1500M
```
2022-01-02 21:49:03 +08: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 19:50:07 +08:00
You'll have to start MySQL and redis to support VIP mode, subscription and settings.
2022-01-02 21:49:03 +08: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 10:19:49 +08:00
docker-compose up -d
```
2021-05-04 12:01:53 +08:00
2022-01-02 21:49:03 +08:00
On the other machine:
```shell
2022-02-07 19:50:07 +08:00
docker-compose -f worker.yml up -d
2022-01-02 21:49:03 +08:00
```
**⚠️ You should not publish Redis directly on the internet.
2023-04-07 04:33:24 +08:00
Instead, you can use WireGuard to wrap it up for added security.**
2023-01-07 00:06:26 +08:00
2023-04-07 04:33:24 +08:00
## kubernetes
2023-01-07 00:06:26 +08:00
2023-04-07 04:33:24 +08:00
refer guide here [kubernetes](k8s.md)
2022-11-25 15:09:56 +08:00
2021-05-05 14:10:08 +08:00
# Command
2021-08-29 10:19:49 +08:00
```
2021-08-16 19:45:36 +08:00
start - Let's start
2022-02-04 12:25:10 +08:00
about - What's this bot?
2021-08-16 19:45:36 +08:00
ping - Bot running status
2022-02-04 12:25:10 +08:00
help - Help
2021-08-16 19:45:36 +08:00
ytdl - Download video in group
settings - Set your preference
2023-04-08 18:06:15 +08:00
buy - Buy token
2022-01-20 21:01:58 +08:00
direct - Download file directly
2022-02-04 12:25:10 +08:00
sub - Subscribe to YouTube Channel
unsub - Unsubscribe from YouTube Channel
2022-02-09 13:47:44 +08:00
sub_count - Check subscription status, owner only.
2023-01-07 19:11:26 +08:00
uncache - Delete cache for this link, owner only.
2023-04-08 18:06:15 +08:00
purge - Delete all tasks, owner only.
```
2021-05-05 14:10:08 +08:00
2022-01-04 21:33:03 +08:00
# Test data
## Test video
2021-08-29 10:19:49 +08:00
2021-05-05 14:10:08 +08:00
https://www.youtube.com/watch?v=BaW_jenozKc
2022-01-04 21:33:03 +08:00
## Test Playlist
2021-08-29 10:19:49 +08:00
https://www.youtube.com/playlist?list=PL1Hdq7xjQCJxQnGc05gS4wzHWccvEJy0w
2023-04-19 01:09:44 +08:00
## Test twitter
2022-09-05 18:22:21 +08:00
2022-04-19 03:28:20 +08:00
https://twitter.com/nitori_sayaka/status/1526199729864200192
https://twitter.com/BennyThinks/status/1475836588542341124
2023-04-19 01:09:44 +08:00
## Test instagram
https://www.instagram.com/p/ClBSqo3PkJw/
2023-05-21 02:24:16 +08:00
2023-04-19 01:09:44 +08:00
https://www.instagram.com/p/CaiAHoWDnrM/
2023-05-21 02:24:16 +08:00
2023-04-19 01:09:44 +08:00
https://www.instagram.com/p/CZtUDyyv1u1/
2023-04-16 20:27:24 +08:00
2022-01-02 21:49:03 +08:00
# Donation
Found this bot useful? You can donate to support the development of this bot.
## Donation Platforms
2022-01-02 21:49:03 +08:00
* [Buy me a coffee](https://www.buymeacoffee.com/bennythink)
* [Afdian](https://afdian.net/@BennyThink)
2023-01-07 00:06:26 +08:00
* [GitHub Sponsor](https://github.com/sponsors/BennyThink)
## Stripe
You can choose to donate via Stripe.
| USD(Card, Apple Pay and Google Pay) | CNY(Card, Apple Pay, Google Pay and Alipay) |
|--------------------------------------------------|--------------------------------------------------|
| [USD](https://buy.stripe.com/cN203sdZB98RevC3cd) | [CNY](https://buy.stripe.com/dR67vU4p13Ox73a6oq) |
| ![](assets/USD.png) | ![](assets/CNY.png) |
## Cryptocurrency
2023-04-07 04:33:24 +08:00
TRX or USDT(TRC20)
2023-01-07 00:06:26 +08:00
![](assets/tron.png)
```
TF9peZjC2FYjU4xNMPg3uP4caYLJxtXeJS
```
2022-01-02 21:49:03 +08:00
2021-05-04 12:01:53 +08:00
# License
2021-08-29 10:19:49 +08:00
2022-12-06 09:53:03 +08:00
Apache License 2.0