PHPackages                             ytmusicapi/ytmusicapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ytmusicapi/ytmusicapi

ActiveLibrary[API Development](/categories/api)

ytmusicapi/ytmusicapi
=====================

Unofficial API for YouTube Music

v1.11.1(8mo ago)147724MITPHPPHP &gt;=7.4CI passing

Since Jun 24Pushed 8mo ago4 watchersCompare

[ Source](https://github.com/theyak/ytmusicapi-php)[ Packagist](https://packagist.org/packages/ytmusicapi/ytmusicapi)[ RSS](/packages/ytmusicapi-ytmusicapi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (4)Used By (0)

ytmusicapi-php
==============

[](#ytmusicapi-php)

Please see  for latest documentation. Note that the documentation is a work in progress.

WARNING

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

About
-----

[](#about)

This is a port of the [ytmusicapi](https://github.com/sigma67/ytmusicapi)package available for Python. It tries to stay as close to the original as possible. All API function names, parameter names, and public methods have been kept the same as in their original Python library. Keeping everything the same should make it easy to reference their [documentation](https://ytmusicapi.readthedocs.io/en/stable/index.html). This package is currently feature compatable with YtMusicAPI v1.11.0.

Requirements
------------

[](#requirements)

This package was developed and tested in PHP 8.2 and the testing library requires 8.1+ so I have not tested in anything lower than PHP 8.2. That being said, I have tried to keep the code compatible with PHP 7.4+.

This package uses the [requests](https://requests.ryanmccue.info/)package for communication with YouTube Music.

Known Differences From Python Version
-------------------------------------

[](#known-differences-from-python-version)

- The option to open the web browser from the command line is not available in OAuth setup.
- No support for locales or languages.
- You can pass a cookie string from your browser as the `$auth` parameter in the YTMusic constructor in the PHP version.
- Addition of get\_account() function to get information about the authorized account. This was developed before the Python version's get\_account\_info() function.
- Addition of get\_playlist\_continuation() which allows pagniated results of tracks. Useful when wanting to provide a progress indicator while loading a playlist.
- Addition of get\_song\_info() to get basic information about a track, include if the track is a music video or not.
- Addition of get\_track() to get regular track information about a track. This function is useful to get track information in the form of a Track type with the addition of IDs to get lyrics and related tracks.
- There are various minor differences throughout. They have been labeled in the code with "Known differences" or "Custom"

Installation
------------

[](#installation)

```
composer require ytmusicapi/ytmusicapi

```

Examples
--------

[](#examples)

```
// Fetch information about a song

require "vendor/autoload.php";

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

```
// Display tracks from liked music list, displaying a progress indicator.
// Since the liked music playlist is private, you need to be authenticated.
// This example requires PHP 8.0+ due to usage of named parameters.

$yt = new Ytmusicapi\YTMusic("oauth.json");

try {
    $playlist = $yt->get_playlist("LM", get_continuations: false);
    $tracks = $playlist->tracks;

    // This is the number of tracks YouTube says is in the playlist.
    // However, hidden or deleted tracks may make your actual
    // count a bit lower.
    $count = $playlist->track_count;

    while ($playlist->continuation) {
        echo "Loaded " . count($tracks) . " of approximately $count tracks\n";

        $playlist = $yt->get_playlist_continuation("LM", $playlist->continuation);

        $tracks = array_merge($tracks, $playlist->tracks);
    }
    echo "Loaded " . count($tracks) . PHP_EOL;

    foreach ($tracks as $track) {
        $artists = array_map(fn ($artist) => $artist->name, $track->artists);
        echo $track->title . " - " . implode(", ", $artists) . PHP_EOL;
    }
} catch (Exception $ex) {
    echo $ex->getMessage() . PHP_EOL;
}
```

Testing
-------

[](#testing)

To run tests:

1. Clone the repository
2. Setup browser authentication with `php src/setup_ytmusicapi browser`
3. Run `vendor/bin/pest -v`

You can run a single test file with `vendor/bin/pest -v tests/Features/testfile.php`

You can skip tests by adding `->skip()` to the end of a test function.

You can specify limited tests by adding `->only()` to the end of test functions.

### Code

[](#code)

If you look at the code, you will notice docblocks are generally used to define parameter and return types. This allows greater flexibility in types and documenting what the parameters are for. It also prevents ugly run-time wrong parameter type errors which can kill your entire application - PHP is very good at converting types on the fly, so this is usually OK. When it's not OK, you'll usually receive another type of error, such as unable to convert object to string.

### Credits

[](#credits)

This library is based almost 100% on sigma67's ytmusicapi library for python. . And when I say almost entirely, I mean it. Same function names, same parameter names, same variable names, same logic except where PHP neccessitates different logic.

OpenAI's GPT-4 and GitHub CoPilot helped a lot in converting code from Python to PHP. It's not perfect, but it certainly made things easier and faster. It wasn't very good at writing tests.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance59

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~218 days

Total

3

Last Release

258d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/92d387165b1228b0ffd35816ae741f1f26890ee5cf3603c400f066505d32532a?d=identicon)[theyak](/maintainers/theyak)

---

Top Contributors

[![theyak](https://avatars.githubusercontent.com/u/211792?v=4)](https://github.com/theyak "theyak (43 commits)")

---

Tags

phpyoutubemusicytmusicapiyoutube music

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/ytmusicapi-ytmusicapi/health.svg)

```
[![Health](https://phpackages.com/badges/ytmusicapi-ytmusicapi/health.svg)](https://phpackages.com/packages/ytmusicapi-ytmusicapi)
```

###  Alternatives

[razorpay/razorpay

Razorpay PHP Client Library

2024.8M44](/packages/razorpay-razorpay)[culqi/culqi-php

Cliente Culqi API para PHP

41356.8k1](/packages/culqi-culqi-php)[socialapis/youtubedownloader

A small project for fetching youtube vidoes with their private api.

241.4k](/packages/socialapis-youtubedownloader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
