Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ CAPTION_URL_LENGTH_LIMIT=150
POTOKEN=11

BROWSERS=firefox

# Proxy URL for downloads (e.g., http://proxy.example.com:8080 or socks5://proxy.example.com:1080)
PROXY=
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ This bot can be deployed on any platform that supports Python.
- `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)
- `PROXY`: Proxy URL for downloads (e.g., http://proxy.example.com:8080 or socks5://proxy.example.com:1080)
- `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)
Expand Down
3 changes: 3 additions & 0 deletions src/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def get_env(name: str, default=None):

RCLONE_PATH = get_env("RCLONE")

# proxy settings
PROXY = get_env("PROXY")

# payment settings
ENABLE_VIP = get_env("ENABLE_VIP")
PROVIDER_TOKEN = get_env("PROVIDER_TOKEN")
Expand Down
5 changes: 4 additions & 1 deletion src/engine/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import yt_dlp

from config import AUDIO_FORMAT
from config import AUDIO_FORMAT, PROXY
from utils import is_youtube
from database.model import get_format_settings, get_quality_settings
from engine.base import BaseDownloader
Expand Down Expand Up @@ -104,6 +104,9 @@ def _download(self, formats) -> list:
"embed_thumbnail": True,
"writethumbnail": False,
}
# add proxy if configured
if PROXY:
ydl_opts["proxy"] = PROXY
# setup cookies for youtube only
if is_youtube(self._url):
# use cookies from browser firstly
Expand Down
6 changes: 5 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
OWNER,
PROVIDER_TOKEN,
TOKEN_PRICE,
PROXY,
BotText,
)
from database.model import (
Expand Down Expand Up @@ -341,7 +342,10 @@ def ytdl_handler(client: Client, message: types.Message):


def check_link(url: str):
ytdl = yt_dlp.YoutubeDL()
opts = {}
if PROXY:
opts["proxy"] = PROXY
ytdl = yt_dlp.YoutubeDL(opts)
if re.findall(r"^https://www\.youtube\.com/channel/", url) or "list" in url:
# TODO maybe using ytdl.extract_info
raise ValueError("Playlist or channel download are not supported at this moment.")
Expand Down
3 changes: 3 additions & 0 deletions src/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
# ytdlbot - test.py

import yt_dlp
from config import PROXY

url = "https://www.youtube.com/watch?v=e19kTVgb2c8"
opts = {
"cookiefile": "cookies.txt",
"cookiesfrombrowser": ["firefox"],
}
if PROXY:
opts["proxy"] = PROXY

with yt_dlp.YoutubeDL(opts) as ydl:
ydl.download([url])