Skip to main content

A simple library for extracting YouTube content using yt-dlp

Project description

🎥🎵 Tubegrab

PyPI version Python versions License Downloads

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

  • 📥 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 dictionary
  • from_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

  1. Fork the repository

  2. Create a new branch

    git checkout -b feature/my-feature
    
  3. Make your changes

  4. Add tests (if applicable)

  5. Commit your changes

    git commit -m "Add: my new feature"
    
  6. Push to your fork

    git push origin feature/my-feature
    
  7. 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 release
  • 1.1.0 – New features
  • 1.1.1 – Bug fixes

📝 License

MIT License © 2026

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tubegrab-0.1.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tubegrab-0.1.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

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

Hashes for tubegrab-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ab1c8faa81f0cd6d091196cf1177658457abbe4ac7bfd233251db6e0ab58eed6
MD5 bbe08568dc3b402854667e99d6ef045a
BLAKE2b-256 9c3b340064a9a9857fca71ae97f15049551599bef49b82240f98d68b714a99e7

See more details on using hashes here.

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

Hashes for tubegrab-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9aad0631af37d26dcd0bcaf5c7e098435012e75a78f281378e8a2da9aaf2b698
MD5 365c63f36180c1ad2730639e2883e550
BLAKE2b-256 09e880452ee7734ef080226808411b3adeb7fb2e330e2c65c01263a4022952b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page