Introducing a new way to review your PRs.

Read the announcement

iv-org / invidious

Invidious is an alternative front-end to YouTube

View on GitHub

19 documents · Updated Oct 12, 2026

docs / playlists-and-personal-library

Playlists and personal library

Playlists let people browse and play grouped video content while giving signed-in users a personal library for playlists they create or save. The system joins public playlist data from YouTube with private playlist state in Invidious, then presents both through web pages, feeds, playback controls, and authenticated API access.

Playlist model

The playlist model has two main sources. A public playlist is read from the YouTube service when a request names an external playlist ID. An Invidious playlist is owned by a signed-in user and keeps its title, description, privacy state, item order, and item count in the local account data store. src/invidious/playlists.cr#L85-L179 defines the shared public shape and the user-owned shape.

Public playlists

Public playlists provide metadata such as a title, author, description, thumbnail, view count, update time, and video count. The system retrieves their current metadata and items from YouTube, so the playlist page reflects the source service rather than a local copy. src/invidious/playlists.cr#L328-L421.

Public playlists can have an author, while some generated or incomplete playlists do not. The page still exposes the video list and source links when author data is missing. src/invidious/views/playlist.ecr#L71-L101.

References: src/…/playlists.cr• L85-159 src/…/playlists.cr• L328-421 src/…/playlist.ecr• L71-101

User-owned playlists

User-owned playlists are the local playlist type. They belong to the account that created or saved them, support Public, Unlisted, and Private visibility, and keep an ordered set of video items. A private playlist is visible only to its owner through the web and API retrieval paths. src/invidious/playlists.cr#L167-L253, src/invidious/routes/playlists.cr#L401-L437.

The personal library separates playlists created in Invidious from saved references to external playlists. The library uses the playlist ID form to keep these groups distinct, then renders both groups on the signed-in playlists page. src/invidious/routes/feeds.cr#L8-L31, src/invidious/views/feeds/playlists.ecr#L7-L41.

References: src/…/playlists.cr• L161-253 src/…/playlists.cr• L401-437 src/…/feeds.cr• L8-31 src/…/playlists.ecr• L7-41

Playlist retrieval

Playlist retrieval first identifies the source of the playlist and then loads the requested page of items. The same decision supports a browser page, an API response, an RSS feed, and the playlist panel shown beside a video. src/invidious/playlists.cr#L328-L338.

Retrieval paths

The retrieval path follows this sequence:

  1. The request supplies a playlist ID. Mix IDs are sent to the mix flow instead of the playlist flow.
  2. An Invidious-owned ID is read from local account data. Other IDs are fetched from YouTube.
  3. Privacy is checked against the signed-in user when the playlist is private.
  4. The requested page or playback position is used to load playlist items.
  5. The result is returned as a full page, JSON, HTML for dynamic playback, or Atom feed data.

The following diagram shows how the source choice leads to the different consumers.

flowchart TD
    A[Playlist request] --> B{Playlist ID}
    B -->|Invidious ID| C[Local playlist data]
    B -->|Public source ID| D[YouTube playlist data]
    C --> E[Privacy check]
    D --> E
    E --> F[Ordered playlist items]
    F --> G[Playlist page]
    F --> H[API JSON or HTML]
    F --> I[Atom feed]
    F --> J[Watch and embed playback]

src/invidious/routes/api/v1/misc.cr#L29-L101 applies the same retrieval rule to the public and authenticated playlist API paths. It can return JSON for clients or a small HTML playlist view for the watch page.

References: src/…/playlists.cr• L328-338 src/…/playlists.cr• L383-447 src/…/misc.cr• L29-101

Item pages and order

Playlist pages use pagination because public and local playlists can contain many videos. Local playlists read items in the order held by the playlist, while public playlists request enough source data to cover the requested range. src/invidious/playlists.cr#L424-L455.

When a video is opened with a playlist position, the API can locate that video and return nearby items. This lets the watch page start at the current video and identify the next video without loading the whole playlist into the browser. src/invidious/routes/api/v1/misc.cr#L65-L98.

References: src/…/playlists.cr• L424-455 src/…/playlists.cr• L409-444 src/…/misc.cr• L65-98

Personal library

