Type System Overview
YTMusicAPI PHP uses docblock-typed objects to document the data returned from the YouTube Music API. These types are defined as PHP classes with documented properties using PHPDoc annotations. Most objects returned are actually stdclass objects retrieved directly from YouTube's data, but the docblock annotations allow your intellisense to provide you with the correct properties.
Core Types
These are the fundamental types used throughout the library.
SearchResult
Represents a single search result item. The type of content depends on the resultType property.
Properties
Category of search result: "Top results", "Songs", "Videos", "Albums", "Artists", "Playlists", etc.
Type of result: "album", "artist", "playlist", "song", "video", "station", "profile", "podcast", "episode"
Title of the search result (not valid for artist results)
Artists (valid for songs, videos, and albums)
Browse ID for detailed information
Video ID (for songs and videos)
Duration in MM:SS format
Thumbnail images
$results = $yt->search("Oasis Wonderwall");
foreach ($results as $result) {
if ($result->resultType === "song") {
echo "Song: " . $result->title . "\n";
echo "Video ID: " . $result->videoId . "\n";
}
}
Song
Complete song information including streaming data and metadata.
Properties
Playability information and status
Streaming URLs and formats
Video metadata (title, author, duration, etc.)
Additional metadata and tags
$song = $yt->get_song("kJQP7kiw5Fk");
echo "Title: " . $song->videoDetails->title . "\n";
echo "Playable: " . ($song->playabilityStatus->status === "OK" ? "Yes" : "No") . "\n";
Track
Simplified track information used in playlists and library results.
Properties
Track title
Video ID
Track artists
Album reference
Duration in MM:SS format
Whether track is in your library
Whether track has explicit content
Search Types
Types specifically related to search functionality.
TrackArtist
Artist information in track contexts.
Properties
Artist name
Artist channel ID
foreach ($track->artists as $artist) {
echo "Artist: " . $artist->name . " (ID: " . $artist->id . ")\n";
}
Content Types
Types for different kinds of content (albums, artists, playlists).
Playlist
Complete playlist information including tracks and metadata.
Properties
Playlist ID
Playlist title
Playlist description
Privacy status: "PUBLIC", "PRIVATE", or "UNLISTED"
Number of tracks in playlist
Total duration
Playlist author
Array of tracks in the playlist
Continuation token for loading more tracks
$playlist = $yt->get_playlist("PLfY7JYgRs-QJZP7zqsKPFMqKJ5qghLqm_");
echo "Playlist: " . $playlist->title . "\n";
echo "Tracks: " . $playlist->trackCount . "\n";
echo "Duration: " . $playlist->duration . "\n";
Artist
Complete artist information including songs, albums, and related content.
Properties
Artist name
Artist channel ID
Artist description
Subscriber count
Whether you're subscribed to this artist
Artist's popular songs
Artist's albums
Artist's singles
Album
Album information including tracks and metadata.
Properties
Album title
Album type: "Album", "Single", "EP"
Primary artist
Release year
Number of tracks
Total duration
Album tracks
Library Types
Types for user library content and account information.
Account
User account information. (PHP-specific type)
Properties
Account name
Account channel ID
Whether account has YouTube Music Premium
Profile pictures
$account = $yt->get_account();
if ($account->is_premium) {
echo "Premium user: " . $account->name . "\n";
}
SongInfo
Basic song information with music detection. (PHP-specific type)
Properties
Whether this is actual music (not just a video)
Video ID
Track title
Track author
Whether track can be embedded
Media Types
Types for media content and streaming information.
Episode
Podcast episode information.
Properties
Episode title
Podcast/channel information
Publication date
Episode duration
Episode playlist ID
Episode description
$episode = $yt->get_episode("nDnLSYCOg7E");
echo "Episode: " . $episode->title . "\n";
echo "Podcast: " . $episode->author->name . "\n";
WatchList
Watch playlist for continuous playback.
Properties
List of tracks for playback
Watch playlist ID
Lyrics browse ID (if available)
Related content browse ID
Common Properties
Properties and types that appear across multiple objects.
Thumbnail
Image thumbnail information.
Properties
Thumbnail URL
Image width in pixels
Image height in pixels
foreach ($artist->thumbnails as $thumbnail) {
echo "Thumbnail: " . $thumbnail->width . "x" . $thumbnail->height . "\n";
echo "URL: " . $thumbnail->url . "\n";
}
Ref
Reference object containing ID and name for linked content.
Properties
Display name
ID for browsing (browseId or channelId)
// Used for artists, albums, authors, etc.
echo "Album: " . $track->album->name . "\n";
$album_details = $yt->get_album($track->album->id);
FeedbackTokens
Tokens for adding/removing items from library.
Properties
Token for adding to library
Token for removing from library
Type Usage Patterns
<?php
// Most API methods return strongly-typed objects
$results = $yt->search("Radiohead"); // Returns SearchResult[]
$playlist = $yt->get_playlist("PLxyz"); // Returns Playlist
$artist = $yt->get_artist("UCxyz"); // Returns Artist
// Access properties with IDE autocomplete support
echo $playlist->title; // string
echo $playlist->trackCount; // int
echo $playlist->tracks[0]->title; // string
// Check types at runtime if needed
if ($result->resultType === "song") {
// $result has song-specific properties
echo "Duration: " . $result->duration . "\n";
}
// Many objects contain references to related content
$track = $playlist->tracks[0];
if ($track->album) {
$album_details = $yt->get_album($track->album->id);
}
Complete Type List
The library includes these type definitions:
Type | Purpose | Used By |
---|---|---|
Account | User account information | get_account() |
SearchResult | Search result item | search() |
Song | Complete song data | get_song() |
SongInfo | Basic song information | get_song_info() |
Track | Track in playlist/library | Playlist tracks, library songs |
WatchTrack | Track with playback information | get_track() |
Playlist | Playlist information | get_playlist() |
Artist | Artist information | get_artist() |
Album | Album information | get_album() |
Episode | Podcast episode | get_episode() |
Podcast | Podcast information | get_podcast() |
UploadTrack | Uploaded track | Upload methods |
WatchList | Watch playlist | get_watch_playlist() |
Thumbnail | Image information | All content types |
Ref | Reference with ID and name | Artists, albums, authors |