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 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

Prequisite

Installation

Either of the following ways will get you ready.

  1. From pypi:

    $ pip install 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

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.

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.0.4.tar.gz (16.2 kB view hashes)

Uploaded Source

Built Distribution

ytube_api-0.0.4-py3-none-any.whl (14.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page