The personal library is the signed-in view of a user's playlist state. It gives the user one place to see created playlists, saved external playlists, create a new playlist, and reach data import or export. src/invidious/views/feeds/playlists.ecr#L7-L41.

Created and saved playlists

Created playlists are local playlists owned by the user. Saved playlists are local library records for external playlists that the user chose to keep. The subscribe flow copies enough source metadata to place the external playlist in the library while preserving the user's private ownership of the saved record. src/invidious/routes/playlists.cr#L58-L79, src/invidious/playlists.cr#L275-L291.

The library requires an authenticated user. This boundary connects playlist access to the account and session rules described in Accounts, sessions, and preferences. Portable playlist state is handled with the import and export flows described in User data import and export.

References: src/…/feeds.cr• L8-31 src/…/playlists.cr• L58-79 src/…/playlists.cr• L275-291

Default playlist selection

The user's preferences can name a default playlist for add-to-playlist actions. This setting affects how the wider video interface chooses a destination, while playlist ownership and item checks still apply when the add request runs. src/invidious/user/preferences.cr#L46-L60, src/invidious/routes/preferences.cr#L146-L190.

References: src/…/preferences.cr• L46-60 src/…/preferences.cr• L146-190

Playlist management

Signed-in users can create, edit, delete, and add or remove items from local playlists. These actions are available from the web interface and from authenticated API endpoints, so both browser users and external clients use the same ownership rules.

Creation and editing

Creation requires a signed-in user, a title, and a valid privacy choice. The web form and API both enforce a maximum of 100 owned playlists. Editing changes the title, description, or privacy state and updates the playlist time when a value changes. src/invidious/routes/playlists.cr#L20-L56, src/invidious/routes/api/v1/authenticated.cr#L210-L270.

The supported privacy states are Public, Unlisted, and Private. Public playlists may be found and viewed by others, Unlisted playlists are available by link, and Private playlists require the owner. The exact visibility behavior is enforced at retrieval time. src/invidious/playlists.cr#L161-L165, src/invidious/routes/playlists.cr#L421-L423.

References: src/…/playlists.cr• L20-56 src/…/playlists.cr• L140-225 src/…/authenticated.cr• L210-270 src/…/playlists.cr• L161-165

Item management

An add request resolves the video first, then records the video details as a playlist item and updates the playlist order and count. A remove request uses the item's playlist position and updates both the item set and the count. The web interface sends these changes in the background so the page can hide or mark the affected tile without a full reload. src/invidious/routes/playlists.cr#L274-L380, assets/…/playlist_widget.js• L5-47.

Users can add videos from the watch and search-style playlist editing views. The add page searches for videos and offers an add action beside each result. The playlist page offers a remove action to its owner. src/invidious/views/add_playlist_items.ecr#L6-L35, src/invidious/views/components/item.ecr#L152-L166.

The authenticated API exposes the same add and remove capabilities. It also returns a location for the new item and a structured item response for API clients. Reordering is not available yet through the web action or authenticated API. src/invidious/routes/api/v1/authenticated.cr#L292-L375, src/invidious/routes/playlists.cr#L321-L373.

References: src/…/playlists.cr• L227-380 src/…/authenticated.cr• L292-375 assets/…/playlist_widget.js• L5-47 src/…/add_playlist_items.ecr• L6-35 src/…/item.ecr• L152-166

Management interfaces

The browser interface uses session-bound request tokens for create, edit, delete, add, and remove actions. The API uses authenticated routes for listing, creation, metadata changes, deletion, and item changes. The route map makes this split explicit. src/invidious/routing.cr#L84-L109, src/invidious/routing.cr#L307-L326.

The main management endpoints are:

InterfaceMain capabilities
Web library and playlist pagesView, create, subscribe, edit, delete, add, and remove
Public playlist APIRetrieve visible public playlist data
Authenticated playlist APIList, create, edit, delete, add, and remove for the signed-in user
Playlist Atom feedSubscribe to an allowed playlist's item updates

References: src/…/routing.cr• L84-109 src/…/routing.cr• L307-326 src/…/authenticated.cr• L195-370

Playlist rendering

Rendering turns the common playlist and item data into several user-facing forms. The full playlist page shows identity, description, privacy, item cards, pagination, and owner controls. src/invidious/views/playlist.ecr#L1-L125.

