Last modified: Feb 05, 2026 By Alexander Williams

Extract YouTube Metadata with Python

YouTube is a vast library of video content. Each video has valuable information attached to it. This is called metadata.

Metadata includes the title, description, view count, and more. Extracting this data can be useful for many projects.

You might want to analyze trends or build a content database. Python makes this task simple and efficient.

What is YouTube Video Metadata?

Metadata is data about data. For a YouTube video, it describes the video's properties.

This information helps users and search engines understand the content. It is crucial for video discovery and organization.

Common metadata fields include:

  • Title: The name of the video.
  • Description: A text summary of the video content.
  • View Count: How many times the video has been watched.
  • Publish Date: When the video was uploaded.
  • Channel Name: The uploader's channel.
  • Duration: The length of the video.

Extracting this data programmatically unlocks many possibilities.

Why Use Python for Metadata Extraction?

Python is a popular programming language. It is known for its simplicity and powerful libraries.

It has excellent tools for web scraping and data extraction. These tools can interact with YouTube's data.

Using Python automates the collection process. This saves a huge amount of time and effort.

You can gather data from hundreds of videos quickly. This data can then be analyzed or stored in a database.

Key Python Libraries for the Job

You don't need to build everything from scratch. The Python community has created great libraries.

Two of the most popular are pytube and youtube-dl (via its Python wrapper).

pytube is a lightweight, dependency-free library. It is great for downloading videos and getting basic metadata.

youtube-dl is a powerful command-line tool. Its Python wrapper gives you access to extensive metadata.

We will explore examples using both.

Method 1: Using the Pytube Library

First, you need to install the library. Use the package manager pip.


pip install pytube

Now, let's write a simple script. We will extract metadata from a specific YouTube video URL.

The core function is YouTube(). You pass the video URL to it.


from pytube import YouTube

# Define the YouTube video URL
video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

# Create a YouTube object
yt = YouTube(video_url)

# Extract and print metadata
print(f"Video Title: {yt.title}")
print(f"Video Description: {yt.description[:100]}...")  # First 100 chars
print(f"Number of Views: {yt.views}")
print(f"Video Length: {yt.length} seconds")
print(f"Author/Channel: {yt.author}")
print(f"Publish Date: {yt.publish_date}")
print(f"Video Rating: {yt.rating}")

When you run this script, you will get output similar to this:


Video Title: Rick Astley - Never Gonna Give You Up (Official Music Video)
Video Description: The official video for “Never Gonna Give You Up” by Rick Astley...
Number of Views: 1400000000
Video Length: 212 seconds
Author/Channel: RickAstleyVEVO
Publish Date: 2009-10-25 00:00:00
Video Rating: 4.9

This method is straightforward. It gives you quick access to the most common metadata fields.

Method 2: Using the Youtube-dl Python Wrapper

The youtube-dl library offers more detailed information. First, install it.


pip install youtube-dl

Now, let's use its Python wrapper. We will import the YoutubeDL class.

The key method here is extract_info(). It returns a dictionary full of metadata.


import youtube_dl

# Define the YouTube video URL
video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

# Set options (we are not downloading, just extracting info)
ydl_opts = {
    'quiet': True,
    'no_warnings': True,
}

# Create a YoutubeDL object and extract info
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    info_dict = ydl.extract_info(video_url, download=False)

    # Print selected metadata from the large dictionary
    print(f"Title: {info_dict.get('title')}")
    print(f"Uploader: {info_dict.get('uploader')}")
    print(f"View Count: {info_dict.get('view_count')}")
    print(f"Like Count: {info_dict.get('like_count')}")
    print(f"Dislike Count: {info_dict.get('dislike_count')}")
    print(f"Duration: {info_dict.get('duration')} sec")
    print(f"Upload Date: {info_dict.get('upload_date')}")
    print(f"Categories: {info_dict.get('categories')}")
    print(f"Tags: {info_dict.get('tags')}")
    print(f"Thumbnail URL: {info_dict.get('thumbnail')}")

The output will be much more detailed. It includes data not available through pytube.


Title: Rick Astley - Never Gonna Give You Up (Official Music Video)
Uploader: RickAstleyVEVO
View Count: 1400000000
Like Count: 9000000
Dislike Count: 200000
Duration: 212 sec
Upload Date: 20091025
Categories: ['Music']
Tags: ['Rick', 'Astley', 'Never', 'Gonna', 'Give', 'You', 'Up', 'Official', 'Music', 'Video']
Thumbnail URL: https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg

This method is more powerful. It is the best choice for comprehensive data extraction.

Handling Errors and Limitations

Web scraping can sometimes fail. Videos can be private, deleted, or age-restricted.

Your code should handle these cases gracefully. Use try-except blocks in Python.

Also, YouTube's structure can change. This might break your extraction code.

Make sure to keep your libraries updated. The maintainers fix these issues.

Always respect YouTube's Terms of Service. Do not overload their servers with requests.

Practical Applications of Extracted Metadata

What can you do with this data? The applications are vast.

You can perform content analysis. Find common keywords in titles of popular videos.

Build a recommendation system. Suggest videos based on similar tags or categories.

Create a video analytics dashboard. Track view counts and engagement over time.

You can also use it for SEO research. See what titles and descriptions work best in your niche.

The data is a goldmine for creators, marketers, and researchers.

Conclusion

Extracting YouTube metadata with Python is a valuable skill. It opens doors to data analysis and automation.

We covered two main methods. The pytube library is simple and fast.

The youtube-dl wrapper provides deep, extensive data. Choose based on your