Skip to main content

Fast and simple API for YouTube and YouTube Music

Project description

"""

YouTube & YouTube Music API

A powerful, lightweight, and high-performance API for accessing YouTube and YouTube Music content, metadata, and streams. Designed for simplicity and flexibility, this library provides full access to YouTube sources, including videos, playlists, metadata, and more. """

Features

- Fetch videos, playlists, and metadata from YouTube and YouTube Music.

- Retrieve lyrics, related tracks, and detailed metadata.

from typing import Union, List, Dict, Any

Core Functions

async def get_video_id(q: str, is_youtube: bool) -> Union[str, Dict[str, str]]: """ Retrieves the YouTube video ID for a given song or title.

Parameters:
- q (str): The search query (e.g., song name or title).
- is_youtube (bool): If true, searches YouTube; otherwise, searches YouTube Music.

Returns:
- str | Dict: The video ID or an error object.
"""
pass

async def get_youtube_list(id: str) -> Union[Dict[str, Any], Dict[str, str]]: """ Fetches metadata and tracks for a YouTube playlist.

Parameters:
- id (str): The ID of the YouTube playlist.

Returns:
- Dict: Playlist metadata and track list or an error object.
"""
pass

async def get_youtube_music_list(id: str) -> Union[Dict[str, Any], Dict[str, str]]: """ Fetches metadata and tracks for a YouTube Music playlist.

Parameters:
- id (str): The ID of the YouTube Music playlist.

Returns:
- Dict: Playlist metadata and track list or an error object.
"""
pass

async def youtube_music_search(q: str, method: str = 'songs') -> Union[List[Any], Dict[str, str]]: """ Searches YouTube Music for songs, artists, albums, or playlists.

Parameters:
- q (str): The search query.
- method (str): The search category (songs, artists, albums, etc.).

Returns:
- List | Dict: An array of search results or an error object.
"""
pass

async def get_related_and_lyrics(id: str) -> Union[Dict[str, Any], Dict[str, str]]: """ Fetches related tracks, playlist queue, and lyrics for a given video ID.

Parameters:
- id (str): The YouTube video ID.

Returns:
- Dict: Related tracks, playlist queue, and lyrics data or an error object.
"""
pass

async def get_lyrics(id: str) -> Union[str, Dict[str, str]]: """ Fetches lyrics for a specific video ID.

Parameters:
- id (str): The YouTube video ID.

Returns:
- str | Dict: Lyrics or an error object.
"""
pass

async def get_yt_music_related(id: str) -> Union[Any, Dict[str, str]]: """ Fetches related tracks for YouTube Music based on the provided ID.

Parameters:
- id (str): The ID of the track.

Returns:
- Any | Dict: Related track details or an error object.
"""
pass

async def get_artist(id: str) -> Union[Any, Dict[str, str]]: """ Fetches information about an artist.

Parameters:
- id (str): The artist ID.

Returns:
- Any | Dict: Artist details or an error object.
"""
pass

async def get_album(id: str) -> Union[Any, Dict[str, str]]: """ Fetches information about an album.

Parameters:
- id (str): The album ID.

Returns:
- Any | Dict: Album details or an error object.
"""
pass

async def get_track_data(id: str) -> Union[Dict[str, Any], Dict[str, str]]: """ Fetches detailed track data, including artist, album, duration, and poster information.

Parameters:
- id (str): The track ID.

Returns:
- Dict: Track metadata and details or an error object.
"""
pass

async def get_podcast(id: str) -> Union[Any, Dict[str, str]]: """ Fetches details about a podcast.

Parameters:
- id (str): The podcast ID.

Returns:
- Any | Dict: Podcast details or an error object.
"""
pass

CLI Script

import argparse import asyncio from hydra_youtube_api import get_data, filter_formats, get_lyrics

async def main(): parser = argparse.ArgumentParser(description="Fast and simple API for YouTube and YouTube Music.") parser.add_argument("video_id", help="YouTube video ID") parser.add_argument("--formats", action="store_true", help="List available formats") parser.add_argument("--lyrics", action="store_true", help="Fetch lyrics for the video") args = parser.parse_args()

video_id = args.video_id

if args.formats:
    # Fetch and list available formats
    data = await get_data(video_id, client_name="ios")
    formats = filter_formats(data, filter_type="all")
    for fmt in formats:
        print(f"Format: {fmt.get('mimeType')}, Resolution: {fmt.get('width')}x{fmt.get('height')}, Bitrate: {fmt.get('bitrate')}")

if args.lyrics:
    # Fetch and display lyrics
    lyrics = await get_lyrics(video_id)
    if lyrics:
        print("Lyrics:")
        print(lyrics)
    else:
        print("No lyrics found.")

if name == "main": asyncio.run(main())

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

hydra_youtube_api-1.1.4.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hydra_youtube_api-1.1.4-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file hydra_youtube_api-1.1.4.tar.gz.

File metadata

  • Download URL: hydra_youtube_api-1.1.4.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for hydra_youtube_api-1.1.4.tar.gz
Algorithm Hash digest
SHA256 2f0c2c965f900565a70c0e3f036b817a2917ef259202b0d24825bfe032cb3666
MD5 686a5197c186d826e17f25ab5ea44276
BLAKE2b-256 e03d2587c22d3fb3f73ebfeac393de1a213851e77888802ea8685d1d72807bb9

See more details on using hashes here.

File details

Details for the file hydra_youtube_api-1.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for hydra_youtube_api-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1c49c6f47ddd3f4396724a0d705ddad5a1d5a3e0559103f3db700184dc2e05e2
MD5 f0d3deddcb3eafbfe6d19a25c0ac5b4f
BLAKE2b-256 4b1fe15b3893986e6995e62f55874ec1dc94caf2c77ca2ceed762645f42d223c

See more details on using hashes here.

Supported by

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