Search code examples
pythonpython-3.7pytubekali-linux

How to download a youtube video through pytube python module


Here is the code:

>>> from pytube import YouTube
>>> v=YouTube('https://www.youtube.com/watch?v=Wl2OyaZVU3U')
>>> v.title
'Maroon 5 - Memories (Lyrics)'
>>> v.streams
<pytube.query.StreamQuery object at 0x7f76859e3a20>
>>> v.download()
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    v.download()
AttributeError: 'YouTube' object has no attribute 'download'

How can I solve this problem?


Solution

  • There is an exemple on the library documentation where it uses the streams member of the object in order to download.

    In your code that would be :

    >>> v.streams.first().download()
    

    See also the API doc.