tubegrab


Nametubegrab JSON
Version 0.0.0 PyPI version JSON
download
home_pageNone
SummaryA simple library for extracting YouTube content using yt-dlp
upload_time2025-09-04 06:29:20
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords youtube extract yt-dlp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # YouTube Extractor 🎥🎵

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 other serializers like **Django REST Framework**.

---

## ✨ 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.
-   💾 **Serialization support** – convert objects to JSON (`to_json`) or restore them from JSON (`from_json`).
-   🛠 **Compatible with Django serializers** – easily plug into DRF or custom serializers.
-   ⚡ Built on top of [`yt-dlp`](https://github.com/yt-dlp/yt-dlp) for reliable YouTube extraction.

---

## 📦 Installation

```bash
pip install youtube_extractor
```

> Requires **Python 3.8+**

---

## 🚀 Quick Start

```python
from youtube_extractor import YouTube

# Initialize extractor
video_url = "https://www.youtube.com/watch?v=Wpi1_RsRaAU"
yt = YouTube(video_url)

# Extract metadata + formats
yt.extract_info(download=True)

# General metadata
data = yt.video_data()
print("Title:", data.title)
print("Duration:", data.duration)
print("Uploader:", data.uploader)

# Audio formats
for audio in yt.audio_formats():
    print(audio.codec, audio.bitrate, audio.url)

# Video formats
for video in yt.video_formats():
    print(video.resolution, video.fps, video.url)

# 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 objects support **`to_json`** and **`from_json`**:

```python
import json

# Save to file
with open("video.json", "w") as f:
    json.dump(data.to_json(to_dict=True), f, indent=4)

# Restore from file
with open("video.json", "r") as f:
    restored = YouTube.VideoData.from_json(json.load(f))
    print(restored.title)
```

---

## 📖 Example: Save Audio, Video & Metadata

```python
from youtube_extractor import YouTube
import json

def write(file, obj):
    with open(file, "w") as f:
        json.dump(obj, f, indent=4)

def main(video_url: str):
    yt = YouTube(video_url)
    yt.extract_info(download=True)

    # Extract audio formats
    audio = yt.audio_formats()
    write("Audio.json", audio.to_json(to_dict=True))

    # Extract video formats
    video = yt.video_formats()
    write("Video.json", video.to_json(to_dict=True))

    # Extract general metadata
    data = yt.video_data()
    write("Data.json", data.to_json(to_dict=True))

if __name__ == "__main__":
    main("https://www.youtube.com/watch?v=Wpi1_RsRaAU")
```

This script will create three files in your project directory:

-   `Audio.json` → list of all available **audio formats**
-   `Video.json` → list of all available **video formats**
-   `Data.json` → **general video metadata**

---

## ⚙️ Integration with Django REST Framework

```python
from rest_framework import serializers
from youtube_extractor import YouTube

class VideoDataSerializer(serializers.Serializer):
    id = serializers.CharField()
    title = serializers.CharField()
    duration = serializers.IntegerField()
    uploader = serializers.CharField()
    thumbnails = serializers.ListField()

# Example usage
yt = YouTube("https://www.youtube.com/watch?v=Wpi1_RsRaAU")
yt.extract_info()

serializer = VideoDataSerializer(yt.video_data().to_json(to_dict=True))
print(serializer.data)
```

---

## 📝 License

MIT License © 2025

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tubegrab",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "youtube, extract, yt-dlp",
    "author": null,
    "author_email": "Sachin Acharya <tubegrab.sachin.acharya@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a1/0f/ed9e66b643bcba76e7e2c4065923a063166f6ae8f44e4286134b25c7e792/tubegrab-0.0.0.tar.gz",
    "platform": null,
    "description": "# YouTube Extractor \ud83c\udfa5\ud83c\udfb5\r\n\r\nA Python library for extracting **video, audio, and metadata** from YouTube.\r\nIt provides a clean **dataclass-based API** with built-in JSON serialization (`to_json` / `from_json`) and integrates well with other serializers like **Django REST Framework**.\r\n\r\n---\r\n\r\n## \u2728 Features\r\n\r\n-   \ud83d\udce5 **Extract video metadata** \u2013 title, id, duration, uploader, thumbnails, and more.\r\n-   \ud83c\udfb6 **List all available audio formats** \u2013 codecs, bitrates, container, size, and direct download URL.\r\n-   \ud83c\udfac **List all available video formats** \u2013 resolution, fps, codecs, container, and direct download URL.\r\n-   \ud83c\udf0d **Subtitle extraction** \u2013 download subtitles in multiple languages.\r\n-   \ud83d\udcbe **Serialization support** \u2013 convert objects to JSON (`to_json`) or restore them from JSON (`from_json`).\r\n-   \ud83d\udee0 **Compatible with Django serializers** \u2013 easily plug into DRF or custom serializers.\r\n-   \u26a1 Built on top of [`yt-dlp`](https://github.com/yt-dlp/yt-dlp) for reliable YouTube extraction.\r\n\r\n---\r\n\r\n## \ud83d\udce6 Installation\r\n\r\n```bash\r\npip install youtube_extractor\r\n```\r\n\r\n> Requires **Python 3.8+**\r\n\r\n---\r\n\r\n## \ud83d\ude80 Quick Start\r\n\r\n```python\r\nfrom youtube_extractor import YouTube\r\n\r\n# Initialize extractor\r\nvideo_url = \"https://www.youtube.com/watch?v=Wpi1_RsRaAU\"\r\nyt = YouTube(video_url)\r\n\r\n# Extract metadata + formats\r\nyt.extract_info(download=True)\r\n\r\n# General metadata\r\ndata = yt.video_data()\r\nprint(\"Title:\", data.title)\r\nprint(\"Duration:\", data.duration)\r\nprint(\"Uploader:\", data.uploader)\r\n\r\n# Audio formats\r\nfor audio in yt.audio_formats():\r\n    print(audio.codec, audio.bitrate, audio.url)\r\n\r\n# Video formats\r\nfor video in yt.video_formats():\r\n    print(video.resolution, video.fps, video.url)\r\n\r\n# Subtitles (if available)\r\nif data.subtitles:\r\n    for lang, subs in data.subtitles.items():\r\n        print(f\"Language: {lang}, Available formats: {[s.ext for s in subs]}\")\r\n```\r\n\r\n---\r\n\r\n## \ud83d\uddc2 JSON Serialization\r\n\r\nAll objects support **`to_json`** and **`from_json`**:\r\n\r\n```python\r\nimport json\r\n\r\n# Save to file\r\nwith open(\"video.json\", \"w\") as f:\r\n    json.dump(data.to_json(to_dict=True), f, indent=4)\r\n\r\n# Restore from file\r\nwith open(\"video.json\", \"r\") as f:\r\n    restored = YouTube.VideoData.from_json(json.load(f))\r\n    print(restored.title)\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udcd6 Example: Save Audio, Video & Metadata\r\n\r\n```python\r\nfrom youtube_extractor import YouTube\r\nimport json\r\n\r\ndef write(file, obj):\r\n    with open(file, \"w\") as f:\r\n        json.dump(obj, f, indent=4)\r\n\r\ndef main(video_url: str):\r\n    yt = YouTube(video_url)\r\n    yt.extract_info(download=True)\r\n\r\n    # Extract audio formats\r\n    audio = yt.audio_formats()\r\n    write(\"Audio.json\", audio.to_json(to_dict=True))\r\n\r\n    # Extract video formats\r\n    video = yt.video_formats()\r\n    write(\"Video.json\", video.to_json(to_dict=True))\r\n\r\n    # Extract general metadata\r\n    data = yt.video_data()\r\n    write(\"Data.json\", data.to_json(to_dict=True))\r\n\r\nif __name__ == \"__main__\":\r\n    main(\"https://www.youtube.com/watch?v=Wpi1_RsRaAU\")\r\n```\r\n\r\nThis script will create three files in your project directory:\r\n\r\n-   `Audio.json` \u2192 list of all available **audio formats**\r\n-   `Video.json` \u2192 list of all available **video formats**\r\n-   `Data.json` \u2192 **general video metadata**\r\n\r\n---\r\n\r\n## \u2699\ufe0f Integration with Django REST Framework\r\n\r\n```python\r\nfrom rest_framework import serializers\r\nfrom youtube_extractor import YouTube\r\n\r\nclass VideoDataSerializer(serializers.Serializer):\r\n    id = serializers.CharField()\r\n    title = serializers.CharField()\r\n    duration = serializers.IntegerField()\r\n    uploader = serializers.CharField()\r\n    thumbnails = serializers.ListField()\r\n\r\n# Example usage\r\nyt = YouTube(\"https://www.youtube.com/watch?v=Wpi1_RsRaAU\")\r\nyt.extract_info()\r\n\r\nserializer = VideoDataSerializer(yt.video_data().to_json(to_dict=True))\r\nprint(serializer.data)\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udcdd License\r\n\r\nMIT License \u00a9 2025\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A simple library for extracting YouTube content using yt-dlp",
    "version": "0.0.0",
    "project_urls": {
        "Homepage": "https://github.com/sachin-acharya-projects/youtube-extractor",
        "Issues": "https://github.com/sachin-acharya-projects/youtube-extractor/issues"
    },
    "split_keywords": [
        "youtube",
        " extract",
        " yt-dlp"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "29cf12f5723e2e0247f9c297bbc45724e8cf2fe15025b5e7c04f5e8d9ea659f4",
                "md5": "00101efe44c18f033b95cd7247564934",
                "sha256": "283c0c0d4a5e8ebd8295c3a3750c4cdbec7e4e7463e3c1fd472d163c84b5fd35"
            },
            "downloads": -1,
            "filename": "tubegrab-0.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "00101efe44c18f033b95cd7247564934",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 12903,
            "upload_time": "2025-09-04T06:29:19",
            "upload_time_iso_8601": "2025-09-04T06:29:19.224548Z",
            "url": "https://files.pythonhosted.org/packages/29/cf/12f5723e2e0247f9c297bbc45724e8cf2fe15025b5e7c04f5e8d9ea659f4/tubegrab-0.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a10fed9e66b643bcba76e7e2c4065923a063166f6ae8f44e4286134b25c7e792",
                "md5": "c072f9a42cb6b23d397177f3e6dac6e8",
                "sha256": "9b6134c65fa6e1deb7e862720839f9b4ae1b93ef70c27756e641a032c8ae1caa"
            },
            "downloads": -1,
            "filename": "tubegrab-0.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c072f9a42cb6b23d397177f3e6dac6e8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 11378,
            "upload_time": "2025-09-04T06:29:20",
            "upload_time_iso_8601": "2025-09-04T06:29:20.741548Z",
            "url": "https://files.pythonhosted.org/packages/a1/0f/ed9e66b643bcba76e7e2c4065923a063166f6ae8f44e4286134b25c7e792/tubegrab-0.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-04 06:29:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sachin-acharya-projects",
    "github_project": "youtube-extractor",
    "github_not_found": true,
    "lcname": "tubegrab"
}
        
Elapsed time: 0.88778s