mirror of
https://github.com/omg-xtao/ytdlbot.git
synced 2024-11-16 03:45:23 +00:00
update docs, add support for mp3, flac
This commit is contained in:
parent
2efaa318cc
commit
97639e999c
27
README.md
27
README.md
@ -22,8 +22,9 @@ Websites [supported by youtube-dl](https://ytdl-org.github.io/youtube-dl/support
|
||||
# Limitations of my bot
|
||||
|
||||
I don't have unlimited servers and bandwidth, so I have to make some restrictions.
|
||||
|
||||
* 10 GiB one-way traffic per 24 hours for each user
|
||||
* maximum 5 minutes streaming conversion support
|
||||
* maximum 5 minutes streaming conversion support
|
||||
* maximum 3 subscriptions
|
||||
|
||||
You can choose to become 'VIP' if you really need large traffic. And also, you could always deploy your own bot.
|
||||
@ -96,11 +97,12 @@ vim env/ytdl.env
|
||||
|
||||
you can configure all the following environment variables:
|
||||
|
||||
* WORKERS: default 200
|
||||
* APP_ID: **REQUIRED**
|
||||
* PYRO_WORKERS: number of workers for pyrogram, default is 100
|
||||
* WORKERS: workers count for celery,it'll be doubled.
|
||||
* APP_ID: **REQUIRED**, get it from https://core.telegram.org/
|
||||
* APP_HASH: **REQUIRED**
|
||||
* TOKEN: **REQUIRED**
|
||||
* REDIS: **REQUIRED** ⚠️ Don't publish your redis server on the internet. ⚠️
|
||||
* REDIS: **REQUIRED if you need VIP mode** ⚠️ Don't publish your redis server on the internet. ⚠️
|
||||
|
||||
* OWNER: owner username
|
||||
* QUOTA: quota in bytes
|
||||
@ -122,22 +124,31 @@ you can configure all the following environment variables:
|
||||
* MYSQL_HOST: you'll have to setup MySQL if you enable VIP mode
|
||||
* MYSQL_USER
|
||||
* MYSQL_PASS
|
||||
* 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.
|
||||
|
||||
## 3.2 Set up init data
|
||||
|
||||
If you only need basic functionality, you can skip this step.
|
||||
|
||||
### 3.2.1 Create MySQL db
|
||||
|
||||
Required for VIP, settings, YouTube subscription and notification.
|
||||
|
||||
```shell
|
||||
docker-compose up -d
|
||||
docker-compose exec mysql bash
|
||||
|
||||
mysql -u root -p
|
||||
|
||||
> create database vip;
|
||||
> create database ytdl;
|
||||
```
|
||||
|
||||
### 3.2.2 Setup flower db in `ytdlbot/ytdlbot/data`
|
||||
|
||||
Required if you enable celery and want to monitor the workers.
|
||||
|
||||
```shell
|
||||
{} ~ python3
|
||||
Python 3.9.9 (main, Nov 21 2021, 03:22:47)
|
||||
@ -148,6 +159,8 @@ Type "help", "copyright", "credits" or "license" for more information.
|
||||
|
||||
### 3.2.3 Setup instagram cookies
|
||||
|
||||
Required if you want to support instagram.
|
||||
|
||||
You can use this extension
|
||||
[Get cookies.txt](https://chrome.google.com/webstore/detail/get-cookiestxt/bgaddhkoddajcdgocldbbfleckgcbcid)
|
||||
to get instagram cookies
|
||||
@ -185,7 +198,7 @@ docker-compose up -d ytdl
|
||||
|
||||
### 4.2 VIP mode
|
||||
|
||||
You'll have to start MySQL and redis to support VIP mode.
|
||||
You'll have to start MySQL and redis to support VIP mode, subscription and settings.
|
||||
|
||||
```
|
||||
docker-compose up -d mysql redis ytdl
|
||||
@ -202,7 +215,7 @@ docker-compose up -d
|
||||
On the other machine:
|
||||
|
||||
```shell
|
||||
docker-compose -f worker up -d
|
||||
docker-compose -f worker.yml up -d
|
||||
```
|
||||
|
||||
**⚠️ Bear in mind don't publish redis directly on the internet! You can use WireGuard to wrap it up.**
|
||||
|
@ -13,8 +13,6 @@ services:
|
||||
restart: always
|
||||
logging:
|
||||
driver: none
|
||||
ports:
|
||||
- "192.168.6.1:6379:6379"
|
||||
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
@ -25,8 +23,6 @@ services:
|
||||
MYSQL_ROOT_PASSWORD: 'root'
|
||||
logging:
|
||||
driver: none
|
||||
ports:
|
||||
- "192.168.6.1:3306:3306"
|
||||
|
||||
ytdl:
|
||||
image: bennythink/ytdlbot
|
||||
|
@ -9,10 +9,10 @@ __author__ = "Benny <benny.think@gmail.com>"
|
||||
|
||||
from pyrogram import Client
|
||||
|
||||
from config import APP_HASH, APP_ID, TOKEN
|
||||
from config import APP_HASH, APP_ID, PYRO_WORKERS, TOKEN
|
||||
|
||||
|
||||
def create_app(session="ytdl", workers=100):
|
||||
def create_app(session="ytdl", workers=PYRO_WORKERS):
|
||||
_app = Client(session, APP_ID, APP_HASH,
|
||||
bot_token=TOKEN, workers=workers,
|
||||
# proxy={"hostname": "host.docker.internal", "port": 1080}
|
||||
|
@ -10,7 +10,8 @@ __author__ = "Benny <benny.think@gmail.com>"
|
||||
import os
|
||||
|
||||
# general settings
|
||||
WORKERS: "int" = int(os.getenv("WORKERS", 200))
|
||||
WORKERS: "int" = int(os.getenv("WORKERS", 100))
|
||||
PYRO_WORKERS: "int" = int(os.getenv("PYRO_WORKERS", 100))
|
||||
APP_ID: "int" = int(os.getenv("APP_ID", 111))
|
||||
APP_HASH = os.getenv("APP_HASH", "111")
|
||||
TOKEN = os.getenv("TOKEN", "3703WLI")
|
||||
@ -49,3 +50,5 @@ BROKER = os.getenv("BROKER", f"redis://{REDIS}:6379/4")
|
||||
MYSQL_HOST = os.getenv("MYSQL_HOST")
|
||||
MYSQL_USER = os.getenv("MYSQL_USER", "root")
|
||||
MYSQL_PASS = os.getenv("MYSQL_PASS", "root")
|
||||
|
||||
AUDIO_FORMAT = os.getenv("AUDIO_FORMAT", "m4a")
|
@ -26,7 +26,7 @@ from pyrogram import idle
|
||||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
from client_init import create_app
|
||||
from config import BROKER, ENABLE_CELERY, ENABLE_VIP, WORKERS
|
||||
from config import AUDIO_FORMAT, BROKER, ENABLE_CELERY, ENABLE_VIP, WORKERS
|
||||
from constant import BotText
|
||||
from db import Redis
|
||||
from downloader import (edit_text, sizeof_fmt, tqdm_progress, upload_hook,
|
||||
@ -206,13 +206,17 @@ def normal_audio(bot_msg, client):
|
||||
logging.info("downloading to %s", tmp)
|
||||
base_path = pathlib.Path(tmp)
|
||||
video_path = base_path.joinpath(fn)
|
||||
audio = base_path.joinpath(fn).with_suffix(".m4a")
|
||||
audio = base_path.joinpath(fn).with_suffix(f".{AUDIO_FORMAT}")
|
||||
client.send_chat_action(chat_id, 'record_video_note')
|
||||
client.download_media(bot_msg, video_path)
|
||||
logging.info("downloading complete %s", video_path)
|
||||
# execute ffmpeg
|
||||
client.send_chat_action(chat_id, 'record_audio')
|
||||
subprocess.check_output(f"ffmpeg -y -i '{video_path}' -vn -acodec copy '{audio}'", shell=True)
|
||||
try:
|
||||
subprocess.check_output(f"ffmpeg -y -i '{video_path}' -vn -acodec copy '{audio}'", shell=True)
|
||||
except subprocess.CalledProcessError:
|
||||
subprocess.check_output(f"ffmpeg -y -i '{video_path}' '{audio}'", shell=True)
|
||||
|
||||
client.send_chat_action(chat_id, 'upload_audio')
|
||||
client.send_audio(chat_id, audio)
|
||||
Redis().update_metrics("audio_success")
|
||||
|
Loading…
Reference in New Issue
Block a user