dj-cli 0.1.0

A CLI tool for DJs to download MP3s from YouTube
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<p align="center">
  <img src="logo.png" alt="dj-cli logo" width="400"/>
</p>

<h1 align="center">🎵 DJ-CLI</h1>
<h2 align="center">Professional Terminal Interface for YouTube MP3 Downloads</h2>

<p align="center">
  <a href="https://crates.io/crates/dj-cli">
    <img src="https://img.shields.io/crates/v/dj-cli?label=crates.io&logo=rust&color=orange" alt="Crates.io version"/>
  </a>
  <a href="https://docs.rs/dj-cli">
    <img src="https://img.shields.io/docsrs/dj-cli?label=docs.rs" alt="docs.rs status"/>
  </a>
  <a href="https://github.com/henryoman/dj-cli/actions">
    <img src="https://img.shields.io/github/actions/workflow/status/henryoman/dj-cli/ci.yml?branch=main&label=CI&logo=github" alt="Build Status"/>
  </a>
  <a href="https://github.com/henryoman/dj-cli/stargazers">
    <img src="https://img.shields.io/github/stars/henryoman/dj-cli?style=social" alt="GitHub stars"/>
  </a>
  <a href="./LICENSE">
    <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"/>
  </a>
</p>

---

## 📸 Interface Preview

<p align="center">
  <img src="dj-screenshot.png" alt="DJ-CLI Terminal Interface" width="800"/>
</p>

*DJ-CLI's beautiful terminal interface featuring real-time status updates, batch processing capabilities, and intuitive keyboard controls.*

---

## ✨ Features

### 🚀 **Core Functionality**
- **Lightning-fast downloads** using the battle-tested [`yt-dlp`]https://github.com/yt-dlp/yt-dlp backend
- **High-quality audio extraction** with support for 128kbps and 256kbps MP3 output
- **Smart URL extraction** from messy clipboard text - paste anything, get clean URLs
- **Batch processing** - queue multiple videos and download them all at once
- **Async operations** - non-blocking downloads with real-time progress updates

### 🎨 **Terminal User Interface**
- **Beautiful TUI** powered by [`ratatui`]https://ratatui.rs with vibrant colors
- **Responsive design** that adapts to different terminal sizes
- **Real-time status updates** with download progress and error handling
- **Keyboard-driven navigation** with intuitive controls
- **Focus management** for seamless user experience

### 🛡️ **Reliability & Performance**
- **Robust error handling** - graceful failures that don't crash the interface
- **Input sanitization** - automatically cleans and validates pasted content
- **Memory-safe operations** with input length limits and cleanup
- **Cross-platform support**: macOS, Linux, Windows (via WSL)
- **Zero external dependencies** beyond yt-dlp and ffmpeg

### 📁 **File Management**
- **Automatic organization** - downloads save directly to your Downloads folder
- **Metadata embedding** - includes thumbnails and track information
- **Filename sanitization** - handles special characters and long titles
- **Duplicate detection** - smart handling of existing files

---

## 🚀 Quick Start

### Installation Options

#### Option 1: Install from Crates.io (Recommended)
```bash
cargo install dj-cli
```

#### Option 2: Build from Source
```bash
git clone https://github.com/henryoman/dj-cli.git
cd dj-cli
cargo build --release
cargo install --path .
```

#### Option 3: Run Directly
```bash
git clone https://github.com/henryoman/dj-cli.git
cd dj-cli
cargo run --release
```

### First Run
```bash
# Launch the interactive TUI
dj-cli

# Or download directly (non-interactive)
dj-cli "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
```

---

## 🛠️ Prerequisites & Dependencies

### Required Software

