Skip to main content

YouTube.py is a light python module for youtube.

Project description

banner

rtd license size ver lang status ver

YouTube Python

Youtube Python is best and powerful python module for developers internal use APIs or command line CLI , Downloading specific video or playlist if now easy.

Install

Python module

run this command on terminal.

$ pip install youtube.py

Have multipls versions of python?

$ python3.x -m pip install youtube.py

Install FFMPEG

Windows download link. After download the exe file make sure to put that on environment variables or simply move ffmpeg.exe to c:\windows\system32\

For Linux

$ sudo apt update
$ sudo apt install ffmpeg

Features

  • Supports proxy (for scraping data, proxy will not be used for downloading videos)
  • Rate limit bypass
  • Light module
  • Command line input available
  • Supports FFMPEG
  • Can parsec youtube video details

Basic

from youtube import Video

video_url = "https://www.youtube.com/watch?v=3AtDnEC4zak"

v = Video(video_url)

#Print Title
print(v.title)

#Print Author name
print(v.author)

#Print Channel ID
print(v.channel)

#Print video description
print(v.description)

#Print video length in second
print(v.length)

#Print video keywords in dict
print(v.keywords)

#Print high resolution thumbnail
print(v.thumbnail)

#Print video id
print(v.videoId)

#Print total video views
print(v.views)

Working with streams

