Skip to main content

ytube-api

Python version Python Test License PyPi Downloads

Download YouTube videos in mp4 or mp3 formats.

from ytube_api import Auto
Auto(
  query = "Alan Walker - Alone"
)
# Alan Walker - Alone - Alan Walker (720p, h264, youtube).mp4
# > Downloaded 15.68 MB ############ ~ Elapsed (00:00:32) [■■■█■]
# ## Saved to : /home/smartwa/y2mate/Alan Walker - Alone - Alan Walker (720p, h264, youtube).mp4
from ytube_api import Auto
Auto(
  query = "Alan Walker - Alone",
  format = "mp3"
)
# Alan Walker - Alone - Alan Walker (youtube).mp3
# > Downloaded 2.61 MB ############ ~ Elapsed (00:00:06) [■█■■■]
# ## Saved to : /home/smartwa/y2mate/Alan Walker - Alone - Alan Walker (youtube).mp3

Pre-requisite

Installation

Either of the following ways will get you ready.

  1. From pypi:

    $ pip install -U "ytube-api[cli]"
    
  2. From source:

    $ pip install git+http://github.com/Simatwa/ytube-api.git
    

Alternatively, you can download standalone executable for your system from here.

Usage

1. Developers

Search videos

By Title

from ytube_api import Ytube
yt = Ytube()
videos = yt.search_videos(
   "Alan Walker songs"
)
print(videos)
"""
SearchResults(query='Alan Walker songs', items=[SearchResultsItem(title='Alan Walker, Putri Ariani, Peder Elias - Who I Am (Official Music Video)', id='ccu6JuC21rk', size='2.91 MB', duration='3:32', channelTitle='Alan Walker', source='yt'), SearchResultsItem(title='Alan Walker - Faded', id='60ItHLz5WEA', size='2.93 MB', duration='3:33', channelTitle='Alan Walker', source='yt')], from_link=False)
"""

By Video URL

from ytube_api import Ytube
yt = Ytube()
videos = yt.search_videos(
   "https://youtu.be/oociIYNVdVQ?si=v1Ic_mcBq2bb_j8J"
)
print(videos)
"""
SearchResults(query='https://youtu.be/oociIYNVdVQ?si=v1Ic_mcBq2bb_j8J', items=[SearchResultsItem(title=None, id='oociIYNVdVQ', size=None, duration=None, channelTitle=None, source=None)], from_link=True)
"""

Video

from ytube_api import Ytube
yt = Ytube()
search_results = yt.search_videos(
   "Alan Walker songs"
)
target_video = search_results.items[0]
download_link = yt.get_download_link(
   target_video,
   format="mp4",
   quality="1080"
   )
print(
   download_link
)
"""
DownloadLink(status='tunnel', url='https://vgbh.nmnm.store/tunnel?id=svqwnZ5CJOJJZi12yXq0b&exp=1729856312453&sig=kcY69-AGCv--0t5cY0RZ93lyyI_rDDe88iGQo_fpJTc&sec=rrJnEyYU9sETaZG8kEbobbhGGfae7rU0SQNCkBidT90&iv=t9YVnta7aLw0qEh5GJW8Lg', filename='Alan Walker, Putri Ariani, Peder Elias - Who I Am (Official Music Video) - Alan Walker (1080p, h264, youtube).mp4')
"""

Audio

from ytube_api import Ytube
yt = Ytube()
search_results = yt.search_videos(
   "Alan Walker songs"
)
target_video = search_results.items[0]
download_link = yt.get_download_link(
   target_video,
   format="mp3",
   quality="320"
   )
print(
   download_link
)
"""
DownloadLink(status='tunnel', url='https://xdcf.nmnm.store/tunnel?id=5K8ZukESJDx0ov3liUj_N&exp=1729856389952&sig=D9ejkqecxpkBsxcXmBtIrYXo1BMIFyawLoBC1_X3J3Q&sec=L5EpDuWoxXk6dK2pLqK9jYyqNF0X06_YKtb9gLB6SVs&iv=YGnrLa_v5qh9uVQSe1x_Og', filename='Alan Walker, Putri Ariani, Peder Elias - Who I Am (Official Music Video) - Alan Walker (youtube).mp3')
"""

Download

from ytube_api import Ytube
yt = Ytube()
search_results = yt.search_videos(
   "Alan Walker songs"
)
target_video = search_results.items[0]
download_link = yt.get_download_link(
   target_video,
   format="mp3",
   quality="320"
   )
saved_to = yt.download(
   download_link,
   progress_bar=True,
   quiet=False
)
print(saved_to)
"""
/home/smartwa/git/smartwa/ytube-api/Alan Walker, Putri Ariani, Peder Elias - Who I Am (Official Music Video) - Alan Walker (youtube).mp3
"""

Query suggestions

from ytube_api import Ytube
yt = Ytube()

suggestions = yt.suggest_queries(
    'Hello wor'
)

print(
    suggestions
)

