From 0ac49e12b430d976d8f15d6736f97290e3e403a7 Mon Sep 17 00:00:00 2001 From: Benny Date: Sun, 26 Jan 2025 18:57:43 +0100 Subject: [PATCH] add comments --- .env.example | 14 +++++++------- README.md | 17 ++++++++--------- pre-push.py | 4 ++-- src/engine/generic.py | 12 +++++++++--- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/.env.example b/.env.example index dbe01f2..4be0e68 100644 --- a/.env.example +++ b/.env.example @@ -12,22 +12,22 @@ APP_HASH= # Telegram bot token BOT_TOKEN= -# Owner ID, separate by , +# Owner ID, comma-separated OWNER= -# List of authorized users (comma-separated) +# List of authorized users, comma-separated AUTHORIZED_USER= -# database Data Source Name +# database Data Source Name, i.e. mysql+pymysql://user:pass@mysql/dbname SQLite sqlite:///db.sqlite DB_DSN= -# Redis host -REDIS_HOST= +# Redis host, leave it empty to use fakeredis +REDIS_HOST=redis # Enable FFMPEG for video processing (True/False) ENABLE_FFMPEG=False -# Desired audio format (e.g., mp3, wav) +# Desired audio format (e.g., mp3, wav), leave it empty to use m4a AUDIO_FORMAT= # Enable Aria2 for downloads (True/False) @@ -39,7 +39,7 @@ RCLONE_PATH= # Enable VIP features (True/False) ENABLE_VIP=False -# Payment provider token +# Payment provider token from Bot Father PROVIDER_TOKEN= # Free downloads allowed per user diff --git a/README.md b/README.md index e069fed..6286009 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![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🚀🎬⬇️** -🧰Refactor ongoing🧰 This Telegram bot allows you to download videos from YouTube and [other supported websites](#supported-websites). @@ -38,7 +37,7 @@ Just send a link directly to the bot. > ## Limitations > Due to limitations on servers and bandwidth, there are some restrictions on this free service. -> * Each user is limited to 3 free downloads every day. +> * Each user is limited to 1 free downloads every day. # Screenshots @@ -66,7 +65,7 @@ This bot can be deployed on any platform that supports Python. or for more ways: [Official Docs](https://pdm-project.org/en/latest/#installation) -2. Install modules using PDM: `pdm install`, or the old way use `requirements.txt` +2. Install modules using PDM: `pdm install`, or the old way use `pip install -r requirements.txt` 3.
Setting up config file @@ -75,7 +74,7 @@ This bot can be deployed on any platform that supports Python. cp .env.example .env ``` - Fill the fields in `.env`. + Fill the fields in `.env`. For more information, see the comments in the `.env.example` file. **- Required Fields** - `WORKERS`: Number of workers (default is 100) @@ -83,8 +82,8 @@ This bot can be deployed on any platform that supports Python. - `APP_HASH`: Telegram app hash - `BOT_TOKEN`: Your telegram bot token - `OWNER`: Owner ID (separate by `,`) - - `AUTHORIZED_USER`: List of authorized users (separate by `,`) - - `DB_DSN`: Your database URL (mysql+pymysql://user:pass@some_mariadb/dbname) + - `AUTHORIZED_USER`: List of authorized users ids, (separate by `,`) + - `DB_DSN`: Your database URL (mysql+pymysql://user:pass@mysql/dbname) or SQLite (sqlite:///db.sqlite) - `REDIS_HOST`: Redis host **- Optional Fields** @@ -93,14 +92,14 @@ This bot can be deployed on any platform that supports Python. - `ENABLE_ARIA2`: Enable Aria2 for downloads (True/False) - `RCLONE_PATH`: Path to Rclone executable - `ENABLE_VIP`: Enable VIP features (True/False) - - `PROVIDER_TOKEN`: Payment provider token + - `PROVIDER_TOKEN`: Payment provider token from Stripe - `FREE_DOWNLOAD`: Free downloads allowed per user - `RATE_LIMIT`: Rate limit for requests - `TMPFILE_PATH`: Path for temporary/download files (ensure the directory exists and is writable) - `TG_NORMAL_MAX_SIZE`: Maximum size for Telegram uploads in MB - `CAPTION_URL_LENGTH_LIMIT`: Maximum URL length in captions - `POTOKEN`: Your PO Token. [PO-Token-Guide](https://github.com/yt-dlp/yt-dlp/wiki/PO-Token-Guide) - - `BROWSERS`: Browser to handle 'cookies from browser' + - `BROWSERS`: Browser to handle 'cookies from browser', i.e. firefox
4. Activate virtual environment that created by PDM: `source .venv/bin/activate` @@ -112,7 +111,7 @@ This bot can be deployed on any platform that supports Python. One line command to run the bot ```shell -docker run -e APP_ID=111 -e APP_HASH=111 -e TOKEN=370FXI bennythink/ytdlbot +docker run --env-file .env bennythink/ytdlbot ``` # Command diff --git a/pre-push.py b/pre-push.py index 809fd2b..38d5488 100755 --- a/pre-push.py +++ b/pre-push.py @@ -18,5 +18,5 @@ with open("requirements.txt", "w") as file: file.write(f"{item}\n") # commit with amend -subprocess.run(["git", "add", "requirements.txt"]) -subprocess.run(["git", "commit", "-m", "pre-push"]) +# subprocess.run(["git", "add", "requirements.txt"]) +# subprocess.run(["git", "commit", "-m", "pre-push"]) diff --git a/src/engine/generic.py b/src/engine/generic.py index a12a90d..2659130 100644 --- a/src/engine/generic.py +++ b/src/engine/generic.py @@ -11,6 +11,7 @@ import yt_dlp from database.model import get_format_settings, get_quality_settings from engine.base import BaseDownloader +from config import AUDIO_FORMAT def match_filter(info_dict): @@ -38,14 +39,15 @@ class YoutubeDownload(BaseDownloader): "bestvideo[vcodec^=avc]+bestaudio[acodec^=mp4a]/best[vcodec^=avc]/best", None, ] + audio = AUDIO_FORMAT or "m4a" maps = { - "high-audio": ["bestaudio[ext=m4a]"], + "high-audio": [f"bestaudio[ext=={audio}]"], "high-video": defaults, "high-document": defaults, - "medium-audio": ["bestaudio[ext=m4a]"], # no mediumaudio :-( + "medium-audio": [f"bestaudio[ext={audio}]"], # no mediumaudio :-( "medium-video": self.get_format(720), "medium-document": self.get_format(720), - "low-audio": ["bestaudio[ext=m4a]"], + "low-audio": [f"bestaudio[ext={audio}]"], "low-video": self.get_format(480), "low-document": self.get_format(480), "custom-audio": "", @@ -100,6 +102,10 @@ class YoutubeDownload(BaseDownloader): # try add extract_args if present if potoken := os.getenv("POTOKEN"): ydl_opts["extractor_args"] = {"youtube": ["player-client=web,default", f"po_token=web+{potoken}"]} + # for new version? https://github.com/yt-dlp/yt-dlp/wiki/PO-Token-Guide + # ydl_opts["extractor_args"] = { + # "youtube": [f"po_token=web.player+{potoken}", f"po_token=web.gvs+{potoken}"] + # } if self._url.startswith("https://drive.google.com"): # Always use the `source` format for Google Drive URLs.