📅  最后修改于: 2023-12-03 15:18:59.408000             🧑  作者: Mango
Pytube is a lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos. It was created and is maintained by Nick Ficano.
Pytube can be installed with pip:
pip install pytube
To download a YouTube video with Pytube, simply instantiate the YouTube
class with the video URL and call the streams
attribute. From there, you can choose the stream you want to download and call the download()
method.
from pytube import YouTube
# Instantiate YouTube class with video URL
yt = YouTube('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
# Print all available video streams
print(yt.streams.all())
# Choose the stream you want to download
stream = yt.streams.get_by_itag(22)
# Download the stream
stream.download()
Pytube offers the following features:
Pytube also comes with a command-line utility that can be used for downloading YouTube videos. To download a video simply run:
python -m pytube [url]
For example:
python -m pytube https://www.youtube.com/watch?v=dQw4w9WgXcQ
Pytube does not currently support:
Pytube is a lightweight and easy-to-use Python library for downloading YouTube videos. Its simplicity makes it a great choice for beginners, while its versatility and batch operations make it a solid choice for more experienced programmers.