YTMusicAPI PHP

Unofficial YouTube Music API for PHP

A PHP library that allows you to interact with YouTube Music programmatically. Search for music, manage playlists, access your library, and much more.

<?php
require "vendor/autoload.php";

$yt = new Ytmusicapi\YTMusic();

// Search for music
$results = $yt->search("Oasis Wonderwall");
$videoId = $results[0]->videoId;

// Get song information
$song = $yt->get_song_info($videoId);

print_r($song);

Features

🔍

Search & Browse

Search for songs, albums, artists, playlists, and podcasts. Browse YouTube Music content programmatically.

📚

Library Management

Access and manage your personal library, liked songs, playlists, and upload content.

🎵

Playlist Control

Create, edit, and delete playlists. Add or remove songs with full programmatic control.

📊

Charts & Trends

Get access to music charts, trending content, and mood-based playlists from around the world.

🎧

Podcast Support

Browse podcasts, get episode information, and manage podcast subscriptions.

🔐

Multiple Auth Methods

Support for browser headers, cookies, and OAuth authentication for secure access.

Based on Python YTMusicAPI

This library is a faithful PHP port of the popular Python ytmusicapi library. We maintain compatibility with function names, parameter names, and API behavior to make migration easy for developers familiar with the Python version.

Same function names and parameters
Compatible with YtMusicAPI v1.11.0
PHP-specific enhancements included

Quick Start

1

Install via Composer

composer require ytmusicapi/ytmusicapi
2

Basic Usage

<?php
require "vendor/autoload.php";

$yt = new Ytmusicapi\YTMusic();
$song = $yt->get_song('kJQP7kiw5Fk');
3

With Authentication

Load YouTube Music in your browser, go to developer tools, and copy the request headers for any request to a browse or next endpoint. Then create a browser.json file with the headers.

// Setup authentication
php vendor/bin/setup-ytmusicapi browser

// Use authenticated client
$yt = new Ytmusicapi\YTMusic("browser.json");

⚠️ Important Notice

Google has taken a harder stance against bots. Endpoints that may have previously worked while not authenticated may now respond with an error. This seems especially true if you are running the software on common hosting providers such as AWS, Netlify, Vercel, Digital Ocean, or Linode.

Note: This PHP port is currently behind the Python version in updates. If you can choose either Python or PHP, consider using the Python version.