Skip to main content

Unofficial wrapper for y2mate.tube

Project description

ytube-api

Python version Python Test License PyPi Latest release release date Black Python-publish 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)
"""

Get Download Link

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

[!NOTE] Shorthand for python -m pytube_api is pytube.

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.

[!NOTE] Interactive is the default option incase no command/argument is supplied. $ ytube is enough to kickoff.

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.

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

ytube_api-0.1.2.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

ytube_api-0.1.2-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file ytube_api-0.1.2.tar.gz.

File metadata

  • Download URL: ytube_api-0.1.2.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for ytube_api-0.1.2.tar.gz
Algorithm Hash digest
SHA256 34f4dfb9af4e71e9359c56239d4ba6031db8129b5a96f9acaa55351b491954d8
MD5 d57d79af854c3391d461f5a7413138c0
BLAKE2b-256 912e47fbc7bb3c2f421df8fe4f93fbfd83f42b770e01d45f0aaa79a1eabe0eeb

See more details on using hashes here.

File details

Details for the file ytube_api-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ytube_api-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for ytube_api-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f778abecc2a4f00c5fe0361f70272021ad5944fa6acd80afbdee931d64ab6798
MD5 c304bac60148012a700247931c5d4fbd
BLAKE2b-256 0f3ea36b79d1dcccf70f4a56c6f78e5f668a9a28312882f4e9e725cd5c9a3920

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