Skip to main content

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

Project description

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

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.

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, without downloading get the data of all the videos and write it to a json file:

ytget "never gonna give you up" --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).
  • Make user input download speed in MB/s and not using chunk size.

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.

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

ytget-0.2.2.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

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

ytget-0.2.2-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file ytget-0.2.2.tar.gz.

File metadata

  • Download URL: ytget-0.2.2.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.0

File hashes

Hashes for ytget-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ed781c22776cc95753c02cf917dde6365f0c62cc13ca6990c818f80f943363ca
MD5 029454bcfbb81b9d12aa65222ba1ce46
BLAKE2b-256 bc1d4ea9fd67629349575014ac09653a1197bf438ede91a32b6882058100fa2f

See more details on using hashes here.

File details

Details for the file ytget-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: ytget-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.0

File hashes

Hashes for ytget-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5ba83ea206a1e56426718db07f20cb0c222d109477f00ca604b92f2c3cbb1933
MD5 df0a5226c532bc8a17bd5d41bd11d711
BLAKE2b-256 b951bfdb0e3038a0237efabebb4201a45144448dfe2174124735cc9d1b03de56

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