Pytube Description and Keyword Not Showing: Solution
Solve the issue with Pytube not showing youtube description and tags in this article.
Here is the article rewritten in an SEO friendly way with subtitles and paragraphs:
Pytube Description and Keyword Not Showing: A Solution
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:
- The video description (
yt.description) was returning None - 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
How to merge JSON files in python
Learn different techniques to merge multiple JSON files in Python using built-in JSON module and Pandas library. Includes examples for combining data arrays and merging dictionaries by key.
How to Fix the subprocess-exited-with-error in Python
Learn what cause the subprocess-exited-with-error in Python and also learn how to solve the error in your code.
Python Integer Division: The Floor Division Operator Explained
Article on Python Integer Division operator (//) with examples and the difference between standard division and floor division.
SyntaxError: Unexpected EOF While Parsing - Python Error Solved
This article explains what causes the common "SyntaxError: unexpected EOF while parsing" error in Python and how to fix it with various examples.
