Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/faraasaaay/innertube-v2/llms.txt

Use this file to discover all available pages before exploring further.

Overview

YTItem is a sealed class that acts as the common supertype for every piece of content returned by the InnerTube API. Whenever a method returns a mixed list of content — such as search results or artist sections — it returns List<YTItem>, and you use a when expression to handle each concrete type.
sealed class YTItem {
    abstract val id: String
    abstract val title: String
    abstract val thumbnail: String?
    abstract val explicit: Boolean
    abstract val shareLink: String
}
There are four concrete subtypes:
SubtypeRepresents
SongItemAn individual track (audio or music video)
AlbumItemAn album or EP (links to a browse page and a playlist)
PlaylistItemA user playlist or auto-generated playlist (radio, mix)
ArtistItemA YouTube Music artist channel

Shared Fields

All four subtypes inherit these abstract members from YTItem:
FieldTypeDescription
idStringPrimary identifier. Meaning varies by subtype (see below).
titleStringDisplay name of the item.
thumbnailString?URL of the best-available thumbnail image.
explicitBooleantrue if the content carries an explicit label.
shareLinkStringA shareable music.youtube.com URL computed for each subtype.

SongItem

Represents a single track — either a pure audio track (MUSIC_VIDEO_TYPE_ATV) or a music video.
data class SongItem(
    override val id: String,            // videoId (e.g. "dQw4w9WgXcQ")
    override val title: String,
    val artists: List<Artist>,
    val album: Album? = null,
    val duration: Int? = null,          // seconds
    val musicVideoType: String? = null,
    val chartPosition: Int? = null,
    val chartChange: String? = null,
    override val thumbnail: String,
    override val explicit: Boolean = false,
    val endpoint: WatchEndpoint? = null,
    val setVideoId: String? = null,
    val libraryAddToken: String? = null,
    val libraryRemoveToken: String? = null,
    val historyRemoveToken: String? = null,
    val viewCountText: String? = null,
) : YTItem()
FieldTypeDescription
idStringThe YouTube video ID.
artistsList<Artist>One or more artists. Each has name: String and optional id: String.
albumAlbum?Associated album (name and id). Null for standalone videos.
durationInt?Track length in seconds.
musicVideoTypeString?Internal type string from YouTube (e.g., MUSIC_VIDEO_TYPE_ATV).
endpointWatchEndpoint?Watch endpoint for initiating playback.
setVideoIdString?Required when removing a song from a specific playlist position.
libraryAddTokenString?Feedback token to add this song to the library.
libraryRemoveTokenString?Feedback token to remove this song from the library.
historyRemoveTokenString?Feedback token to remove this song from history.
viewCountTextString?Localised view count string (e.g., "1.2B views").
shareLinkStringhttps://music.youtube.com/watch?v={id}
Computed property:
val isVideoSong: Boolean
    get() = musicVideoType != null && musicVideoType != MUSIC_VIDEO_TYPE_ATV
isVideoSong is true when the track is a music video rather than a pure audio track. Use this to separate songs from videos in search results.

AlbumItem

Represents an album or EP browse page.
data class AlbumItem(
    val browseId: String,               // e.g. "MPREb_..."
    val playlistId: String,             // e.g. "OLAK5uy_..."
    override val id: String = browseId, // aliases browseId
    override val title: String,
    val artists: List<Artist>?,
    val year: Int? = null,
    override val thumbnail: String,
    override val explicit: Boolean = false,
    val description: String? = null,
) : YTItem()
FieldTypeDescription
browseIdStringBrowse ID used with YouTube.album(browseId).
playlistIdStringPlaylist ID used with YouTube.albumSongs(playlistId).
idStringAliases browseId.
artistsList<Artist>?List of album artists. May be null for compilations.
yearInt?Release year.
descriptionString?Album description text.
shareLinkStringhttps://music.youtube.com/playlist?list={playlistId}

PlaylistItem

