Skip to main content

pytube

A lightweight, dependency-free Python library for downloading YouTube Videos.

Description

Downloading videos from YouTube shouldn’t require some bloatware application, it’s usually a niche condition you want to do so in the first place. So I present to you, PyTube!

Installation

If you are on Mac OS X or Linux, chances are that one of the following two commands will work for you:

Installation

Using PIP via PyPI

pip install pytube

Using PIP via Github

pip install git+git://github.com/NFicano/pytube.git@0.2.0#egg=pytube

Adding to your requirements.txt file (run pip install -r requirements.txt afterwards)

git+ssh://git@github.com/NFicano/pytube.git@0.2.0#egg=pytube

Manually via GIT

git clone git://github.com/NFicano/pytube.git pytube
cd pytube
python setup.py install

Roadmap

The only features I see implementing in the near future are:

  • refactor console printing into separate command-line utility.

  • Add nosetests

  • Add Sphinx documentation

Usage Example

from pytube import YouTube

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

yt = YouTube()

# Set the video URL.
yt.url = "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.

pprint(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>]

# 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.filename = 'Dancing Scene from Pulp Fiction'

# You can also filter the criteria by filetype.

pprint(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
pprint(yt.filter(res='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:

pprint(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>]

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

video = yt.get('mp4')
# MultipleObjectsReturned: get() returned more than one object -- it returned 2!

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

# Okay, let's download it!
video.download()

# Downloading: Pulp Fiction - Dancing Scene.mp4 Bytes: 37561829
# 37561829  [100.00%]

# Note: If you wanted to choose the output directory, simply pass it as an
# argument to the download method.
video.download('/tmp/')

Background

After missing the deadline to register for PyCon 2012, I decided to write what became PyTube and crawler to collect all the YouTube links for the talks on PyVideos.

To avoid having to encode them to mp4 (so I could watch them on my iPhone) I wrote it so you could specify an encoding format.

In recently weeks interest has picked up in the project, so I decided to dedicate more time to further its development and actively maintain it.

Philosophy

My only real goal for this is to never require any third party dependancies, to keep it simple and make it reliable.

Metadata

Release files for pytube 0.2.0

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

Source distribution (sdist)

Source distribution for pytube 0.2.0
File Size Uploaded
pytube-0.2.0.tar.gz 16.9 kB Details

Release files / pytube-0.2.0.tar.gz

Download URL pytube-0.2.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8ae3ce66d233fb11489e5a25835122c80fdd717b2d3bf11649cfdccc44b31b31
BLAKE2b-256 checksum
How to use checksums
3c1e449480a1766be765d30415ec52474e5830e24d8229506678abea868f3e86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

12.1.3

2 release files

12.1.2

2 release files

12.1.1

2 release files

12.0.0

2 release files

11.0.2

2 release files

11.0.1

2 release files

10.9.3

2 release files

10.8.5

2 release files

10.8.3

2 release files

10.8.2

2 release files

10.7.2

2 release files

10.6.1

2 release files

10.6.0

2 release files

10.5.1

2 release files

10.4.1

2 release files

10.0.0

2 release files

9.7.3

2 release files

9.7.2

2 release files

9.7.0

2 release files

9.6.0

2 release files

9.5.3

2 release files

9.5.2

2 release files

9.5.1

2 release files

9.5.0

2 release files

9.4.0

2 release files

9.3.5

2 release files

9.3.3

2 release files

9.3.2

2 release files

9.3.0

2 release files

9.2.3

2 release files

9.2.2

2 release files

9.2.0

2 release files

9.1.0

2 release files

9.0.6

2 release files

9.0.4

2 release files

9.0.2

2 release files

9.0.0

2 release files

8.0.2

2 release files

8.0.0

2 release files

7.0.18

2 release files

7.0.16

2 release files

7.0.14

2 release files

7.0.12

2 release files

7.0.10

2 release files

7.0.9

2 release files

7.0.8

2 release files

7.0.6

2 release files

7.0.4

2 release files

7.0.2

2 release files

7.0.0

2 release files

6.4.2

2 release files

6.4.0

2 release files

6.3.0

2 release files

6.2.2

2 release files

6.2.1

1 release file

6.1.11

1 release file

6.1.10

1 release file

6.1.8

1 release file

6.1.5

1 release file

6.1.4

1 release file

6.1.3

1 release file

6.1.2

1 release file

6.1.0

1 release file

6.0.2

1 release file

6.0.1

1 release file

6.0.0

1 release file

5.1.0

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.3.3

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.1

1 release file

This release

0.2.0 This release

1 release file

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