ytconvert-cli 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ytconvert_cli-1.0.0/.gitignore +148 -0
- ytconvert_cli-1.0.0/LICENSE +21 -0
- ytconvert_cli-1.0.0/PKG-INFO +224 -0
- ytconvert_cli-1.0.0/README.md +184 -0
- ytconvert_cli-1.0.0/pyproject.toml +129 -0
- ytconvert_cli-1.0.0/ytconvert/__init__.py +27 -0
- ytconvert_cli-1.0.0/ytconvert/cli.py +146 -0
- ytconvert_cli-1.0.0/ytconvert/converter.py +355 -0
- ytconvert_cli-1.0.0/ytconvert/exceptions.py +69 -0
- ytconvert_cli-1.0.0/ytconvert/py.typed +0 -0
- ytconvert_cli-1.0.0/ytconvert/utils.py +186 -0
- ytconvert_cli-1.0.0/ytconvert/validators.py +133 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
*.manifest
|
|
31
|
+
*.spec
|
|
32
|
+
|
|
33
|
+
# Installer logs
|
|
34
|
+
pip-log.txt
|
|
35
|
+
pip-delete-this-directory.txt
|
|
36
|
+
|
|
37
|
+
# Unit test / coverage reports
|
|
38
|
+
htmlcov/
|
|
39
|
+
.tox/
|
|
40
|
+
.nox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
.cache
|
|
44
|
+
nosetests.xml
|
|
45
|
+
coverage.xml
|
|
46
|
+
*.cover
|
|
47
|
+
*.py,cover
|
|
48
|
+
.hypothesis/
|
|
49
|
+
.pytest_cache/
|
|
50
|
+
|
|
51
|
+
# Translations
|
|
52
|
+
*.mo
|
|
53
|
+
*.pot
|
|
54
|
+
|
|
55
|
+
# Django stuff:
|
|
56
|
+
*.log
|
|
57
|
+
local_settings.py
|
|
58
|
+
db.sqlite3
|
|
59
|
+
db.sqlite3-journal
|
|
60
|
+
|
|
61
|
+
# Flask stuff:
|
|
62
|
+
instance/
|
|
63
|
+
.webassets-cache
|
|
64
|
+
|
|
65
|
+
# Scrapy stuff:
|
|
66
|
+
.scrapy
|
|
67
|
+
|
|
68
|
+
# Sphinx documentation
|
|
69
|
+
docs/_build/
|
|
70
|
+
|
|
71
|
+
# PyBuilder
|
|
72
|
+
.pybuilder/
|
|
73
|
+
target/
|
|
74
|
+
|
|
75
|
+
# Jupyter Notebook
|
|
76
|
+
.ipynb_checkpoints
|
|
77
|
+
|
|
78
|
+
# IPython
|
|
79
|
+
profile_default/
|
|
80
|
+
ipython_config.py
|
|
81
|
+
|
|
82
|
+
# pyenv
|
|
83
|
+
.python-version
|
|
84
|
+
|
|
85
|
+
# pipenv
|
|
86
|
+
Pipfile.lock
|
|
87
|
+
|
|
88
|
+
# PEP 582
|
|
89
|
+
__pypackages__/
|
|
90
|
+
|
|
91
|
+
# Celery stuff
|
|
92
|
+
celerybeat-schedule
|
|
93
|
+
celerybeat.pid
|
|
94
|
+
|
|
95
|
+
# SageMath parsed files
|
|
96
|
+
*.sage.py
|
|
97
|
+
|
|
98
|
+
# Environments
|
|
99
|
+
.env
|
|
100
|
+
.venv
|
|
101
|
+
env/
|
|
102
|
+
venv/
|
|
103
|
+
ENV/
|
|
104
|
+
env.bak/
|
|
105
|
+
venv.bak/
|
|
106
|
+
|
|
107
|
+
# Spyder project settings
|
|
108
|
+
.spyderproject
|
|
109
|
+
.spyproject
|
|
110
|
+
|
|
111
|
+
# Rope project settings
|
|
112
|
+
.ropeproject
|
|
113
|
+
|
|
114
|
+
# mkdocs documentation
|
|
115
|
+
/site
|
|
116
|
+
|
|
117
|
+
# mypy
|
|
118
|
+
.mypy_cache/
|
|
119
|
+
.dmypy.json
|
|
120
|
+
dmypy.json
|
|
121
|
+
|
|
122
|
+
# Pyre type checker
|
|
123
|
+
.pyre/
|
|
124
|
+
|
|
125
|
+
# pytype static type analyzer
|
|
126
|
+
.pytype/
|
|
127
|
+
|
|
128
|
+
# Cython debug symbols
|
|
129
|
+
cython_debug/
|
|
130
|
+
|
|
131
|
+
# IDE
|
|
132
|
+
.idea/
|
|
133
|
+
.vscode/
|
|
134
|
+
*.swp
|
|
135
|
+
*.swo
|
|
136
|
+
*~
|
|
137
|
+
|
|
138
|
+
# OS
|
|
139
|
+
.DS_Store
|
|
140
|
+
Thumbs.db
|
|
141
|
+
|
|
142
|
+
# Project specific
|
|
143
|
+
downloads/
|
|
144
|
+
output/
|
|
145
|
+
*.mp3
|
|
146
|
+
*.mp4
|
|
147
|
+
*.webm
|
|
148
|
+
*.m4a
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ytconvert-cli contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ytconvert-cli
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A command-line tool to convert YouTube videos to MP3 or MP4 using yt-dlp
|
|
5
|
+
Project-URL: Homepage, https://github.com/yourusername/ytconvert-cli
|
|
6
|
+
Project-URL: Documentation, https://github.com/yourusername/ytconvert-cli#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/yourusername/ytconvert-cli
|
|
8
|
+
Project-URL: Issues, https://github.com/yourusername/ytconvert-cli/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/yourusername/ytconvert-cli/blob/main/CHANGELOG.md
|
|
10
|
+
Author: ytconvert-cli contributors
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: audio,cli,converter,download,mp3,mp4,video,youtube,yt-dlp
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
26
|
+
Classifier: Topic :: Multimedia :: Video
|
|
27
|
+
Classifier: Topic :: Utilities
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Requires-Dist: imageio-ffmpeg>=0.4.9
|
|
30
|
+
Requires-Dist: typer>=0.9.0
|
|
31
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
32
|
+
Requires-Dist: yt-dlp>=2024.1.0
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# ytconvert-cli
|
|
43
|
+
|
|
44
|
+
**Production-ready YouTube to MP3/MP4 converter.**
|
|
45
|
+
|
|
46
|
+
[](https://pypi.org/project/ytconvert-cli/)
|
|
47
|
+
[](https://www.python.org/downloads/)
|
|
48
|
+
[](https://opensource.org/licenses/MIT)
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 🚀 Features
|
|
53
|
+
|
|
54
|
+
- Convert YouTube videos to **MP3** (audio extraction)
|
|
55
|
+
- Download YouTube videos as **MP4** (with quality selection)
|
|
56
|
+
- Custom output directory support
|
|
57
|
+
- Progress indicators with download speed and ETA
|
|
58
|
+
- Clean error handling with specific exit codes
|
|
59
|
+
- **FFmpeg is bundled**—no separate install needed
|
|
60
|
+
- Uses yt-dlp Python API (no shell calls)
|
|
61
|
+
- Pip-installable and PyPI-ready
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 📦 Installation
|
|
66
|
+
|
|
67
|
+
### From PyPI (recommended)
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install ytconvert-cli
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### From source
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
git clone https://github.com/yourusername/ytconvert-cli.git
|
|
77
|
+
cd ytconvert-cli
|
|
78
|
+
pip install .
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 🖥️ CLI Usage
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Convert to MP3 (default)
|
|
87
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID
|
|
88
|
+
|
|
89
|
+
# Convert to MP4
|
|
90
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID --format mp4
|
|
91
|
+
|
|
92
|
+
# MP4 with specific quality
|
|
93
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID --format mp4 --quality 720p
|
|
94
|
+
|
|
95
|
+
# Save to custom directory
|
|
96
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID -f mp3 -o ./downloads
|
|
97
|
+
|
|
98
|
+
# Get video info only (no download)
|
|
99
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID --info
|
|
100
|
+
|
|
101
|
+
# Show help
|
|
102
|
+
ytconvert --help
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Short options:**
|
|
106
|
+
| Long | Short | Description |
|
|
107
|
+
|-----------|-------|---------------------|
|
|
108
|
+
| --format | -f | mp3 or mp4 |
|
|
109
|
+
| --quality | -q | Video quality |
|
|
110
|
+
| --output | -o | Output directory |
|
|
111
|
+
| --info | -i | Info only |
|
|
112
|
+
| --verbose | -v | Debug mode |
|
|
113
|
+
| --version | -V | Show version |
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 🐍 Python API Usage
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from ytconvert import YouTubeConverter
|
|
121
|
+
|
|
122
|
+
# Convert to MP3
|
|
123
|
+
converter = YouTubeConverter(output_dir="./downloads")
|
|
124
|
+
mp3_path = converter.convert_to_mp3("https://youtube.com/watch?v=VIDEO_ID")
|
|
125
|
+
print(f"Saved: {mp3_path}")
|
|
126
|
+
|
|
127
|
+
# Convert to MP4 with quality
|
|
128
|
+
mp4_path = converter.convert_to_mp4("https://youtube.com/watch?v=VIDEO_ID", quality="720p")
|
|
129
|
+
|
|
130
|
+
# Get video info only
|
|
131
|
+
info = converter.get_video_info("https://youtube.com/watch?v=VIDEO_ID")
|
|
132
|
+
print(f"Title: {info['title']}")
|
|
133
|
+
print(f"Duration: {info['duration']} seconds")
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 🛠️ Integration Example (Django, subprocess)
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
import subprocess
|
|
142
|
+
import sys
|
|
143
|
+
|
|
144
|
+
def convert_youtube_video(url: str, format: str = "mp3", quality: str = "best"):
|
|
145
|
+
cmd = [
|
|
146
|
+
sys.executable, "-m", "ytconvert.cli",
|
|
147
|
+
url,
|
|
148
|
+
"--format", format,
|
|
149
|
+
"--output", "/path/to/downloads",
|
|
150
|
+
]
|
|
151
|
+
if format == "mp4" and quality != "best":
|
|
152
|
+
cmd.extend(["--quality", quality])
|
|
153
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
154
|
+
if result.returncode == 0:
|
|
155
|
+
return {"success": True, "output": result.stdout}
|
|
156
|
+
else:
|
|
157
|
+
return {"success": False, "exit_code": result.returncode, "error": result.stderr}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## ⚠️ Exit Codes
|
|
163
|
+
|
|
164
|
+
| Code | Meaning |
|
|
165
|
+
|------|-------------------------------|
|
|
166
|
+
| 0 | Success |
|
|
167
|
+
| 1 | Invalid YouTube URL |
|
|
168
|
+
| 2 | Download failure |
|
|
169
|
+
| 3 | Format or quality unavailable |
|
|
170
|
+
| 4 | Unexpected error |
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 🏗️ Project Structure
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
ytconvert-cli/
|
|
178
|
+
├── ytconvert/
|
|
179
|
+
│ ├── __init__.py # Package exports
|
|
180
|
+
│ ├── cli.py # CLI entry point
|
|
181
|
+
│ ├── converter.py # yt-dlp logic
|
|
182
|
+
│ ├── validators.py # URL/format validation
|
|
183
|
+
│ ├── exceptions.py # Custom exceptions
|
|
184
|
+
│ └── utils.py # Utilities
|
|
185
|
+
├── pyproject.toml # Packaging config
|
|
186
|
+
├── README.md # This file
|
|
187
|
+
└── LICENSE # MIT License
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## 📝 Development
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Run tests
|
|
196
|
+
pytest
|
|
197
|
+
|
|
198
|
+
# Format code
|
|
199
|
+
black ytconvert/
|
|
200
|
+
ruff check ytconvert/ --fix
|
|
201
|
+
|
|
202
|
+
# Type check
|
|
203
|
+
mypy ytconvert/
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## 📄 License
|
|
209
|
+
|
|
210
|
+
MIT License - see [LICENSE](LICENSE)
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## 🙏 Acknowledgments
|
|
215
|
+
|
|
216
|
+
- [yt-dlp](https://github.com/yt-dlp/yt-dlp) - Video downloader
|
|
217
|
+
- [Typer](https://typer.tiangolo.com/) - CLI framework
|
|
218
|
+
- [FFmpeg](https://ffmpeg.org/) - Media backend (bundled)
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## 📢 Disclaimer
|
|
223
|
+
|
|
224
|
+
This tool is intended for downloading videos you have the right to download. Please respect copyright laws and YouTube's Terms of Service. The authors are not responsible for misuse.
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
|
|
2
|
+
# ytconvert-cli
|
|
3
|
+
|
|
4
|
+
**Production-ready YouTube to MP3/MP4 converter.**
|
|
5
|
+
|
|
6
|
+
[](https://pypi.org/project/ytconvert-cli/)
|
|
7
|
+
[](https://www.python.org/downloads/)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🚀 Features
|
|
13
|
+
|
|
14
|
+
- Convert YouTube videos to **MP3** (audio extraction)
|
|
15
|
+
- Download YouTube videos as **MP4** (with quality selection)
|
|
16
|
+
- Custom output directory support
|
|
17
|
+
- Progress indicators with download speed and ETA
|
|
18
|
+
- Clean error handling with specific exit codes
|
|
19
|
+
- **FFmpeg is bundled**—no separate install needed
|
|
20
|
+
- Uses yt-dlp Python API (no shell calls)
|
|
21
|
+
- Pip-installable and PyPI-ready
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 📦 Installation
|
|
26
|
+
|
|
27
|
+
### From PyPI (recommended)
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install ytconvert-cli
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### From source
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/yourusername/ytconvert-cli.git
|
|
37
|
+
cd ytconvert-cli
|
|
38
|
+
pip install .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 🖥️ CLI Usage
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Convert to MP3 (default)
|
|
47
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID
|
|
48
|
+
|
|
49
|
+
# Convert to MP4
|
|
50
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID --format mp4
|
|
51
|
+
|
|
52
|
+
# MP4 with specific quality
|
|
53
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID --format mp4 --quality 720p
|
|
54
|
+
|
|
55
|
+
# Save to custom directory
|
|
56
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID -f mp3 -o ./downloads
|
|
57
|
+
|
|
58
|
+
# Get video info only (no download)
|
|
59
|
+
ytconvert https://www.youtube.com/watch?v=VIDEO_ID --info
|
|
60
|
+
|
|
61
|
+
# Show help
|
|
62
|
+
ytconvert --help
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Short options:**
|
|
66
|
+
| Long | Short | Description |
|
|
67
|
+
|-----------|-------|---------------------|
|
|
68
|
+
| --format | -f | mp3 or mp4 |
|
|
69
|
+
| --quality | -q | Video quality |
|
|
70
|
+
| --output | -o | Output directory |
|
|
71
|
+
| --info | -i | Info only |
|
|
72
|
+
| --verbose | -v | Debug mode |
|
|
73
|
+
| --version | -V | Show version |
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 🐍 Python API Usage
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from ytconvert import YouTubeConverter
|
|
81
|
+
|
|
82
|
+
# Convert to MP3
|
|
83
|
+
converter = YouTubeConverter(output_dir="./downloads")
|
|
84
|
+
mp3_path = converter.convert_to_mp3("https://youtube.com/watch?v=VIDEO_ID")
|
|
85
|
+
print(f"Saved: {mp3_path}")
|
|
86
|
+
|
|
87
|
+
# Convert to MP4 with quality
|
|
88
|
+
mp4_path = converter.convert_to_mp4("https://youtube.com/watch?v=VIDEO_ID", quality="720p")
|
|
89
|
+
|
|
90
|
+
# Get video info only
|
|
91
|
+
info = converter.get_video_info("https://youtube.com/watch?v=VIDEO_ID")
|
|
92
|
+
print(f"Title: {info['title']}")
|
|
93
|
+
print(f"Duration: {info['duration']} seconds")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 🛠️ Integration Example (Django, subprocess)
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
import subprocess
|
|
102
|
+
import sys
|
|
103
|
+
|
|
104
|
+
def convert_youtube_video(url: str, format: str = "mp3", quality: str = "best"):
|
|
105
|
+
cmd = [
|
|
106
|
+
sys.executable, "-m", "ytconvert.cli",
|
|
107
|
+
url,
|
|
108
|
+
"--format", format,
|
|
109
|
+
"--output", "/path/to/downloads",
|
|
110
|
+
]
|
|
111
|
+
if format == "mp4" and quality != "best":
|
|
112
|
+
cmd.extend(["--quality", quality])
|
|
113
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
114
|
+
if result.returncode == 0:
|
|
115
|
+
return {"success": True, "output": result.stdout}
|
|
116
|
+
else:
|
|
117
|
+
return {"success": False, "exit_code": result.returncode, "error": result.stderr}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## ⚠️ Exit Codes
|
|
123
|
+
|
|
124
|
+
| Code | Meaning |
|
|
125
|
+
|------|-------------------------------|
|
|
126
|
+
| 0 | Success |
|
|
127
|
+
| 1 | Invalid YouTube URL |
|
|
128
|
+
| 2 | Download failure |
|
|
129
|
+
| 3 | Format or quality unavailable |
|
|
130
|
+
| 4 | Unexpected error |
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 🏗️ Project Structure
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
ytconvert-cli/
|
|
138
|
+
├── ytconvert/
|
|
139
|
+
│ ├── __init__.py # Package exports
|
|
140
|
+
│ ├── cli.py # CLI entry point
|
|
141
|
+
│ ├── converter.py # yt-dlp logic
|
|
142
|
+
│ ├── validators.py # URL/format validation
|
|
143
|
+
│ ├── exceptions.py # Custom exceptions
|
|
144
|
+
│ └── utils.py # Utilities
|
|
145
|
+
├── pyproject.toml # Packaging config
|
|
146
|
+
├── README.md # This file
|
|
147
|
+
└── LICENSE # MIT License
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 📝 Development
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Run tests
|
|
156
|
+
pytest
|
|
157
|
+
|
|
158
|
+
# Format code
|
|
159
|
+
black ytconvert/
|
|
160
|
+
ruff check ytconvert/ --fix
|
|
161
|
+
|
|
162
|
+
# Type check
|
|
163
|
+
mypy ytconvert/
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## 📄 License
|
|
169
|
+
|
|
170
|
+
MIT License - see [LICENSE](LICENSE)
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 🙏 Acknowledgments
|
|
175
|
+
|
|
176
|
+
- [yt-dlp](https://github.com/yt-dlp/yt-dlp) - Video downloader
|
|
177
|
+
- [Typer](https://typer.tiangolo.com/) - CLI framework
|
|
178
|
+
- [FFmpeg](https://ffmpeg.org/) - Media backend (bundled)
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 📢 Disclaimer
|
|
183
|
+
|
|
184
|
+
This tool is intended for downloading videos you have the right to download. Please respect copyright laws and YouTube's Terms of Service. The authors are not responsible for misuse.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ytconvert-cli"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "A command-line tool to convert YouTube videos to MP3 or MP4 using yt-dlp"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "ytconvert-cli contributors"}
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"youtube",
|
|
17
|
+
"converter",
|
|
18
|
+
"mp3",
|
|
19
|
+
"mp4",
|
|
20
|
+
"yt-dlp",
|
|
21
|
+
"cli",
|
|
22
|
+
"video",
|
|
23
|
+
"audio",
|
|
24
|
+
"download",
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 5 - Production/Stable",
|
|
28
|
+
"Environment :: Console",
|
|
29
|
+
"Intended Audience :: End Users/Desktop",
|
|
30
|
+
"Intended Audience :: Developers",
|
|
31
|
+
"License :: OSI Approved :: MIT License",
|
|
32
|
+
"Operating System :: OS Independent",
|
|
33
|
+
"Programming Language :: Python :: 3",
|
|
34
|
+
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
38
|
+
"Topic :: Multimedia :: Sound/Audio",
|
|
39
|
+
"Topic :: Multimedia :: Video",
|
|
40
|
+
"Topic :: Utilities",
|
|
41
|
+
]
|
|
42
|
+
dependencies = [
|
|
43
|
+
"yt-dlp>=2024.1.0",
|
|
44
|
+
"typer>=0.9.0",
|
|
45
|
+
"typing-extensions>=4.0.0",
|
|
46
|
+
"imageio-ffmpeg>=0.4.9",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[project.optional-dependencies]
|
|
50
|
+
dev = [
|
|
51
|
+
"pytest>=7.0.0",
|
|
52
|
+
"pytest-cov>=4.0.0",
|
|
53
|
+
"mypy>=1.0.0",
|
|
54
|
+
"ruff>=0.1.0",
|
|
55
|
+
"black>=23.0.0",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
[project.scripts]
|
|
59
|
+
ytconvert = "ytconvert.cli:cli"
|
|
60
|
+
|
|
61
|
+
[project.urls]
|
|
62
|
+
Homepage = "https://github.com/yourusername/ytconvert-cli"
|
|
63
|
+
Documentation = "https://github.com/yourusername/ytconvert-cli#readme"
|
|
64
|
+
Repository = "https://github.com/yourusername/ytconvert-cli"
|
|
65
|
+
Issues = "https://github.com/yourusername/ytconvert-cli/issues"
|
|
66
|
+
Changelog = "https://github.com/yourusername/ytconvert-cli/blob/main/CHANGELOG.md"
|
|
67
|
+
|
|
68
|
+
[tool.hatch.build.targets.wheel]
|
|
69
|
+
packages = ["ytconvert"]
|
|
70
|
+
|
|
71
|
+
[tool.hatch.build.targets.sdist]
|
|
72
|
+
include = [
|
|
73
|
+
"/ytconvert",
|
|
74
|
+
"/README.md",
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
[tool.ruff]
|
|
78
|
+
target-version = "py310"
|
|
79
|
+
line-length = 100
|
|
80
|
+
|
|
81
|
+
[tool.ruff.lint]
|
|
82
|
+
select = [
|
|
83
|
+
"E", # pycodestyle errors
|
|
84
|
+
"W", # pycodestyle warnings
|
|
85
|
+
"F", # Pyflakes
|
|
86
|
+
"I", # isort
|
|
87
|
+
"B", # flake8-bugbear
|
|
88
|
+
"C4", # flake8-comprehensions
|
|
89
|
+
"UP", # pyupgrade
|
|
90
|
+
"ARG", # flake8-unused-arguments
|
|
91
|
+
"SIM", # flake8-simplify
|
|
92
|
+
]
|
|
93
|
+
ignore = [
|
|
94
|
+
"E501", # line too long (handled by formatter)
|
|
95
|
+
"B008", # do not perform function calls in argument defaults
|
|
96
|
+
"B905", # zip without explicit strict parameter
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
[tool.ruff.lint.isort]
|
|
100
|
+
known-first-party = ["ytconvert"]
|
|
101
|
+
|
|
102
|
+
[tool.mypy]
|
|
103
|
+
python_version = "3.10"
|
|
104
|
+
strict = true
|
|
105
|
+
warn_return_any = true
|
|
106
|
+
warn_unused_ignores = true
|
|
107
|
+
disallow_untyped_defs = true
|
|
108
|
+
|
|
109
|
+
[[tool.mypy.overrides]]
|
|
110
|
+
module = "yt_dlp.*"
|
|
111
|
+
ignore_missing_imports = true
|
|
112
|
+
|
|
113
|
+
[tool.pytest.ini_options]
|
|
114
|
+
testpaths = ["tests"]
|
|
115
|
+
python_files = "test_*.py"
|
|
116
|
+
python_functions = "test_*"
|
|
117
|
+
addopts = "-v --tb=short"
|
|
118
|
+
|
|
119
|
+
[tool.coverage.run]
|
|
120
|
+
source = ["ytconvert"]
|
|
121
|
+
branch = true
|
|
122
|
+
|
|
123
|
+
[tool.coverage.report]
|
|
124
|
+
exclude_lines = [
|
|
125
|
+
"pragma: no cover",
|
|
126
|
+
"def __repr__",
|
|
127
|
+
"raise NotImplementedError",
|
|
128
|
+
"if __name__ == .__main__.:",
|
|
129
|
+
]
|