Pytube Description and Keyword Not Showing: Solution

featured Image


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.

Related Posts

merge json files in python

How to merge JSON files in python

JSON (JavaScript Object Notation) is a data format used for storing, transferring, and visualizing data. Its simple structure of key:value pairs and array data types makes JSON an easy and…

Read more
Install python pip in ubuntu

How to Install Pip(pip3) in Ubuntu Linux 22.04

Pip is a package manager for Python that allows you to install and manage additional Python packages that are not part of the Python standard library. Pip makes it easy…

Read more
featured Image

How to Write If-Else Statements in One Line in Python

If-else statements are a fundamental concept in Python and other programming languages. They allow you to execute different blocks of code based on whether a condition is true or false….

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *