A simple library for extracting YouTube content using yt-dlp
Project description
🎥🎵 Tubegrab
A Python library for extracting video, audio, and metadata from YouTube.
It provides a clean dataclass-based API with built-in JSON serialization (to_json / from_json) and integrates well with frameworks like Django REST Framework.
Built on top of yt-dlp for reliable and fast YouTube extraction.
📚 Table of Contents
- ✨ Features
- 📦 Installation
- 🚀 Quick Start
- 🗂 JSON Serialization
- ⚙️ Django REST Framework Integration
- 🛠 Development
- 🤝 Contributing
- 📦 Build & Publish
- 🔐 Versioning
- 📝 License
✨ Features
- 📥 Extract video metadata – title, id, duration, uploader, thumbnails, and more
- 🎶 List all available audio formats – codecs, bitrates, container, size, and direct download URL
- 🎬 List all available video formats – resolution, fps, codecs, container, and direct download URL
- 🌍 Subtitle extraction – download subtitles in multiple languages
- 💾 Built-in serialization (
to_json/from_json) - 🛠 Django REST Framework friendly
- ⚡ Powered by
yt-dlp
📦 Installation
pip install tubegrab
Requires Python 3.8+
🚀 Quick Start
from tubegrab import YouTube
video_url = "https://www.youtube.com/watch?v=Wpi1_RsRaAU"
youtube = YouTube(video_url)
youtube.extract_info(download=True)
# Metadata
data = youtube.video_data()
print("Title:", data.title)
print("Duration:", data.duration)
print("Uploader:", data.uploader)
# Audio formats
audio = youtube.audio_formats()
print(audio.to_json())
# Video formats
videos = youtube.video_formats()
print(videos.to_json())
# Subtitles (if available)
if data.subtitles:
for lang, subs in data.subtitles.items():
print(f"Language: {lang}, Available formats: {[s.ext for s in subs]}")
🗂 JSON Serialization
All returned objects support:
to_json(to_dict=True)→ convert to serializable dictionaryfrom_json(data)→ restore object from dictionary
Example:
import json
from tubegrab import YouTube
youtube = YouTube("https://www.youtube.com/watch?v=Wpi1_RsRaAU")
youtube.extract_info(download=True)
data = youtube.video_data()
# Save
with open("video.json", "w") as f:
json.dump(data.to_json(to_dict=True), f, indent=4)
# Restore
with open("video.json", "r") as f:
restored = YouTube.VideoData.from_json(json.load(f))
print(restored.title)
⚙️ Django REST Framework Integration
from rest_framework import serializers
from tubegrab import YouTube
class VideoDataSerializer(serializers.Serializer):
id = serializers.CharField()
title = serializers.CharField()
duration = serializers.IntegerField()
uploader = serializers.CharField()
thumbnails = serializers.ListField()
youtube = YouTube("https://www.youtube.com/watch?v=Wpi1_RsRaAU")
youtube.extract_info()
serializer = VideoDataSerializer(
youtube.video_data().to_json(to_dict=True)
)
print(serializer.data)
🛠 Development
Clone the repository
git clone https://github.com/yourusername/tubegrab.git
cd tubegrab
Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
Install in editable mode
pip install -e .
🤝 Contributing
Contributions are welcome!
How to Contribute
-
Fork the repository
-
Create a new branch
git checkout -b feature/my-feature
-
Make your changes
-
Add tests (if applicable)
-
Commit your changes
git commit -m "Add: my new feature"
-
Push to your fork
git push origin feature/my-feature
-
Open a Pull Request
Code Style
- Follow PEP 8
- Use type hints
- Keep API clean and minimal
- Ensure serialization (
to_json/from_json) remains stable
📦 Build & Publish
This project uses a modern pyproject.toml build system.
1️⃣ Install build tools
pip install build twine
2️⃣ Build the package
python -m build
This generates:
dist/
├── tubegrab-x.x.x.tar.gz
└── tubegrab-x.x.x-py3-none-any.whl
3️⃣ Upload to TestPyPI (Recommended)
twine upload --repository testpypi dist/*
Test installation:
pip install --index-url https://test.pypi.org/simple/ tubegrab
4️⃣ Publish to PyPI
twine upload dist/*
🔐 Versioning
Use Semantic Versioning:
MAJOR.MINOR.PATCH
Examples:
1.0.0– First stable release1.1.0– New features1.1.1– Bug fixes
📝 License
MIT License © 2026
Project details
Release history Release notifications | RSS feed
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 tubegrab-0.1.1.tar.gz.
File metadata
- Download URL: tubegrab-0.1.1.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab1c8faa81f0cd6d091196cf1177658457abbe4ac7bfd233251db6e0ab58eed6
|
|
| MD5 |
bbe08568dc3b402854667e99d6ef045a
|
|
| BLAKE2b-256 |
9c3b340064a9a9857fca71ae97f15049551599bef49b82240f98d68b714a99e7
|
File details
Details for the file tubegrab-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tubegrab-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9aad0631af37d26dcd0bcaf5c7e098435012e75a78f281378e8a2da9aaf2b698
|
|
| MD5 |
365c63f36180c1ad2730639e2883e550
|
|
| BLAKE2b-256 |
09e880452ee7734ef080226808411b3adeb7fb2e330e2c65c01263a4022952b0
|