Skip to main content

ytget

Easily get data and download YouTube videos, focused on speed and simplicity.

Also works as a command-line extractor/downloader.

Installation

You can install ytget using pip:

pip install ytget

Some videos/formats will need ffmpeg to download. You can install it from the official website or by running:

sudo apt install ffmpeg

Features

  • Simple use.
  • Quick download and info extraction of youtube videos and playlists.
  • Quick youtube search.
  • Access to age restricted videos without login.
  • Access to your private videos logging into your account.
  • Command-line support.

Usage

Python

To extract information from a video, create a Video object with the url or query:

from ytget import Video

video = Video("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

# Get info
title = video.title
duration = video.duration
subtitles = video.subtitles
stream_url = video.stream_url
# ...and so on. 
# You can use print(dir(video)) or help(video) to get all available info and parameters.

# Download the video
video.download()

# Change some parameters
video.download(path="downloads/", quality="med", only_audio=True)

You can also search for a query and get the information of all the videos obtained with the Search object:

from ytget import Search, Download
from ytget.utils import formatted_to_seconds

# Get the complete information of all videos
results = Search("never gonna give you up", get_duration_formatted=False).results

# Download all
results.download()

# Or do something with the results before downloading
filtered_results = list(filter(lambda x: x.duration < formatted_to_seconds('3:00'), results))
Download(filtered_results, quality="best", only_video=True, target_fps=30)

# Get simplified information (in case you need speed and don't need to download/get the stream urls)
results = Search("never gonna give you up", get_simple=True).results
for result in results:
    print(result['title'], result['url'])

Get information from a playlist with the Playlist object:

from ytget import Playlist, Fetch, Download

# Get the complete information of all videos
playlist = Playlist("https://www.youtube.com/watch?v=9OFpfTd0EIs&list=PLd9auH4JIHvupoMgW5YfOjqtj6Lih0MKw")

# Download all
playlist.download()

for video in playlist:
    print(video.get('title'), video.get('url'))

# Instead of downloading directly, you can do something with the videos before
videos = list(filter(lambda x: x.title.lower().startswith('a'), playlist.videos))
Download(videos)
        
# If you want to be the most efficient, get only the initial data of each video
videos_info = list(filter(lambda x: x.get('title').lower().startswith('b'), playlist.videos_info))
Download(Fetch(videos_info))

And (as shown in the previous examples) you can also use useful objects like Fetch and Download, and functions like formatted_to_seconds, format_seconds and delete_cache (among others) to make it even easier for you.

You can also use the GenericExtractor to extract info from various sites, though it's recommended to use a dedicated extractor for each website.

Command-line

For more detailed information, use:

ytget --help

Example 1 - Downloading a video and printing its title and url:

ytget https://www.youtube.com/watch?v=dQw4w9WgXcQ --print title url

Example 2 - Searching for a query for videos under 5 minutes long, and without downloading get the data of all the videos and write it to a json file:

ytget "never gonna give you up" --max-duration 5:00 --search --skip-download --print all --write-to-json

Example 3 - Get playlist info (with a maximum of 150 videos) and write to json file their titles, urls and ids:

ytget "https://www.youtube.com/playlist?list=PLd9auH4JIHvupoMgW5YfOjqtj6Lih0MKw" --max-length 150 --print title url video_id --skip-download --write-to-json

To Do

  • Add playlist support.
  • Add channels support.
  • Allow some way to download livestreams (fractions).
  • Allow search for multiple pages.

Known issues

  • Issues related to downloading age restricted videos without logging in.
  • When downloading some specific formats the result might be "corrupted". For now this can be fixed by enabling "force_ffmpeg".

Repository

The source code is available on GitHub.

License

This project is licensed under the MIT License.

Metadata

Release files for ytget 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ytget 0.5.1
File Size Uploaded
ytget-0.5.1.tar.gz 35.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ytget 0.5.1
File Interpreter ABI Platform
ytget-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 70.2 kB

Release files / ytget-0.5.1.tar.gz

Download URL ytget-0.5.1.tar.gz
Size 35.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8289e053cfc716f44be0d82c96b491e5920bf95eaf9a56838438d7fd2cc81e7f
BLAKE2b-256 checksum
How to use checksums
8574ddecc606b38db82652b25092f89d635333b29e91bcbfb9179cc58b512e15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Release files / ytget-0.5.1-py3-none-any.whl

Download URL ytget-0.5.1-py3-none-any.whl
Size 35.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de003bd0196ba6ea296c8f23f3d7ac0e077162b681c9e64304ac1303d093b936
BLAKE2b-256 checksum
How to use checksums
d8de920736fd0ff07ca7aaf8ee23316fe0df8cf6c4d6f256c4183f703539cf02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page