pytubefix


Namepytubefix JSON
Version 8.12.0 PyPI version JSON
download
home_pageNone
SummaryPython3 library for downloading YouTube Videos.
upload_time2025-01-14 02:19:31
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT license
keywords youtube download video stream
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pytubefix

[![PyPI - Downloads](https://img.shields.io/pypi/dm/pytubefix)](https://pypi.org/project/pytubefix/)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/juanbindez)](https://github.com/sponsors/juanbindez)
[![PyPI - License](https://img.shields.io/pypi/l/pytubefix)](https://opensource.org/licenses/MIT)
[![Read the Docs](https://img.shields.io/readthedocs/pytubefix)](https://pytubefix.readthedocs.io/)
[![GitHub Tag](https://img.shields.io/github/v/tag/JuanBindez/pytubefix?include_prereleases)](https://github.com/JuanBindez/pytubefix/releases)
[![PyPI - Version](https://img.shields.io/pypi/v/pytubefix)](https://pypi.org/project/pytubefix/)

## Python3 Library for Downloading YouTube Videos

---

## Installation

```bash
pip install pytubefix
```

---

## Quickstart

### Download MP4 Video in Highest Resolution:

```python
from pytubefix import YouTube
from pytubefix.cli import on_progress

url = "url"

yt = YouTube(url, on_progress_callback=on_progress)
print(yt.title)

ys = yt.streams.get_highest_resolution()
ys.download()
```

### Download Audio-Only (.m4a):

```python
from pytubefix import YouTube
from pytubefix.cli import on_progress

url = "url"

yt = YouTube(url, on_progress_callback=on_progress)
print(yt.title)

ys = yt.streams.get_audio_only()
ys.download()
```

### Download a Complete Playlist:

```python
from pytubefix import Playlist
from pytubefix.cli import on_progress

url = "url"

pl = Playlist(url)
for video in pl.videos:
    ys = video.streams.get_audio_only()
    ys.download()
```

### Use OAuth Authentication:

```python
from pytubefix import YouTube
from pytubefix.cli import on_progress

url = "url"

yt = YouTube(url, use_oauth=True, allow_oauth_cache=True, on_progress_callback=on_progress)
ys = yt.streams.get_highest_resolution()
ys.download()  # Authenticate once for subsequent downloads
```

### Specify Output Directory for Downloads:

```python
from pytubefix import YouTube
from pytubefix.cli import on_progress

url = "url"

yt = YouTube(url, on_progress_callback=on_progress)
ys = yt.streams.get_highest_resolution()
ys.download(output_path="path/to/directory")
```

---

## Working with Subtitles/Caption Tracks

### View Available Subtitles:

```python
from pytubefix import YouTube

yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')
print(yt.captions)
```

### Print Subtitle Tracks:

```python
from pytubefix import YouTube

yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')
caption = yt.captions['a.en']
print(caption.generate_srt_captions())
```

### Save Subtitles to a Text File:

```python
from pytubefix import YouTube

yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')
caption = yt.captions['a.en']
caption.save_captions("captions.txt")
```

---

## Using Channels

### Get Channel Name:

```python
from pytubefix import Channel

c = Channel("https://www.youtube.com/@ProgrammingKnowledge/featured")
print(f'Channel name: {c.channel_name}')
```

### Download All Videos from a Channel:

```python
from pytubefix import Channel

c = Channel("https://www.youtube.com/@ProgrammingKnowledge")
print(f'Downloading videos by: {c.channel_name}')

for video in c.videos:
    video.streams.get_highest_resolution().download()
```

---

## Search for Videos

### Basic Search:

```python
from pytubefix import Search

results = Search('GitHub Issue Best Practices')
for video in results.videos:
    print(f'Title: {video.title}')
    print(f'URL: {video.watch_url}')
    print(f'Duration: {video.length} sec')
    print('---')
```

### Use Filters:

```python
from pytubefix.contrib.search import Search, Filter

filters = {
    'upload_date': Filter.get_upload_date('Today'),
    'type': Filter.get_type("Video"),
    'duration': Filter.get_duration("Under 4 minutes"),
    'features': [Filter.get_features("4K"), Filter.get_features("Creative Commons")],
    'sort_by': Filter.get_sort_by("Upload date")
}

s = Search('music', filters=filters)
for video in s.videos:
    print(video.watch_url)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytubefix",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "youtube, download, video, stream",
    "author": null,
    "author_email": "Juan Bindez <juanbindez780@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/61/fe/8d8e1426ebd070ee35184a887ff7a600d5435ab2353844d228f6d901a32d/pytubefix-8.12.0.tar.gz",
    "platform": null,
    "description": "# Pytubefix\n\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/pytubefix)](https://pypi.org/project/pytubefix/)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/juanbindez)](https://github.com/sponsors/juanbindez)\n[![PyPI - License](https://img.shields.io/pypi/l/pytubefix)](https://opensource.org/licenses/MIT)\n[![Read the Docs](https://img.shields.io/readthedocs/pytubefix)](https://pytubefix.readthedocs.io/)\n[![GitHub Tag](https://img.shields.io/github/v/tag/JuanBindez/pytubefix?include_prereleases)](https://github.com/JuanBindez/pytubefix/releases)\n[![PyPI - Version](https://img.shields.io/pypi/v/pytubefix)](https://pypi.org/project/pytubefix/)\n\n## Python3 Library for Downloading YouTube Videos\n\n---\n\n## Installation\n\n```bash\npip install pytubefix\n```\n\n---\n\n## Quickstart\n\n### Download MP4 Video in Highest Resolution:\n\n```python\nfrom pytubefix import YouTube\nfrom pytubefix.cli import on_progress\n\nurl = \"url\"\n\nyt = YouTube(url, on_progress_callback=on_progress)\nprint(yt.title)\n\nys = yt.streams.get_highest_resolution()\nys.download()\n```\n\n### Download Audio-Only (.m4a):\n\n```python\nfrom pytubefix import YouTube\nfrom pytubefix.cli import on_progress\n\nurl = \"url\"\n\nyt = YouTube(url, on_progress_callback=on_progress)\nprint(yt.title)\n\nys = yt.streams.get_audio_only()\nys.download()\n```\n\n### Download a Complete Playlist:\n\n```python\nfrom pytubefix import Playlist\nfrom pytubefix.cli import on_progress\n\nurl = \"url\"\n\npl = Playlist(url)\nfor video in pl.videos:\n    ys = video.streams.get_audio_only()\n    ys.download()\n```\n\n### Use OAuth Authentication:\n\n```python\nfrom pytubefix import YouTube\nfrom pytubefix.cli import on_progress\n\nurl = \"url\"\n\nyt = YouTube(url, use_oauth=True, allow_oauth_cache=True, on_progress_callback=on_progress)\nys = yt.streams.get_highest_resolution()\nys.download()  # Authenticate once for subsequent downloads\n```\n\n### Specify Output Directory for Downloads:\n\n```python\nfrom pytubefix import YouTube\nfrom pytubefix.cli import on_progress\n\nurl = \"url\"\n\nyt = YouTube(url, on_progress_callback=on_progress)\nys = yt.streams.get_highest_resolution()\nys.download(output_path=\"path/to/directory\")\n```\n\n---\n\n## Working with Subtitles/Caption Tracks\n\n### View Available Subtitles:\n\n```python\nfrom pytubefix import YouTube\n\nyt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')\nprint(yt.captions)\n```\n\n### Print Subtitle Tracks:\n\n```python\nfrom pytubefix import YouTube\n\nyt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')\ncaption = yt.captions['a.en']\nprint(caption.generate_srt_captions())\n```\n\n### Save Subtitles to a Text File:\n\n```python\nfrom pytubefix import YouTube\n\nyt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')\ncaption = yt.captions['a.en']\ncaption.save_captions(\"captions.txt\")\n```\n\n---\n\n## Using Channels\n\n### Get Channel Name:\n\n```python\nfrom pytubefix import Channel\n\nc = Channel(\"https://www.youtube.com/@ProgrammingKnowledge/featured\")\nprint(f'Channel name: {c.channel_name}')\n```\n\n### Download All Videos from a Channel:\n\n```python\nfrom pytubefix import Channel\n\nc = Channel(\"https://www.youtube.com/@ProgrammingKnowledge\")\nprint(f'Downloading videos by: {c.channel_name}')\n\nfor video in c.videos:\n    video.streams.get_highest_resolution().download()\n```\n\n---\n\n## Search for Videos\n\n### Basic Search:\n\n```python\nfrom pytubefix import Search\n\nresults = Search('GitHub Issue Best Practices')\nfor video in results.videos:\n    print(f'Title: {video.title}')\n    print(f'URL: {video.watch_url}')\n    print(f'Duration: {video.length} sec')\n    print('---')\n```\n\n### Use Filters:\n\n```python\nfrom pytubefix.contrib.search import Search, Filter\n\nfilters = {\n    'upload_date': Filter.get_upload_date('Today'),\n    'type': Filter.get_type(\"Video\"),\n    'duration': Filter.get_duration(\"Under 4 minutes\"),\n    'features': [Filter.get_features(\"4K\"), Filter.get_features(\"Creative Commons\")],\n    'sort_by': Filter.get_sort_by(\"Upload date\")\n}\n\ns = Search('music', filters=filters)\nfor video in s.videos:\n    print(video.watch_url)\n```\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Python3 library for downloading YouTube Videos.",
    "version": "8.12.0",
    "project_urls": {
        "Bug Reports": "https://github.com/juanbindez/pytubefix/issues",
        "Homepage": "https://github.com/juanbindez/pytubefix",
        "Read the Docs": "http://pytubefix.readthedocs.io/"
    },
    "split_keywords": [
        "youtube",
        " download",
        " video",
        " stream"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "039be12bc6bad2ced372932446c5a78e6e81497324d51a6cc62fafe626f0df18",
                "md5": "400d88de983937cc2399d22915cb5274",
                "sha256": "560b0f17b5a5b86fa9a542b02049eaa06492f2f6f66b787244333673387343eb"
            },
            "downloads": -1,
            "filename": "pytubefix-8.12.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "400d88de983937cc2399d22915cb5274",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 730557,
            "upload_time": "2025-01-14T02:19:29",
            "upload_time_iso_8601": "2025-01-14T02:19:29.261870Z",
            "url": "https://files.pythonhosted.org/packages/03/9b/e12bc6bad2ced372932446c5a78e6e81497324d51a6cc62fafe626f0df18/pytubefix-8.12.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61fe8d8e1426ebd070ee35184a887ff7a600d5435ab2353844d228f6d901a32d",
                "md5": "061d4d677d719d2b49ddfd98a0010f5c",
                "sha256": "8a2b51a06efbec926ad88d2d686b6a66c7da37edf406eab7347d4ee43b638a4b"
            },
            "downloads": -1,
            "filename": "pytubefix-8.12.0.tar.gz",
            "has_sig": false,
            "md5_digest": "061d4d677d719d2b49ddfd98a0010f5c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 732987,
            "upload_time": "2025-01-14T02:19:31",
            "upload_time_iso_8601": "2025-01-14T02:19:31.606020Z",
            "url": "https://files.pythonhosted.org/packages/61/fe/8d8e1426ebd070ee35184a887ff7a600d5435ab2353844d228f6d901a32d/pytubefix-8.12.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-14 02:19:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "juanbindez",
    "github_project": "pytubefix",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pytubefix"
}
        
Elapsed time: 0.45022s