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?
UPDATE:
The feature is now added. You can now use the below mentioned feature without downloading the repository.
Old answer:
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
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.
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.
For a good workaround, see landogardner's answer.