Python下载具有特定文件名的youtube [英] Python download youtube with specific filename

查看:39
本文介绍了Python下载具有特定文件名的youtube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以这种方式使用 pytube 下载 youtube 视频:

I'm trying to download youtube videos with pytube this way:

from pytube import YouTube
YouTube('http://youtube.com/watch?v=9bZkp7q19f0').streams.first().download()

但文件将与原始视频名称相同.如何指定自定义文件名?

but the file will have the same name as the original video name. How do I specify a custom filename?

推荐答案

更新:

现在添加了该功能.您现在可以在不下载存储库的情况下使用下面提到的功能.

The feature is now added. You can now use the below mentioned feature without downloading the repository.

旧答案:

这在当前最新的 (v7.0.18) 版本中是不可能的.该功能已添加,但此后没有发布新版本.如果你想拥有这个功能,你需要下载pytube仓库:https://github.com/NFicano/pytube

This is not possible in the current latest (v7.0.18) release. The feature has been added, but no new release has been released since then. If you want to have this feature, you need to download the pytube repository: https://github.com/NFicano/pytube

如果您这样做了,您可以使用 YouTube('http://youtube.com/watch?v=9bZkp7q19f0').streams.first().download(filename='filename')

If you have done so, you can use YouTube('http://youtube.com/watch?v=9bZkp7q19f0').streams.first().download(filename='filename')

它会自动添加文件扩展名,因此您不必包含它.

It will automatically add the filename extension, so you don't have to include that.

我是通过阅读源代码找到的.在那里,我在文件 streams.py 中找到了函数 download 的声明:

I found it by reading the source. There, I found the declaration of the function download in the file streams.py:

def download(self, output_path=None, filename=None):

所以你显然也可以指定一个路径.

So you can obviously also specify a path.

要获得好的解决方法,请参阅landogardner 的回答.

For a good workaround, see landogardner's answer.

这篇关于Python下载具有特定文件名的youtube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