Library and playlist pages

The library renders created and saved playlists as cards. A playlist card links to the playlist page and shows its thumbnail, title, author information when available, and video count. The shared item renderer also supplies add and remove controls when the current page sets the matching playlist action. src/invidious/views/feeds/playlists.ecr#L25-L41, src/invidious/views/components/item.ecr#L57-L98, src/invidious/views/components/item.ecr#L152-L166.

References: src/…/playlists.ecr• L25-41 src/…/playlist.ecr• L9-125 src/…/item.ecr• L57-98 src/…/item.ecr• L152-166

Playback views

The watch page loads the playlist panel after the video page opens. It asks the playlist API for HTML, places the result beside the player, scrolls to the current item, and uses the returned next item for playlist navigation. Embed routes use the same playlist lookup to resolve a playlist position to a video. assets/…/watch.js• L53-111, src/invidious/routes/embed.cr#L4-L33.

The playback link keeps the playlist ID and item position in the watch URL. This preserves context for next-video navigation, audio mode, and embedded playback. src/invidious/playlists.cr#L544-L578, src/invidious/views/components/item.ecr#L113-L124.

References: assets/…/watch.js• L53-111 src/…/embed.cr• L4-33 src/…/playlists.cr• L544-578 src/…/item.ecr• L113-124

Feeds and channel discovery

Each allowed playlist can expose an Atom feed. Local playlist feeds check private ownership before returning items, while external playlist feeds are obtained from the source service. src/invidious/routes/feeds.cr#L271-L324.

Channel pages provide another entry point for public playlists. They support sorting and continuation for a channel's playlist list, and the API exposes the same collection for programmatic clients. See Channel content and subscriptions for the wider channel flow. src/invidious/routes/channels.cr#L136-L157, src/invidious/routes/api/v1/channels.cr#L281-L311.

References: src/…/feeds.cr• L271-324 src/…/channels.cr• L136-157 src/…/channels.cr• L281-311

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the ownership and privacy checks aligned across the web page, RSS feed, public playlist API, and authenticated playlist API.
  • Keep playlist item order and item count changes in sync when add or remove behavior changes.
  • Keep the HTML response fields used by the watch page aligned with playlist playback navigation.
  • Keep local created-playlist IDs distinct from saved external playlist IDs so library grouping remains correct.
  • Keep playlist import and export mappings aligned with changes to title, description, privacy, item order, and playlist identity.
  • Keep channel playlist pagination and sort behavior aligned between the channel page and channel API.

Important failure modes

TriggerConsequenceGuard
A private playlist request does not match the ownerThe playlist or feed is rejected instead of exposing its itemsApply the owner check before page, API, and Atom rendering
A playlist source returns no usable metadata or item dataThe page or API returns a not-found or retrieval errorKeep source parsing errors on the retrieval boundary
An add request reaches the playlist length limitThe item is not addedEnforce the configured item limit before video lookup and storage
An item removal uses an index not in the playlistThe request fails and no item is removedValidate the index against the playlist order before deletion
Playlist metadata changes without the matching count or order updateThe page can show stale item totals or a wrong orderTreat playlist and playlist-item state as one change
Playlist playback receives an invalid or empty page positionThe watch or embed flow cannot resolve the next videoCheck the requested range and return the playlist page when no item exists

Key files

FileWhy to read it
src/invidious/playlists.crDefines the public and user-owned playlist concepts, item retrieval, and shared output shapes.
src/invidious/routes/playlists.crShows the browser flows for retrieval, creation, editing, deletion, subscription, and item changes.
src/invidious/routes/api/v1/authenticated.crShows the authenticated API contract for personal playlist management.
src/invidious/routes/api/v1/misc.crShows public and authenticated playlist retrieval plus the HTML form used by playback.
src/invidious/routes/feeds.crConnects the personal library and playlist Atom feeds to playlist data.
src/invidious/views/playlist.ecrShows the main playlist page and owner-only controls.
src/invidious/views/feeds/playlists.ecrShows how created and saved playlists form the personal library view.
assets/…/watch.jsShows how the watch page loads a playlist and advances through its items.
src/invidious/routing.crMaps browser, feed, public API, and authenticated API playlist interfaces.