"""
['hello world', 'hello world song', 'hello world bump of chicken', 'hello world gwen stefani', 'hello worker', 'hello world louie zong', 'hello world in assembly language', 'hello world in different languages', 'hello world trailer', 'hello world english cover', 'hello world belle perez', 'hello world anime', 'hello world kekkai sensen', 'hello world lost game']
"""

2. CLI

$ python -m ytube_api --help

Usage: ytube [OPTIONS] COMMAND [ARGS]...

  Download YouTube videos in mp4 and mp3 formats

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  download     Search and download video in mp4 or mp3 formats
  interactive  Search and download videos/audio interactively
  suggest      Suggest videos based on your query

Download

$ ytube download <QUERY>
# e.g ytube download "Alan walker songs"

$ ytube download --help

Usage: ytube download [OPTIONS] QUERY

Search and download video in mp4 or mp3 formats

Options:
-q, --quality [128|320|144|240|360|480|720|1080|128|720]
                               Media download quality - 128|720
--mp4 / --mp3                   Download audio (mp3) or video (mp4) -
                               mp4
--enable-progressbar / --disable-progressbar
                               Show or hide progressbar
-l, --limit INTEGER             Total number of items to be downloaded
                               that matched the search - 1
-t, --timeout INTEGER           Http request timeout - 20
-c, --channels Name             Download videos posted by this channel
                               titles - None.
-d, --dir DIRECTORY             Directory for saving the contents to -
                               pwd.
-o, --output TEXT               Filename to save the contents under -
                               None
-b, --busy-bar INTEGER RANGE    Busy bar index - ['', '/','■█■■■',
                               '⡿'] - 2  [0<=x<=3]
--quiet                         Do not stdout informative messages
--resume                        Resume incomplete download
--confirm                       Ask user for permission to download a
                               video/audio
--help                          Show this message and exit.

Interactive

  • Features live search 🔴 etc.
Welcome to interactive ytube. Type 'help' or 'h' for usage info.
Submit any bug at https://github.com/Simatwa/ytube/issues/new
╭─[Smartwa@YTUBE]~[🕒18:07:27-💻00:00:00-⚡0.0s] 
╰─>Alan Walker
               alan walker                 
               alan walker faded           
               alan walker on my way live  
               alan walker sad sometimes   
               alan walker spectre         
               alan walker alone           
               alan walker mix             

ytube interactive --help
Usage: ytube interactive [OPTIONS] [QUERY]

  Search and download videos/audio interactively

Options:
  -q, --quality [128|320|144|240|360|480|720|1080|128|720|128|720]
                                  Media download quality - 128|720
  --mp4 / --mp3                   Download audio (mp3) or video (mp4) -
                                  mp4
  -s, --suggestions-limit INTEGER
                                  Query suggestions limit - 10
  -l, --limit INTEGER             Total number of items to be downloaded
                                  that matched the search - 1
  -t, --timeout INTEGER           Http request timeout - 20
  -b, --busy-bar INTEGER RANGE    Busy bar index - ['', '/','■█■■■',
                                  '⡿'] - 2  [0<=x<=3]
  -d, --dir DIRECTORY             Directory for saving the contents to -
                                  pwd.
  --disable-coloring              Stdout interactive texts in white font
                                  color
  --select                        Prompt user download format and
                                  quality every time.
  --confirm                       Ask user for permission to download a
                                  video/audio
  --play                          Play the video/audio after completing
                                  download process
  --help                          Show this message and exit.

Disclaimer

This software is not affiliated with or endorsed by y2mate.tube or its parent company. By using this tool, you assume all risks associated with using this unofficial tool.It is your responsibility to ensure compliance with all relevant laws and regulations when using this tool. This software is provided "as-is" without warranty of any kind, express or implied.

Metadata

Release files for ytube-api 0.1.3

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

Source distribution (sdist)

Source distribution for ytube-api 0.1.3
File Size Uploaded
ytube_api-0.1.3.tar.gz 22.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ytube-api 0.1.3
File Interpreter ABI Platform
ytube_api-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 43.5 kB

Release files / ytube_api-0.1.3.tar.gz

Download URL ytube_api-0.1.3.tar.gz
Size 22.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8e331f7bab288649e33f236ca571e71793af71d484ec2e73daa2d081b76369b0
BLAKE2b-256 checksum
How to use checksums
af7a4ab0d179f0ef62266316ca7877d7bdfd5a4d37c11b03c430ee95a4fe8c2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ytube_api-0.1.3-py3-none-any.whl

Download URL ytube_api-0.1.3-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
972fadaccf305cb67b0eb68c28693abab4434d9e341eb76a4f95ef49d60f5127
BLAKE2b-256 checksum
How to use checksums
a2ed1b49f326b0524578471ed03d457dfa2e262d8c50a3372590ee25e437b398
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

1 release file

0.1.0

1 release file

0.0.9

2 release files

0.0.8

2 release files

0.0.7.1

1 release file

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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