Skip to main content

A lightweight Python library for fetching YouTube videos" metadata.

Project description

Meta-YT


Logo

Rystal V6

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

GitHub Forks GitHub Stars License Github Watchers

Key Features

  • 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.

Installation

Install Meta-YT using pip:

pip install meta-yt

Usage

Here is a quick guide on how to use the library.

Importing Necessary Modules

from meta_yt import YouTube, Video, Caption

Initializing the YouTube Object

You can initialize the YouTube object either with a search query or a video URL.

Using a Search Query

yt = YouTube("cat videos")
print(yt.video.title)

Using a Video URL

yt = YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ", isUrl=True)
print(yt.video.title)

Fetching Captions

You can fetch captions for a video and convert them to SubRip (SRT) format.

captions = yt.video.get_captions(include_generated=True)
for lang, caption in captions.items():
    print(f"Captions in {lang}:")
    for line in caption.transcript:
        print(f"{line['start']} - {line['end']}: {line['text']}")

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.

API Reference

class YouTube

Represents a YouTube video and provides metadata fetching functionality.

__init__(self, query: str, isUrl: bool = None)

Initializes a YouTube object.

Args:

  • query (str): The search query or video URL.
  • isUrl (bool, optional): Whether the query is a URL. Defaults to None.

class Video

Represents a YouTube video and provides methods to fetch metadata and captions.

__init__(self, videoId: str)

Initializes a Video object.

Args:

  • videoId (str): The ID of the YouTube video.

Attributes

  • 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.
  • channel_url: The URL of the video channel.
  • metadata: Additional metadata fetched from the YouTube API.

get_captions(self, include_generated: bool = False) -> dict

Fetches the captions for the video.

Args:

  • include_generated (bool, optional): Whether to include auto-generated captions. Defaults to False.

Returns:

  • dict: A dictionary of Caption objects.

class Caption

Represents captions for a YouTube video.

__init__(self, baseUrl: str, language_code: str)

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.

Attributes

  • 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.

to_srt(self) -> str

Converts the transcript to SubRip (SRT) format.

Returns:

  • str: The transcript in SubRip (SRT) format.

Contributing

We welcome contributions! Please fork the repository and submit pull requests.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meta_yt-0.1.0b0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

meta_yt-0.1.0b0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file meta_yt-0.1.0b0.tar.gz.

File metadata

  • Download URL: meta_yt-0.1.0b0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.0

File hashes

Hashes for meta_yt-0.1.0b0.tar.gz
Algorithm Hash digest
SHA256 de09eadd85f83b6451b89feea2d1931ef5294924c59c3472e28d7fbc79a2080f
MD5 2c099175dd1e6c6887788f6ce6c120ec
BLAKE2b-256 8ba2999ce9cf5853f14e587fa14ca80e5111dee7558a72290c9548a24787e7b8

See more details on using hashes here.

File details

Details for the file meta_yt-0.1.0b0-py3-none-any.whl.

File metadata

  • Download URL: meta_yt-0.1.0b0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.0

File hashes

Hashes for meta_yt-0.1.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc28dbcacf992c46610d485be700c3d587df9715a7424f7d2d3b4bbd4c43d12a
MD5 55d242bb4363f1bb31bbe645664f7cdc
BLAKE2b-256 aba8d8ec4e3b043b71b5d1a2927b6ed44a7ae3aac70bd1e827678d99276976b9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page