Meta-YT is a lightweight Python library for fetching YouTube video metadata. It allows users to interact with YouTube videos, captions, and playlists, making it easier to retrieve information and captions from YouTube.
Submit Issues · Releases
- Video Metadata: Retrieve detailed metadata for YouTube videos, including title, duration, views, thumbnails, and more.
- Captions: Fetch and process captions (subtitles) for YouTube videos.
- YouTube Search: Perform YouTube searches and fetch metadata for the top results.
Install Meta-YT using pip:
pip install -U meta-ytHere is a quick guide on how to use the library.
from meta_yt import YouTube, Video, CaptionYou can initialize the YouTube object either with a search query or a video URL.
yt = YouTube("cat videos")
print(yt.video.title)yt = YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
print(yt.video.title)You can fetch captions for a video and convert them to SubRip (SRT) format.
captions = yt.video.get_captions(include_generated=True)
for caption in captions:
print(caption.language_code)
print(caption.auto_generated)
print(caption.to_srt())Since this library does not include a function to download or decrypt video streams, you will need to use external libraries such as YTDL or PyTube for those purposes.
Represents a YouTube video and provides metadata fetching functionality.
Initializes a YouTube object.
Args:
query(str): The search query or video URL.
Represents a YouTube video and provides methods to fetch metadata and captions.
Initializes a Video object.
Args:
videoId(str): The ID of the YouTube video.
video_idThe video ID.url: The URL of the YouTube video.title: The title of the video.channel: The channel name of the video.duration: The duration of the video.views: The number of views on the video.thumbnail: The URL of the video thumbnail.thumbnails: A list of all URLs of video thumbnails.channel_url: The URL of the video channel.channel_id: The ID of the video channel.keywords: A list of keywords of the video.metadata: Additional metadata fetched from the YouTube API.
Fetches the captions for the video.
Args:
include_generated(bool, optional): Whether to include auto-generated captions. Defaults toFalse.
Returns:
captions: A list ofCaptionobjects.
Represents captions for a YouTube video.
Initializes a Caption object.
Args:
baseUrl(str): The base URL of the video.language_code(str): The ISO 639-1 language code of the captions.
url: The URL for fetching captions.language_code: The ISO 639-1 language code of the captions.language: The language name of the captions.transcript: A list containing dictionaries representing each line of the transcript.
Converts the transcript to SubRip (SRT) format.
Returns:
str: The transcript in SubRip (SRT) format.
We welcome contributions! Please fork the repository and submit pull requests.
This project is licensed under the MIT License. See the LICENSE file for details.
Copyright © 2024 Rystal. All rights reserved.