Search code examples
pythonyoutubepytube

Pytube3 - YouTube.title is returning 'YouTube' instead of the expected title


when I try to download a video its titled as 'YouTube' why? and how do I fix it?.

import pytube
  
yt = pytube.YouTube('https://www.youtube.com/watch?v=cKQLKf3dS1Y')
vid = yt.streams.first()

# returns 'YouTube'
print(vid.title)

print('downloading..')

# the title of the video is 'YouTube'
vid.download(r'C:\Users\sruls\OneDrive\Desktop\yt-dl')

print('download complete')

Solution

  • The vid.download() has a second parameter which you can make the name of the video.

    vid.download(r'C:\Users\sruls\OneDrive\Desktop', vid.title) # the first parameter is the directory(the folder)