Represents a user-created or auto-generated playlist.
data class PlaylistItem(
    override val id: String,
    override val title: String,
    val author: Artist?,
    val songCountText: String?,
    override val thumbnail: String?,
    val playEndpoint: WatchEndpoint?,
    val shuffleEndpoint: WatchEndpoint?,
    val radioEndpoint: WatchEndpoint?,
    val isEditable: Boolean = false,
    val description: String? = null,
) : YTItem()
FieldTypeDescription
idStringPlaylist ID (e.g., PLxxxx).
authorArtist?Playlist creator.
songCountTextString?Localised count string (e.g., "42 songs").
playEndpointWatchEndpoint?Endpoint to start playing the playlist.
shuffleEndpointWatchEndpoint?Endpoint to start a shuffle of the playlist.
radioEndpointWatchEndpoint?Endpoint to start a radio based on the playlist.
isEditableBooleantrue if the signed-in user can edit this playlist.
descriptionString?Playlist description.
explicitBooleanAlways false for playlists.
shareLinkStringhttps://music.youtube.com/playlist?list={id}

ArtistItem

Represents a YouTube Music artist channel.
data class ArtistItem(
    override val id: String,
    override val title: String,
    override val thumbnail: String?,
    val channelId: String? = null,
    val playEndpoint: WatchEndpoint? = null,
    val shuffleEndpoint: WatchEndpoint?,
    val radioEndpoint: WatchEndpoint?,
    val subtext: String? = null,
) : YTItem()
FieldTypeDescription
idStringThe artist browse ID (e.g., UCxxxxxx).
channelIdString?The underlying YouTube channel ID for subscriptions.
playEndpointWatchEndpoint?Endpoint to start playing a top track.
shuffleEndpointWatchEndpoint?Endpoint to shuffle the artist’s songs.
radioEndpointWatchEndpoint?Endpoint to start an artist radio.
subtextString?Subscriber count or other secondary text.
explicitBooleanAlways false for artists.
shareLinkStringhttps://music.youtube.com/channel/{id}

Helper Data Classes

Two small data classes are used as nested structures across subtypes:
data class Artist(
    val name: String,
    val id: String?,   // null when the artist has no browse page
)

data class Album(
    val name: String,
    val id: String,    // browseId of the album
)

Handling All Four Subtypes

Use a when expression to exhaustively dispatch on YTItem. Because YTItem is sealed, the compiler enforces that all cases are covered:
fun describe(item: YTItem): String = when (item) {
    is SongItem -> buildString {
        append("🎵 ${item.title}")
        append(" by ${item.artists.joinToString { it.name }}")
        item.album?.let { append(" · ${it.name}") }
        item.duration?.let { append(" (${it / 60}:${(it % 60).toString().padStart(2, '0')})") }
        if (item.isVideoSong) append(" [Video]")
        if (item.explicit) append(" 🅴")
    }
    is AlbumItem -> buildString {
        append("💿 ${item.title}")
        item.artists?.let { append(" by ${it.joinToString { a -> a.name }}") }
        item.year?.let { append(" ($it)") }
    }
    is PlaylistItem -> buildString {
        append("📋 ${item.title}")
        item.author?.let { append(" · ${it.name}") }
        item.songCountText?.let { append(" · $it") }
    }
    is ArtistItem -> buildString {
        append("👤 ${item.title}")
        item.subtext?.let { append(" · $it") }
    }
}

Filter Extension Functions

Three extension functions on List<T : YTItem> let you filter results without manual when expressions:
// Remove explicit tracks (e.g. for parental controls)
fun <T : YTItem> List<T>.filterExplicit(enabled: Boolean = true): List<T>

// Remove music video SongItems, keeping only pure audio tracks
fun <T : YTItem> List<T>.filterVideoSongs(disableVideos: Boolean = false): List<T>

// Remove YouTube Shorts from playlist results (id starts with "SS")
fun <T : YTItem> List<T>.filterYoutubeShorts(enabled: Boolean = false): List<T>
Usage example:
viewModelScope.launch {
    YouTube.search("pop hits", SearchFilter.FILTER_SONG)
        .onSuccess { result ->
            val filtered = result.items
                .filterExplicit(enabled = userPrefs.hideExplicit)
                .filterVideoSongs(disableVideos = userPrefs.audioOnlyMode)

            adapter.submitList(filtered)
        }
}
filterExplicit filters on the explicit field of each YTItem. Note that AlbumItem.explicit is currently always false because the YouTube API does not reliably surface the explicit badge for albums in all response formats.

Build docs developers (and LLMs) love