Search, discovery, and mixes
Search and discovery give Invidious one browseable view over content returned by YouTube and, for subscription search, content held in the local account view. Search turns a user query into typed results with filters and paging. Discovery turns a region or hashtag into a feed. Mixes turn a YouTube recommendation list into a short playable queue.
Search model
The search model separates what the user typed from how the request should run. Invidious::Search::Query in src/invidious/search/query.cr reads the query, page, region, and filter parameters. It can also recognize a channel search, a subscription search, or a playlist-item search. A blank query returns the search page instead of contacting the backend, while a YouTube URL can go directly to its matching Invidious page.
The normal search path uses the YouTube search service. Subscription search instead reads the signed-in user's local subscription view. Channel search resolves the channel first and then asks the YouTube browse service for matching channel videos. This keeps the public search experience close to YouTube while still supporting searches over private Invidious state.
flowchart TD
A[Search request] --> B[Read query, page, region, and filters]
B --> C{Query kind}
C -->|Regular or playlist| D[YouTube search]
C -->|Channel| E[Resolve channel and browse channel search]
C -->|Subscriptions| F[Search local subscription view]
D --> G[Normalize result items]
E --> G
F --> G
G --> H[Render page or return JSON]
References: src/…/query.cr• L2-24 src/…/query.cr• L43-139 src/…/processors.cr• L5-53
Search interfaces
The browser interface is available at /search for GET and POST requests. It shows a search form for an empty query and a paged result list for a non-empty query. The API exposes the same main search through /api/v1/search, while /api/v1/search/suggestions returns completion text from YouTube. The route family also exposes OpenSearch metadata so browser search tools can target Invidious. [src/invidious/routing.cr#L184-L190, src/invidious/routing.cr#L282-L285, src/invidious/routes/search.cr#L4-L37, src/invidious/routes/api/v1/search.cr#L1-L58]
The search form uses POST when search privacy is enabled and GET otherwise. Both methods create the same query model. Search results are converted to the shared item format before the web page or JSON response presents them.
References: src/…/search_box.ecr• L5-19 src/…/search.cr• L39-95 src/…/search.cr• L1-23
Search filters
Filters describe the user's intent in a stable Invidious form before they are translated to YouTube's search request format. The supported groups are date, content type, duration, features, and sort order. Features cover media properties such as live content, HD, subtitles, Creative Commons, 360 video, VR, HDR, location, and purchased content.
The model accepts both current Invidious query parameters and YouTube's encoded sp parameter. It also understands older filter words embedded in the query, then removes those words from the text sent to the search service. The result page rebuilds links from the normalized filter state, so paging keeps the query and selected filters together.
References: src/…/filters.cr• L5-83 src/…/filters.cr• L136-250 src/…/filters.cr• L257-371 src/…/search_filters.cr• L4-35 src/…/search.cr• L81-95
Discovery feeds
Discovery feeds provide entry points that do not need a free-form search term. The trending feed uses a region and a feed type to request a browse page from YouTube. It flattens grouped results into shared search items, removes small noisy groups, and removes duplicate videos before the browser or API sees them.
The available public choices are livestreams and gaming. The default path also uses the livestream source because YouTube no longer provides the former combined trending page. A browser request renders the feed with links for the choices. The API returns the same selected items as a JSON array.
flowchart LR
A[Region and feed type] --> B[YouTube browse feed]
B --> C[Extract grouped items]
C --> D[Drop small noisy groups]
D --> E[Remove duplicate videos]
E --> F[Web feed or API array]
References: src/…/trending.cr• L1-48 src/…/feeds.cr• L45-62 src/…/feeds.cr• L1-25 src/…/trending.ecr• L12-47
Hashtag feeds
A hashtag feed treats a hashtag as a browse key rather than as ordinary search text. /hashtag/:hashtag and /api/v1/hashtag/:hashtag ask YouTube for hashtag results with a page position and optional region. The web route displays the shared paged item list. The API wraps the same items in a results array.
Hashtag paging advances in blocks of 60 results. The route uses the result count to decide whether to show a next-page link, so a short response ends the browse path.
References: src/…/hashtag.cr• L1-13 src/…/search.cr• L98-129 src/…/search.cr• L60-86 src/…/routing.cr• L184-190
Mix queues
A mix is a YouTube-generated recommendation queue linked to a video and a list identifier. The mix flow reads the watch-page playlist, keeps the requested video as the start point when possible, and exposes a bounded list of videos with titles, authors, IDs, positions, and lengths. This lets the watch page and API clients continue through related content without creating an Invidious playlist.
The browser endpoint is /mix?list=.... The API endpoint is /api/v1/mixes/:rdid, with optional continuation and HTML output for clients that need a rendered playlist fragment. The queue is deduplicated and limited to 50 videos. A playlist-style RSS link is shown on the browser page so the mix can be consumed as a feed entry point.
sequenceDiagram
participant U as Client
participant I as Invidious
participant Y as YouTube watch data
U->>I: Request mix ID and optional start video
I->>Y: Load recommendation playlist
Y-->>I: Mix title and playlist items
I->>I: Keep start position, remove duplicates, cap queue
I-->>U: Browseable mix or JSON queue
References: src/…/mixes.cr• L1-19 src/…/mixes.cr• L21-82 src/…/playlists.cr• L449-467 src/…/misc.cr• L104-174 src/…/mix.ecr• L1-20
Backend and presentation boundaries
Search, hashtag, trending, and mix routes depend on the shared YouTube access and extraction layer. That layer turns YouTube response data into common item objects. Web templates then present those objects as cards and paged lists. API routes serialize the same result objects into JSON, which keeps browser and programmatic consumers aligned.
For a broader view of the outbound request layer, see YouTube backend integration. For the registration and delegation of the browser and API route families, see Web and API route families.
References: src/…/processors.cr• L5-35 src/…/trending.cr• L24-48 src/…/hashtag.cr• L4-13 src/…/search.cr• L16-23
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the filter names and value meanings aligned across
Search::Filters, the browser filter form, the Invidious URL format, and YouTube's encoded search parameters. - Keep page-size and next-page rules aligned between search, hashtag, and continuation requests. A change in the upstream result count can otherwise create missing or repeated pages.
- Keep web and API routes on the same query and item-processing paths unless their output contract must differ.
- When YouTube changes browse or watch response shapes, review regular search, hashtag feeds, trending groups, and mix queues together because they share extraction behavior.
- Preserve the start-video and queue-size contract for mix consumers that use
continuation,index, ornextVideo.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| YouTube returns no usable channel ID during channel search | The search cannot resolve the requested channel and returns a channel-search error | Resolve the channel before producing the channel search request and surface the specific channel error |
| A search, hashtag, or trending request fails at the YouTube boundary | The browser receives an error page or the API receives an error response instead of result items | Route handlers catch the request error and map it to the web or JSON error contract |
| The selected mix has no usable playlist data | The client cannot build a playable recommendation queue | Require playlist data before parsing the mix and return a mix error when it is absent |
| Trending results contain repeated items or small noisy groups | The feed looks incomplete or contains low-value duplicate content | Remove small groups when grouped results are present and deduplicate the final video list |
| Search filters use an unknown value | The request falls back to the matching default filter state | Parse known values and preserve a valid normalized query before rebuilding links |
Key files
| File | Why to read it |
|---|---|
src/invidious/search/query.cr | Defines the common search request model and its search modes |
src/invidious/search/filters.cr | Defines filter meaning and the translations between URL and YouTube forms |
src/invidious/search/processors.cr | Shows which backend serves each search mode |
src/invidious/routes/search.cr | Connects browser search and hashtag requests to the query and feed models |
src/invidious/routes/api/v1/search.cr | Defines search suggestions and search/hashtag JSON boundaries |
src/invidious/trending.cr | Defines the regional trending feed and its result cleanup rules |
src/invidious/hashtag.cr | Defines hashtag paging and browse requests |
src/invidious/mixes.cr | Defines the mix queue shape and retrieval behavior |
src/invidious/routes/api/v1/misc.cr | Defines the mix API response and optional HTML output |
src/invidious/routing.cr | Lists the browser and API entry points for this area |