>>> from youtube import Video
>>> v = Video("https://www.youtube.com/watch?v=3AtDnEC4zak")
>>> v.title
"Charlie Puth - We Don't Talk Anymore (feat. Selena Gomez) [Official Video]"
>>> v.length
231
>>> v.views
2550001850
>>> v.streams
[<Class Stream: itag="18" qualityLabel="360p" fps="24" mime="video/mp4" type="both" format="mp4" codecs="avc1.42001E,+mp4a.40.2">, 
<Class Stream: itag="133" qualityLabel="240p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="avc1.4d4015">, 
<Class Stream: itag="134" qualityLabel="360p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="avc1.4d401e">, 
<Class Stream: itag="135" qualityLabel="480p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="avc1.4d401e">, 
<Class Stream: itag="136" qualityLabel="720p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="avc1.4d401f">, 
<Class Stream: itag="137" qualityLabel="1080p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="avc1.640028">, 
<Class Stream: itag="160" qualityLabel="144p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="avc1.4d400c">, 
<Class Stream: itag="242" qualityLabel="240p" fps="24" mime="video/webm" type="video" format="webm" codecs="vp9">, 
<Class Stream: itag="243" qualityLabel="360p" fps="24" mime="video/webm" type="video" format="webm" codecs="vp9">, 
<Class Stream: itag="244" qualityLabel="480p" fps="24" mime="video/webm" type="video" format="webm" codecs="vp9">, 
<Class Stream: itag="247" qualityLabel="720p" fps="24" mime="video/webm" type="video" format="webm" codecs="vp9">, 
<Class Stream: itag="248" qualityLabel="1080p" fps="24" mime="video/webm" type="video" format="webm" codecs="vp9">, 
<Class Stream: itag="249" bitrate="59056" mime="audio/webm" type="audio" format="webm" codecs="opus">, 
<Class Stream: itag="250" bitrate="76035" mime="audio/webm" type="audio" format="webm" codecs="opus">, 
<Class Stream: itag="251" bitrate="143852" mime="audio/webm" type="audio" format="webm" codecs="opus">, 
<Class Stream: itag="278" qualityLabel="144p" fps="24" mime="video/webm" type="video" format="webm" codecs="vp9">, 
<Class Stream: itag="394" qualityLabel="144p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="av01.0.00M.08">, 
<Class Stream: itag="395" qualityLabel="240p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="av01.0.00M.08">, 
<Class Stream: itag="396" qualityLabel="360p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="av01.0.01M.08">, 
<Class Stream: itag="397" qualityLabel="480p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="av01.0.04M.08">, 
<Class Stream: itag="398" qualityLabel="720p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="av01.0.05M.08">, 
<Class Stream: itag="399" qualityLabel="1080p" fps="24" mime="video/mp4" type="video" format="mp4" codecs="av01.0.08M.08">]
>>> type(v.streams)
<class 'youtube.Stream.Queue'>
>>> v.thumbnail
'https://i.ytimg.com/vi/3AtDnEC4zak/maxresdefault.jpg'
>>> v.get_dict
[{'itag': 18, 'mimeType': 'video/mp4', 'bitrate': 395026, 'width': 640, 'height': 360, 'lastModified': '1580859977121104', 'contentLength': '11378647', 'quality': 'medium', 'fps': 24, 'qualityLabel': '360p', 'projectionType': 'RECTANGULAR', 'averageBitrate': 394913, 'audioQuality': 'AUDIO_QUALITY_LOW', 'approxDurationMs': '230504', 'audioSampleRate': '44100', 'audioChannels': 2, 'type': 'both', 'format': 'mp4', 'codecs': 'avc1.42001E,+mp4a.40.2', 's': 'mAq0QJ8wRQIgRe0DKBgGi4uiqHOk6dmrhwQKtFCcrhCKAvNHps-hzk0CIQDDW_HSmfLlD3-4G5x3XtamqDtAWRVkjYYGv_qFYUY4Ow====', 'sp': 'sig', 'url': 'https://r7---sn-ci5gup-civl.googlevideo.com/videoplayback?expire=1606933954&ei=YonHX_XTBIKqvQSXv4-QDg ...........

Command Line Input

usage: youtube [-h] [-o OUTPUT] [-l] [-ff [FFMPEG] | -v [VIDEO] | -i ITAG | -s
               | -a [AUDIO] | -r [RESOLUTION] | --version]
               url

Definitions:
  Quality Types: ('HIGH','MID', 'LOW')
  Video resolution examples. ('144', '240', '360', '480', '720', '1080') more/less depend on your video

Note:
  Default values for '--ffmpeg', '--video', '--audio' is 'HIGH'
  Default values for '--resolution' is 720

positional arguments:
  url                   Enter video or playlist url

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Output location for downloading streams.
  -l, --logs            To enable extra logs.
  -ff [FFMPEG], --ffmpeg [FFMPEG]
                        FFMPEG downloads audio/video both then copy in one file, Pass the quality type.
  -v [VIDEO], --video [VIDEO]
                        Downlaod video (only progressive), Pass quality.
  -i ITAG, --itag ITAG  Download stream with itag, Pass itag id.
  -s, --streams         This argument will list the all available streams.
  -a [AUDIO], --audio [AUDIO]
                        Download audio, Pass quality.
  -r [RESOLUTION], --resolution [RESOLUTION]
                        Download stream with quality type, Pass video resolution.
  --version             Check the current version of youtube.py

Sample Codes

Here are some sample codes.

How to download mass videos with ffmpeg.

from youtube import Video

video_url = ["3AtDnEC4zak", "3AtDnEC4zak"]

for vdo in video_url:
        v = Video(f"https://youtu.be/{vdo}").streams
        v.ffhigh.download() # ffhigh will download stream with highest quality

How to download all playlist videos concurrently/fast.

from youtube import PlayList
import concurrent.futures


MAX_CONCURRENT_DOWNLOADS = 1 #max concurrent download at ones

video_url = "https://www.youtube.com/playlist?list=PLeXILI4F6_4XJau4ZlJXD7-K75g6rDebr"

p = PlayList(video_url, process=True) # process=True to generate all Video objects

func = lambda x: x.streams.get_audios.low().download()

with  concurrent.futures.ThreadPoolExecutor(max_workers=MAX_CONCURRENT_DOWNLOADS) as executor:
        for n in executor.map(func,p.get_object):
                print(f'{n} Downloaded')

Contributing

You just simple fork the project from github and fix the bugs and push with full explanation of bug and fix.

We do love when you invest your time and contribute us for making us more better/stable.

Your each bug report on github or contribute is much appreciated

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

youtube.py-1.0.5.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

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

youtube.py-1.0.5-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file youtube.py-1.0.5.tar.gz.

File metadata

  • Download URL: youtube.py-1.0.5.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.9

File hashes

Hashes for youtube.py-1.0.5.tar.gz
Algorithm Hash digest
SHA256 9ff1c95b4009f28194138644536b2bde59f4dab8ed9d363619526f8b764e1df8
MD5 0186ed518f18a273248a535691d1d576
BLAKE2b-256 5e6d1f3df7d5db548076c81d7b69999d3cae7d2375937447bedb55c1704c5759

See more details on using hashes here.

File details

Details for the file youtube.py-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: youtube.py-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 31.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.9

File hashes

Hashes for youtube.py-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a57ecc7e818c258c6f0fad4a0af003cf87b07945317ce1e23cf53963dc18fe45
MD5 80979dfac17f416a8c297cfaf448ffa2
BLAKE2b-256 82ab74034f0537f8c335c6af04b3a8e8293ed45586319bf24a304eb7481ad89c

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