Pytube Description and Keyword Not Showing: Solution


In this article we will see how to fix the issue with description and keyword not showing in Pytube Python Library.

Issues with Pytube After YouTube API Changes

With the recent changes made to the YouTube API, some of the core features of the Pytube Python library have stopped working properly.

This was the code for my project.

from pytube import YouTube  

video_url = 'https://www.youtube.com/watch?v=zmTPjiuA2KI'  

yt = YouTube(video_url) 

#Run this code before fetching desc and keywords
stream = yt.streams.first()  

tags = yt.keywords  
thumbnail = yt.thumbnail_url  
desc = yt.description  

print("Tags:", tags)  
print("Thumbnail:", thumbnail)  
print("Description:", desc)

The two main issues I faced while using Pytube were:

  1. The video description (yt.description) was returning None
  2. The video keywords (yt.keywords) was returning an empty list

Need for YouTube API Key

The new YouTube API requires an API key to extract information like the tags and description of a video. You need to make a simple GET request to the API endpoint along with the API key to get this data.

Workaround Without Needing an API Key

However, if you want Pytube to work without needing an API key, there is a workaround I found while searching for a solution.

Solution Provided on GitHub

One solution that worked for me was given by the user dimays on the Pytube GitHub issue page.

The solution is to run yt.streams.first() before fetching the keywords and description. This will fix the issue of the description and keywords returning empty data.

Updated Pytube Code

Here is the updated version of the Pytube code which worked for me:

from pytube import YouTube

video_url = 'https://www.youtube.com/watch?v=zmTPjiuA2KI'

yt = YouTube(video_url)

#Run this code before fetching desc and keywords
stream = yt.streams.first()

tags = yt.keywords  
thumbnail = yt.thumbnail_url
desc = yt.description

print("Tags:", tags)  
print("Thumbnail:", thumbnail) 
print("Description:", desc)

Conclusion

By running yt.streams.first() before fetching the description and keywords, you can get all the video information from YouTube using Pytube without needing an API key. This simple workaround fixed the issues I was having and allowed me to access the metadata.

Scroll to Top