- Remove runtime artifacts (app.log, .DS_Store, committed home dir data) - Remove AI session notes (prompt.md, agent.md, LOGGING_*.md) - Move TUI.md, structure.md, docker-setup.md to docs/ - Normalize author metadata to Jarian Cottingham - Fix hardcoded personal paths in gunicorn config and manual test script - Pin textual <2.0 (8.x grid layout breaks TUI rendering) - Fix stale tests: private attr access, missing screen push - Add CI workflow (ruff + pytest, Python 3.10-3.12)
10 KiB
YouTube TUI Documentation
A modern, terminal-based user interface for browsing and downloading YouTube videos using Textual and yt-dlp.
Features
- Modern Terminal Interface - Built with Textual for a rich, interactive experience
- Search Videos - Search YouTube with keyword queries and view results in a table
- Download Videos - Download videos directly with progress indication
- Playlist Support - Download entire YouTube playlists
- Pagination - Navigate through search results with keyboard shortcuts
- Category Selection - Choose download locations from configured categories
- Network Share Integration - Automatically copy downloads to network shares
- Download Archive - Track already downloaded videos
- Short Video Detection - Automatically detect and mark short videos
- Keyboard Navigation - Full keyboard control with intuitive shortcuts
- Responsive Design - Works in any terminal size with adaptive layout
Requirements
- Python 3.7+
- Textual (TUI framework)
- yt-dlp
- rich
Installation
From Source
git clone https://github.com/yourusername/youtube-cli.git
cd youtube-cli
pip install -e .[tui,dev]
With pip
pip install youtube-cli[tui]
Using pip with all extras
pip install youtube-cli[all]
This will install:
- Core dependencies (yt-dlp, rich, requests)
- TUI dependencies (textual)
- Development tools (pytest, black, ruff, mypy)
Docker Installation
docker build -t youtube-tui -f docker/Dockerfile.tui .
docker run -it --rm -v ~/Downloads:/root/Downloads youtube-tui
Usage
Basic Usage
youtube-tui
Running with Arguments
youtube-tui "python tutorial"
This will open the TUI and immediately search for "python tutorial".
Keyboard Shortcuts
Global Shortcuts
| Key | Action | Description |
|---|---|---|
Ctrl+C |
Quit | Exit the application |
Ctrl+Q |
Quit | Exit the application |
F1 |
Help | Open help screen |
Esc |
Back | Go back to previous screen |
Ctrl+R |
Refresh | Refresh current screen |
Search Screen
| Key | Action | Description |
|---|---|---|
Enter |
Search | Execute search with current input |
Ctrl+F |
Search | Open search from anywhere |
Escape |
Cancel | Go back to previous screen |
Results Screen
| Key | Action | Description |
|---|---|---|
Enter |
Download | Download selected video |
n |
Next Page | Go to next page of results |
p |
Previous Page | Go to previous page of results |
q |
Quit | Go back to search screen |
Escape |
Quit | Go back to search screen |
Ctrl+R |
Refresh | Refresh current results |
Ctrl+F |
Search | Open search from anywhere |
Download Screen
| Key | Action | Description |
|---|---|---|
Escape |
Cancel | Cancel current download |
Ctrl+R |
Refresh | Refresh screen |
Navigation
Moving Between Screens
- From Search to Results: Enter a search term and press Enter
- From Results to Download: Select a video and press Enter
- From Download to Results: Wait for download to complete or press Escape to cancel
- From Any Screen to Search: Press Escape or use the navigation menu
Page Navigation
- Next Page: Press
nor click the "Next" button - Previous Page: Press
por click the "Previous" button - Page Indicator: Shows current page and total pages
Configuration
The TUI reads configuration from the same config file as the CLI:
Location: ~/.config/youtube_cli/config.json
Example Configuration:
{
"download_dir": "~/Downloads/youtube",
"default_locations": [
"~/Downloads/youtube",
"~/Movies/youtube",
"/tmp/youtube"
],
"max_videos_per_page": 15,
"yt_dlp_args": {
"format": "bestvideo[height=1080]+bestaudio/bestvideo[height<=1080]+bestaudio",
"write_thumbnail": true,
"extractor_args": "youtube:player-client=default,-tv_simply"
},
"network_share_path": "/Volumes/MediaServer/Youtube/",
"default_network_subfolder": "General"
}
Configuration Options
| Option | Description | Default |
|---|---|---|
download_dir |
Default download directory | ~/Downloads/youtube |
default_locations |
List of category folders | ["~/Downloads/youtube"] |
max_videos_per_page |
Number of videos per page | 15 |
yt_dlp_args |
Custom yt-dlp arguments | {"format": "bestvideo[height=1080]+bestaudio"} |
network_share_path |
Network share path | /Volumes/MediaServer/Youtube/ |
default_network_subfolder |
Default network subfolder | General |
Screens
Search Screen
The search screen is the main entry point. Enter a search term and press Enter to search YouTube.
Features:
- Search input field with placeholder text
- Search and Cancel buttons
- Status bar showing current screen and mode
Results Screen
Displays search results in a table format with:
- Video Title: Click to select for download
- Author/Channel: Shows the video creator
- Duration: Video length (MM:SS format)
- Type: Video, Short, or Playlist indicator
Table Features:
- Keyboard navigation (arrow keys)
- Selection highlighting
- Auto-truncation of long text
- Short video detection with "(short)" prefix
Download Screen
Shows download progress with:
- Video Title: Current video being downloaded
- Progress Bar: Visual progress indicator
- Status Message: Current download state
- Cancel Button: Cancel ongoing download
States:
- Preparing: Initial setup
- Downloading: Active download in progress
- Complete: Download finished successfully
- Failed: Download encountered an error
Help Screen
Displays help information with:
- Keyboard shortcuts reference
- Configuration options
- Troubleshooting tips
- Version information
Status Bar
The status bar appears at the bottom of each screen and shows:
- Current screen name
- Application version
- yt-dlp version
- Status message
- Current time
- Active theme
Theming
The TUI supports theming through Textual's CSS system. You can customize colors and styles by creating a custom CSS file.
Default Theme
The default theme uses a modern dark color scheme with:
- Dark background colors
- Bright text for readability
- Primary color accents
- Muted colors for secondary elements
Custom Themes
Create a custom theme by editing the TUI's CSS file or using Textual's theme system.
Troubleshooting
Application Won't Start
Issue: ModuleNotFoundError: No module named 'textual'
Solution:
pip install textual
Search Returns No Results
Issue: Search completes but no videos are found
Possible Causes:
- Network connectivity issues
- YouTube API restrictions
- Invalid search term
Solutions:
- Check internet connection
- Try a different search term
- Check yt-dlp installation:
yt-dlp --version
Download Fails
Issue: Download starts but fails partway through
Possible Causes:
- Network interruption
- Video unavailable
- Storage space issues
Solutions:
- Check network connection
- Verify video URL works in browser
- Check available disk space
Keyboard Shortcuts Not Working
Issue: Keyboard shortcuts don't respond
Solutions:
- Ensure terminal supports keyboard events
- Check for terminal-specific key bindings
- Try different terminal application
Screen Displays Incorrectly
Issue: Text appears garbled or misaligned
Solutions:
- Resize terminal window
- Check terminal encoding (UTF-8 recommended)
- Update Textual:
pip install --upgrade textual
Configuration Changes Not Applied
Issue: Changes to config file don't take effect
Solutions:
- Restart the application
- Check config file permissions
- Verify JSON syntax is valid
Advanced Usage
Download Multiple Videos
- Search for videos
- Select multiple videos by navigating and using the download function
- The TUI will queue downloads sequentially
Download Playlists
- Search for a playlist URL
- Select the playlist from results
- The TUI will download all videos in the playlist
Custom Download Locations
- Press
Ctrl+Fto open search from anywhere - Search for a video
- When downloading, select a custom category
- The video will be saved to that category's folder
API Integration
The TUI can also be used with the REST API:
# Start the API server
python app.py
# Use the API
curl "http://localhost:4096/search?q=python&page=1"
Development
Running Tests
# Run all tests
python test_tui.py
# Run with coverage
pytest --cov=youtube_tui tests/
# Run specific test file
pytest tests/unit/test_models.py
Building the TUI
# Install development dependencies
pip install -e .[dev]
# Run linter
ruff check .
# Format code
black .
# Type checking
mypy .
Directory Structure
youtube_tui/
├── app.py # Main application class
├── __main__.py # Entry point
├── models/ # Data models
│ ├── __init__.py
│ └── video.py
├── services/ # Service layer
│ ├── __init__.py
│ └── youtube.py
├── screens/ # Textual screens
│ ├── __init__.py
│ ├── search.py
│ ├── results.py
│ ├── download.py
│ └── help.py
└── widgets/ # Custom widgets
├── __init__.py
├── status_bar.py
└── command_palette.py
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
python test_tui.py) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT License