https://github.com/juanbindez/pytubefix
Python3 library for downloading YouTube Videos.
https://github.com/juanbindez/pytubefix
pytube pytubefix youtube-downloader
Last synced: 5 months ago
JSON representation
Python3 library for downloading YouTube Videos.
- Host: GitHub
- URL: https://github.com/juanbindez/pytubefix
- Owner: JuanBindez
- License: mit
- Created: 2023-09-21T15:04:09.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-08T12:22:43.000Z (5 months ago)
- Last Synced: 2025-05-08T18:49:15.645Z (5 months ago)
- Topics: pytube, pytubefix, youtube-downloader
- Language: Python
- Homepage: https://pytubefix.readthedocs.io
- Size: 8.55 MB
- Stars: 1,143
- Watchers: 16
- Forks: 142
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
- Contributing: Contributing.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Pytubefix
[](https://pypi.org/project/pytubefix/)
[](https://github.com/sponsors/juanbindez)
[](https://opensource.org/licenses/MIT)
[](https://pytubefix.readthedocs.io/)
[](https://github.com/JuanBindez/pytubefix/releases)
[](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_progressurl = "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_progressurl = "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_progressurl = "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_progressurl = "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_progressurl = "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 YouTubeyt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')
print(yt.captions)
```### Print Subtitle Tracks:
```python
from pytubefix import YouTubeyt = 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 YouTubeyt = 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 Channelc = Channel("https://www.youtube.com/@ProgrammingKnowledge/featured")
print(f'Channel name: {c.channel_name}')
```### Download All Videos from a Channel:
```python
from pytubefix import Channelc = 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 Searchresults = 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, Filterfilters = {
'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)
```