Yt2Cli
A simple command-line (CLI) tool for searching and playing YouTube videos directly from the terminal, without needing to open a browser.
Features
- Search YouTube videos by keyword, with an optional result limit (
--limit=<n>, default 10, max 100) - Filter results by video type with
--type=short|long|both(short = 60s or less, long = more than 60s) - Results are cached per query, limit, and type, so re-searching the same keyword is instant
- Load more results from the last search with
more - Display search results as formatted video cards (title, channel, views with
K/M/Bsuffix, duration, and Short/Normal badge) with the video thumbnail rendered as block/pixel art; cards flow into a responsive multi-column grid based on terminal width - Play any video from the list through mpv, falling back to the system's default application if mpv isn't installed
- Play a video directly by URL without searching:
open --url=<youtube-url> - Type a YouTube URL directly at the prompt to play it automatically, no command needed
- Download one or more videos to a folder you pick (native folder dialog per OS), including direct URLs:
download --url=<youtube-url> - Copy a video's URL to the clipboard with
copy <id>(usespyperclip) - Clear the in-memory cache and the loaded list with
resetorcache:clear - Any unrecognized command is treated as a search query
- Command line editing and history via
readline - Cross-platform: works on Windows, macOS, and Linux
Requirements
1. Python
Recommended version: Python 3.10 or newer.
2. mpv for video playback (optional)
The app relies on mpv as the default player. If it's not installed, the app will fall back to opening the link with the system's default application.
Installing mpv:
| OS | Command |
|---|---|
| Fedora | sudo dnf install mpv |
| Ubuntu / Debian | sudo apt install mpv |
| macOS (Homebrew) | brew install mpv |
| Windows | Download from mpv.io |
Installation
pip install yt2cli
Usage
yt2cli
This launches an interactive prompt. Type a command and press Enter.
Available Commands
| Command | Description |
|---|---|
list |
Show the currently loaded videos from the last search |
open <id> |
Play a video from the list by its number; use open --url=<youtube-url> to play a direct URL |
download <id> |
Download one or more videos from the list (download <id1> <id2> ...); use download --url=<youtube-url> for a direct URL |
copy <id> |
Copy the URL of a video from the list to the clipboard |
more |
Load more videos from the last search (adds 5 more results) |
reset |
Clear the loaded video list and the backend cache |
cache:clear |
Remove the cached search results only |
clear |
Clear the terminal screen |
help |
Show a list of available commands |
exit |
Close the app |
Note: Any input that isn't a recognized command is treated as a search query. A direct YouTube URL (containing
youtube.com/watch) is played automatically instead of being searched.
Example
==================================================
AVAILABLE OPTIONS
==================================================
[copy] Use it to Copy the Youtube Video Url, Id Required
[open] Use It to Open A video From the List of Searched Videos
[clear] Clear The Terminal Screen
[list] Show The Current Loaded Videos
[exit] Close the App
[help] Show A List of Available Commands
[reset] Remove The Saved Search And Backend Cache
[cache:clear] Remove the Cached Search Results
[more] Get More Videos from the Last Searched Query
[download] Download A Youtube Video
==================================================
Yt2Cli Run: python tutorial --type=both
********** Search Results For: python tutorial , limit = 10 type = both **********
──────────────────────────────────────────────────────────────
┌─────────────── block art ───────────────┐ [0] Python Basics for Beginners
│ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ Programming Academy
│ ░░░░░░ ░░ ░ ░ ░░ ░ ░░░ ░░░ ░░ ░░░ │ 2.34M views
│ ░ ░░░░ ░ ░░ ░ ░ ░░ ░ ░░ ░ ░░░ ░ ░░░░░ │ 18:42 duration
│ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ Normal video
└─────────────────────────────────────────┘
──────────────────────────────────────────────────────────────
# The number in [brackets] is the video's index in the list (used by `open`/`download`/`copy`), not the YouTube video ID
Yt2Cli Run: open 0
Video Card Layout
Each search result is printed as a card:
──────────────────────────────────────────────────────────────
┌─────────────── block art ───────────────┐ [0] Python Basics for Beginners
│ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ Programming Academy
│ ░░░░░░ ░░ ░ ░ ░░ ░ ░░░ ░░░ ░░ ░░░ │ 2.34M views
│ ░ ░░░░ ░ ░░ ░ ░ ░░ ░ ░░ ░ ░░░ ░ ░░░░░ │ 18:42 duration
│ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ Normal video
└─────────────────────────────────────────┘
──────────────────────────────────────────────────────────────
- The card is bounded by a horizontal line (
─) - Left side: the video thumbnail rendered as terminal block/pixel art (~40 columns wide) via
term-image - Right side: the bold
[index] Title(truncated to 45 chars), the channel (truncated to 40 chars), the view count formatted withK/M/Bsuffixes, the video duration, and aShort/Normalvideo badge - Cards are laid out in a responsive grid — as many cards per row as the terminal width allows, and each card is padded so columns align
- The
[index]is the card's position in the loaded list — the number you pass toopen <id>,download <id>, orcopy <id>
You can also play a video directly by URL, without searching first:
Yt2Cli Run: open --url=https://www.youtube.com/watch?v=id
Or simply type the URL itself — it will be detected and played automatically:
Yt2Cli Run: https://www.youtube.com/watch?v=id
Project Structure
yt2cli/
├── src/
│ └── yt2cli/
│ ├── __init__.py # App export entry point
│ ├── App.py # Core logic and command handling
│ ├── Backend.py # Search logic (yt-dlp), result caching, and downloads
│ ├── ParamManager.py # Parses `--option=value` arguments for commands
│ ├── Player.py # Video playback (mpv with system fallback)
│ ├── SearchResults.py # Renders the video cards and thumbnail block art
│ └── cli.py # Interactive REPL entry point
Notes
- The app uses yt-dlp to search and extract video playback URLs.
- Search results are cached per query, limit, and type in memory; playing a video re-resolves the stream URL with yt-dlp.
--type=short|long|bothfilters results by duration:shortvideos are 60 seconds or less,longvideos are more than 60 seconds,bothreturns everything.morere-searches the last query with a higher limit (adds 5 results each time).download <id>opens a native folder-picker dialog (zenity on Linux, osascript on macOS, PowerShell on Windows) and saves the video withyt-dlp. It accepts multiple ids at once:download 0 2 5.copy <id>copies the video's URL to the clipboard viapyperclip.open --url=<youtube-url>plays any video directly by URL, without needing to search for it first.download --url=<youtube-url>downloads any video directly by URL, without needing to search for it first.- Typing a YouTube URL (containing
youtube.com/watch) directly at the prompt plays it automatically.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yt2cli-0.2.5.tar.gz.
File metadata
- Download URL: yt2cli-0.2.5.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Linux/7.1.7-200.fc44.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76de18f23a9df3baec1e56f888b0d6c5c0de0931a14f2b3bf03b839e5fee14a7
|
|
| MD5 |
8785bf4bd6c691708303dfdb35892f8c
|
|
| BLAKE2b-256 |
d1b2646740d9b7c87a4139cb970066214b3887e2049837f556fc09239379ac77
|
File details
Details for the file yt2cli-0.2.5-py3-none-any.whl.
File metadata
- Download URL: yt2cli-0.2.5-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Linux/7.1.7-200.fc44.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bddba06536e70ce8d4787b944f171f45d37553911266dc0288cf9b3bfde5a17c
|
|
| MD5 |
7aa26ba18472a780e08bb329df6bb4de
|
|
| BLAKE2b-256 |
0d389edea805da02a653040e7a3c6c130d069a6467462ce0f8d835296b7ce060
|