Metadata-Version: 2.4
Name: leader-dl
Version: 2026.10.25
Summary: Simple YouTube search & download library (video / audio) built on yt-dlp, with proxy support
License-Expression: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: yt-dlp>=2026.10.21
Provides-Extra: bot
Requires-Dist: python-telegram-bot>=22; extra == "bot"
Dynamic: license-file

# leader-dl

Simple YouTube **search & download** library for Python, built on [yt-dlp](https://github.com/yt-dlp/yt-dlp),
with first-class **proxy support** so it can run on a VPS.

```bash
pip install leader-dl
```
Needs `ffmpeg` (video merging) and a JavaScript runtime such as `deno` or `node` (yt-dlp uses it for YouTube).

## Usage

```python
import leader

hits = leader.search("song name", limit=5)          # [SearchResult(title, url, ...)]
media = leader.download_audio(hits[0].url)           # Media(path, title, uploader, ...)
video = leader.download_video("https://www.youtube.com/watch?v=VIDEO_ID")
print(media.path, media.title)
```

Quality is **fixed for speed**: video is always 144p (mp4) and audio is the lowest bitrate (~50 kbps m4a).
To change it, edit `VIDEO_HEIGHT` / `AUDIO_FORMAT` at the top of `leader/core.py`.

Playlists: `leader.playlist(url, limit=10)` lists videos; download one with `download_*`.
Async versions: `search_async`, `playlist_async`, `download_audio_async`, `download_video_async`.
Errors raise `leader.DownloadError`.

CLI:
```bash
leader doctor                      # checks ffmpeg, JS runtime, proxy, YouTube access
leader search "song name"
leader audio  "https://www.youtube.com/watch?v=VIDEO_ID"
leader video  "https://www.youtube.com/watch?v=VIDEO_ID"
leader audio  "https://www.youtube.com/watch?v=VIDEO_ID"
```

## Running on a VPS (YouTube blocks many server IPs)
YouTube often answers "Sign in to confirm you're not a bot" for datacenter IPs. Account login does not change that.
What worked in our test is sending requests through Cloudflare WARP in proxy mode:

```bash
sudo bash scripts/setup_warp.sh                     # installs WARP, SOCKS5 on 127.0.0.1:40000
export LEADER_PROXY=socks5://127.0.0.1:40000
leader doctor
```
Or in code: `leader.configure(proxy="socks5://127.0.0.1:40000")`.
This is **not guaranteed** to work for every server or every time. Any HTTP/SOCKS proxy works the same way.

## Telegram bot
`examples/telegram_bot.py` (`pip install "leader-dl[bot]"`): link, playlist link or song name.
Read the token from the `BOT_TOKEN` environment variable; never commit it.

## نبذة بالعربي
مكتبة للبحث والتحميل من يوتيوب مبنية على yt-dlp. على السيرفرات اللي يوتيوب بيحجبها استخدم بروكسي
(`LEADER_PROXY`)، وسكربت `scripts/setup_warp.sh` بيركّب Cloudflare WARP كبروكسي محلي. مش مضمون يشتغل في كل الحالات.

## Notes
Downloading may violate YouTube's Terms of Service. Use it only for content you are allowed to download.

## License
MIT
