Skip to main content

A Python library for downloading YouTube videos.

Project description

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sub-license, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice, and every other copyright notice found in this
software, and all the attributions in every file, and this permission notice
shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Description: ======
pytube
======

.. image:: https://img.shields.io/pypi/v/pytube.svg
:alt: Pypi
:target: https://pypi.python.org/pypi/pytube/

.. image:: https://img.shields.io/pypi/pyversions/pytube.svg
:alt: Python Versions
:target: https://pypi.python.org/pypi/pytube/

.. image:: https://travis-ci.org/nficano/pytube.svg?branch=master
:alt: Build status
:target: https://travis-ci.org/nficano/pytube

.. image:: https://coveralls.io/repos/nficano/pytube/badge.svg?branch=master&service=github
:alt: Coverage
:target: https://coveralls.io/github/nficano/pytube?branch=master

*pytube* is a lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.

Description
===========

YouTube is the most popular video-sharing platform in the world and as a hacker you may encounter a situation where you want to script something to download videos. For this I present to you *pytube*.

*pytube* is a lightweight library written in Python. It has no third party dependencies and aims to be highly reliable.

*pytube* makes *zero assumptions*, meaning there is no built-in method to get say the *"best"* quality video, *pytube* simply exposes all the available formats and resolutions, giving you the developer the power to define what *"best"* is.

*pytube* also makes pipelining easy, allowing you to specify callback functions for different download events, such as ``on progress`` or ``on complete``.

Finally *pytube* also includes a command-line utility, allowing you to quickly download videos right from terminal.

Installation
============

Download using pip via pypi.

.. code:: bash

pip install pytube


Library usage
=============

.. code:: python

from pytube import YouTube

# not necessary, just for demo purposes.
from pprint import pprint

yt = YouTube("http://www.youtube.com/watch?v=Ik-RsDGPI5Y")

# Once set, you can see all the codec and quality options YouTube has made
# available for the perticular video by printing videos.

print(yt.get_videos())

# [<Video: MPEG-4 Visual (.3gp) - 144p>,
# <Video: MPEG-4 Visual (.3gp) - 240p>,
# <Video: Sorenson H.263 (.flv) - 240p>,
# <Video: H.264 (.flv) - 360p>,
# <Video: H.264 (.flv) - 480p>,
# <Video: H.264 (.mp4) - 360p>,
# <Video: H.264 (.mp4) - 720p>,
# <Video: VP8 (.webm) - 360p>,
# <Video: VP8 (.webm) - 480p>]

# The filename is automatically generated based on the video title. You
# can override this by manually setting the filename.

# view the auto generated filename:
print(yt.filename)

# Pulp Fiction - Dancing Scene [HD]

# set the filename:
yt.set_filename('Dancing Scene from Pulp Fiction')

# You can also filter the criteria by filetype.
print(yt.filter('flv'))

# [<Video: Sorenson H.263 (.flv) - 240p>,
# <Video: H.264 (.flv) - 360p>,
# <Video: H.264 (.flv) - 480p>]

# Notice that the list is ordered by lowest resolution to highest. If you
# wanted the highest resolution available for a specific file type, you
# can simply do:
print(yt.filter('mp4')[-1])
# <Video: H.264 (.mp4) - 720p>

# You can also get all videos for a given resolution
print(yt.filter(resolution='480p'))

# [<Video: H.264 (.flv) - 480p>,
# <Video: VP8 (.webm) - 480p>]

# To select a video by a specific resolution and filetype you can use the get
# method.

video = yt.get('mp4', '720p')

# NOTE: get() can only be used if and only if one object matches your criteria.
# for example:

print(yt.videos)

#[<Video: MPEG-4 Visual (.3gp) - 144p>,
# <Video: MPEG-4 Visual (.3gp) - 240p>,
# <Video: Sorenson H.263 (.flv) - 240p>,
# <Video: H.264 (.flv) - 360p>,
# <Video: H.264 (.flv) - 480p>,
# <Video: H.264 (.mp4) - 360p>,
# <Video: H.264 (.mp4) - 720p>,
# <Video: VP8 (.webm) - 360p>,
# <Video: VP8 (.webm) - 480p>]

# Since we have two H.264 (.mp4) available to us... now if we try to call get()
# on mp4...

video = yt.get('mp4')
# MultipleObjectsReturned: 2 videos met criteria.

# In this case, we'll need to specify both the codec (mp4) and resolution
# (either 360p or 720p).

# Okay, let's download it! (a destination directory is required)
video.download('/tmp/')

Command-line usage
==================

You can download a video by simply passing the ``-e`` (or ``--extension=``) switch and
setting it to the desired filetype:

.. code:: bash

$ pytube -e mp4 http://www.youtube.com/watch?v=Ik-RsDGPI5Y


Same thing for specifying a resolution:

.. code:: bash

$ pytube -r 720p http://www.youtube.com/watch?v=Ik-RsDGPI5Y


You can also specify a download file path (``-p`` or ``--path=``):

.. code:: bash

$ pytube -e mp4 -p ~/Downloads/ http://www.youtube.com/watch?v=Ik-RsDGPI5Y

and/or optionally choose the filename (``-f`` or ``--filename=``):

.. code:: bash

$ pytube -e mp4 -f "Dancing Scene from Pulp Fiction" http://www.youtube.com/watch?v=Ik-RsDGPI5Y

You can also specify a resolution or desired filetype:

.. code:: bash

$ pytube -e mp4 -r 720p http://www.youtube.com/watch?v=Ik-RsDGPI5Y

Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft
Classifier: Operating System :: POSIX
Classifier: Operating System :: Unix
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python
Classifier: Topic :: Internet
Classifier: Topic :: Multimedia :: Video
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Terminals
Classifier: Topic :: Utilities

Project details


Release history Release notifications | RSS feed

This version

6.2.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytube-6.2.2.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

pytube-6.2.2-py2-none-any.whl (20.7 kB view details)

Uploaded Python 2

File details

Details for the file pytube-6.2.2.tar.gz.

File metadata

  • Download URL: pytube-6.2.2.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pytube-6.2.2.tar.gz
Algorithm Hash digest
SHA256 da123064c74cd6861f4f406e6a56ba842268e54a5c9997a3542e01bb2162da92
MD5 534b3b6541d82f74f04592107cb0da88
BLAKE2b-256 66f7ed0d730f13da146e986fac37dff6e3241482368d63cf5d8116c7936d957d

See more details on using hashes here.

File details

Details for the file pytube-6.2.2-py2-none-any.whl.

File metadata

File hashes

Hashes for pytube-6.2.2-py2-none-any.whl
Algorithm Hash digest
SHA256 92824a729ed75d226d1f013e2b3d22973340521873cc825f103cf61a3345504a
MD5 00f473eddef5da4a1b56786bc1b1bb4c
BLAKE2b-256 26480054cefcefa8b1c0997c024ddb6b356f2b8953be49a34a585d7caf033bc1

See more details on using hashes here.

Supported by

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