#### 1. Rust Toolchain
DJ-CLI requires **Rust 1.78 or later**. Install via [`rustup`](https://www.rust-lang.org/tools/install):

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
```

#### 2. yt-dlp (Core Download Engine)
Install the latest version of yt-dlp:

```bash
# macOS (Homebrew)
brew install yt-dlp

# Ubuntu/Debian
sudo apt update && sudo apt install yt-dlp

# Arch Linux
sudo pacman -S yt-dlp

# Or via pip (universal)
pip install yt-dlp
```

#### 3. FFmpeg (Audio Processing)
Required for audio extraction and format conversion:

```bash
# macOS (Homebrew)
brew install ffmpeg

# Ubuntu/Debian
sudo apt update && sudo apt install ffmpeg

# Arch Linux
sudo pacman -S ffmpeg

# Windows (Chocolatey)
choco install ffmpeg
```

### Verification
Test your setup:
```bash
yt-dlp --version
ffmpeg -version
cargo --version
```

---

## 📖 Comprehensive Usage Guide

### 🎯 Single Download Mode

1. **Launch DJ-CLI**
   ```bash
   dj-cli
   ```

2. **Paste YouTube URL**
   - Simply paste any YouTube URL into the input field
   - DJ-CLI automatically extracts and cleans the URL from messy clipboard content

3. **Choose Quality & Download**
   - **Tab** to navigate between input field and download buttons
   - **Enter** for default 128kbps download
   - **Ctrl+1** for quick 128kbps download
   - **Ctrl+2** for quick 256kbps download

### 🎯 Batch Download Mode

1. **Enable Batch Mode**
   ```
   Press Ctrl+B to toggle batch mode
   ```

2. **Add Multiple URLs**
   ```
   Paste URL → Press Enter → Repeat for each video
   ```

3. **Start Batch Download**
   ```
   Press Ctrl+D to download all queued videos
   ```

4. **Monitor Progress**
   - Real-time progress updates for each download
   - Success/failure count at completion
   - Detailed status for each URL in the queue

### 🎯 Advanced Features

#### Smart Input Handling
- **Paste any text** containing YouTube URLs - DJ-CLI extracts them automatically
- **F5** to clean and extract URLs from current input
- **Input validation** prevents invalid URLs from processing
- **Length limits** protect against memory issues (500 chars max)

#### Keyboard Shortcuts
| Shortcut | Function |
|----------|----------|
| **Ctrl+C** | Quit application |
| **Esc** | Exit application |
| **Tab** | Switch focus between elements |
| **Enter** | Download (single mode) / Add URL (batch mode) |
| **Ctrl+B** | Toggle batch mode |
| **Ctrl+D** | Start batch download |
| **Ctrl+1** | Quick 128kbps download |
| **Ctrl+2** | Quick 256kbps download |
| **F5** | Clean and extract URL from input |
| **Delete** | Clear input field |
| **Backspace** | Remove last character |

---

## 🔧 Configuration & Customization

### Output Directory
Files are automatically saved to your system's Downloads folder:
- **macOS**: `~/Downloads/`
- **Linux**: `~/Downloads/`
- **Windows**: `%USERPROFILE%\Downloads\`

### Audio Quality Options

| Quality | Bitrate | Use Case |
|---------|---------|----------|
| **128kbps** | Standard quality | General listening, smaller files |
| **256kbps** | High quality | Audiophile listening, DJ sets |

### File Naming
Downloaded files use the format: `[Video Title].mp3`
- Special characters are automatically sanitized
- Long titles are handled gracefully
- Metadata and thumbnails are embedded automatically

---

## 🏗️ Architecture & Technical Details

### Built With Modern Rust
- **[Tokio]https://tokio.rs** - Async runtime for non-blocking operations
- **[Ratatui]https://ratatui.rs** - Terminal UI framework with rich widgets
- **[Crossterm]https://github.com/crossterm-rs/crossterm** - Cross-platform terminal manipulation
- **[Color-eyre]https://github.com/yaahc/color-eyre** - Enhanced error reporting
- **[Tracing]https://github.com/tokio-rs/tracing** - Structured logging
- **[Regex]https://github.com/rust-lang/regex** - URL pattern matching

### Performance Characteristics
- **Memory-efficient**: Smart input limiting and cleanup
- **CPU-light**: Async operations prevent blocking
- **Storage-aware**: Downloads to standard user directories
- **Network-optimized**: Leverages yt-dlp's efficient downloading

### Code Quality
- **Memory safety** through Rust's ownership system
- **Error handling** with graceful degradation
- **Input validation** and sanitization throughout
- **Modular architecture** for maintainability

---

## 🐛 Troubleshooting

### Common Issues

#### "yt-dlp not found"
```bash
# Ensure yt-dlp is installed and in PATH
which yt-dlp
# If not found, install via your package manager
brew install yt-dlp  # macOS
```

#### "Download failed"
```bash
# Check if URL is accessible
yt-dlp --list-formats [YOUR_URL]
# Update yt-dlp to latest version
pip install -U yt-dlp
```

#### "Permission denied" in Downloads folder
```bash
# Check Downloads folder permissions
ls -la ~/Downloads/
# Create if missing
mkdir -p ~/Downloads/
```

#### Audio conversion fails
```bash
# Verify ffmpeg installation
ffmpeg -version
# Reinstall if needed
brew reinstall ffmpeg  # macOS
```

### Debug Mode
For detailed error information:
```bash
# Enable verbose logging (modify source)
RUST_LOG=debug cargo run
```

---

## 🔄 Updates & Maintenance

### Staying Current
```bash
# Update DJ-CLI
cargo install dj-cli --force

# Update yt-dlp (important for YouTube compatibility)
pip install -U yt-dlp

# Update dependencies when building from source
cd dj-cli
cargo update
```

### Version Compatibility
- **Minimum Rust version**: 1.78.0
- **Tested yt-dlp versions**: 2023.12.30+
- **Supported platforms**: macOS 10.15+, Ubuntu 20.04+, Windows 10+ (WSL)

---

## 🤝 Contributing

We welcome contributions! Here's how to get involved:

### Development Setup
```bash
# Clone and setup development environment
git clone https://github.com/henryoman/dj-cli.git
cd dj-cli
cargo build
cargo test

# Install development tools
cargo install cargo-watch
```

### Code Standards
```bash
# Format code
cargo fmt

# Lint with Clippy
cargo clippy --all-targets --all-features -- -D warnings

# Run tests
cargo test
```

### Contribution Workflow
1. **Fork** the repository
2. **Create** a feature branch: `git checkout -b feature/amazing-feature`
3. **Make** your changes with tests
4. **Ensure** all checks pass: `cargo fmt && cargo clippy && cargo test`
5. **Commit** with clear messages: `git commit -m 'Add amazing feature'`
6. **Push** to your fork: `git push origin feature/amazing-feature`
7. **Open** a Pull Request with detailed description

### Areas for Contribution
- 🎨 UI/UX improvements
- 🚀 Performance optimizations
- 🔧 Additional audio formats (FLAC, AAC)
- 📱 Configuration file support
- 🌐 Internationalization
- 📝 Documentation improvements

---

## 📜 License

This project is licensed under the **MIT License** - see the [LICENSE](./LICENSE) file for complete details.

```
MIT License

Copyright (c) 2024 Henryoman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files...
```

---

## 🙏 Acknowledgments

- **[yt-dlp team]https://github.com/yt-dlp/yt-dlp** - Powerful YouTube download engine
- **[Ratatui community]https://ratatui.rs** - Excellent terminal UI framework
- **[Rust community]https://www.rust-lang.org** - Amazing language and ecosystem

---

## 📊 Project Stats

- **Language**: Rust 🦀
- **Lines of Code**: ~850+
- **Dependencies**: 16 (carefully chosen)
- **Binary Size**: ~2MB (optimized)
- **Performance**: Downloads limited only by network speed

---

<p align="center">
  <strong>Built with ❤️ using Rust</strong><br>
  <i>Making YouTube audio downloads fast, safe, and beautiful</i>
</p>