📅  最后修改于: 2023-12-03 15:33:23.119000             🧑  作者: Mango
Pafy是一个Python库,它提供了从YouTube下载视频和音频的简单而易用的界面。
安装Pafy:
pip install pafy
使用Pafy:
import pafy
# 获取视频信息
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
video = pafy.new(url)
title = video.title
author = video.author
length = video.length
duration = video.duration
likes = video.likes
dislikes = video.dislikes
print("Title:", title)
print("Author:", author)
print("Length:", length)
print("Duration:", duration)
print("Likes:", likes)
print("Dislikes:", dislikes)
# 获取最佳视频流
best = video.getbest()
print("Resolution:", best.resolution)
print("Extension:", best.extension)
print("Size:", best.get_filesize())
# 下载视频流
best.download()
更多用法请参见官方文档。
Pafy是一个非常实用的Python库,能够方便地从YouTube下载视频和音频。它的简单易用的接口和强大的功能使得它成为最受欢迎的Python网络视频下载库之一。