Skip to main content

Overview

The CatalogWithFilters model manages catalog browsing with support for filtering by type, catalog, and extra properties. It handles pagination and provides a selectable interface for users to refine their catalog queries. This is a generic model that works with different content types through the CatalogResourceAdapter trait.

Structure

Fields

selected
Option<Selected>
Currently selected catalog request with filters applied
selectable
Selectable
required
Available filter options for types, catalogs, and extra properties
catalog
Catalog<T>
required
Paginated catalog pages. Each page is a ResourceLoadable<Vec<T>>

Selected

Represents the currently selected catalog filters:
pub struct Selected {
    pub request: ResourceRequest,
}
request
ResourceRequest
required
The resource request containing base URL, resource path, type, and extra filters

Selectable

Provides available filter options:
pub struct Selectable {
    pub types: Vec<SelectableType>,
    pub catalogs: Vec<SelectableCatalog>,
    pub extra: Vec<SelectableExtra>,
    pub next_page: Option<SelectablePage>,
}
types
Vec<SelectableType>
required
Available content types (movie, series, etc.) with selection state
catalogs
Vec<SelectableCatalog>
required
Available catalogs from addons with selection state
extra
Vec<SelectableExtra>
required
Additional filter options (genre, year, etc.) with values
next_page
Option<SelectablePage>
Request for loading the next page, if available

SelectableType

type
String
required
Content type identifier (e.g., “movie”, “series”)
selected
bool
required
Whether this type is currently selected
request
ResourceRequest
required
Request to apply this type filter

SelectableCatalog

catalog
String
required
Catalog name from addon manifest
selected
bool
required
Whether this catalog is currently selected
request
ResourceRequest
required
Request to switch to this catalog

SelectableExtra

name
String
required
Extra property name (e.g., “genre”, “year”)
is_required
bool
required
Whether this extra is required by the addon
options
Vec<SelectableExtraOption>
required
Available values for this extra property

CatalogResourceAdapter

The generic type T must implement this trait:
pub trait CatalogResourceAdapter {
    fn resource() -> &'static str;
    fn catalogs(manifest: &Manifest) -> &[ManifestCatalog];
    fn selectable_priority() -> SelectablePriority;
}

Built-in Implementations

  • MetaItemPreview: For browsing meta catalogs (movies, series)
    • Resource: "catalog"
    • Priority: SelectablePriority::Type
  • DescriptorPreview: For browsing addon catalogs
    • Resource: "addon_catalog"
    • Priority: SelectablePriority::Catalog
  • Descriptor: For browsing full addon descriptors
    • Resource: "addon_catalog"
    • Priority: SelectablePriority::Catalog

Constructor

new()

Creates a new catalog browser instance:
pub fn new(profile: &Profile) -> (Self, Effects)
Returns: A tuple of the initialized model and effects to load initial selectable state.

Update Implementation

Implements UpdateWithCtx<E> to handle catalog operations:

Supported Messages

Loads a catalog with the specified filters:
  • Updates selected request
  • Clears existing catalog pages
  • Loads first page of results
  • Updates selectable options
Source: src/models/catalog_with_filters.rs:157
Clears all catalog data:
  • Resets selected to None
  • Clears catalog pages
  • Updates selectable based on profile addons
Source: src/models/catalog_with_filters.rs:178
Loads the next page of catalog results:
  • Uses next_page request from selectable
  • Appends results to existing catalog
  • Updates pagination state
Source: src/models/catalog_with_filters.rs:191
Processes resource responses:
  • Updates corresponding catalog page
  • Marks page as Ready or Err
  • Refreshes selectable options
Source: src/models/catalog_with_filters.rs:210
Updates selectable options when profile changes (addons added/removed)Source: src/models/catalog_with_filters.rs:230

Filtering Logic

Type Selection

When SelectablePriority::Type is used:
  1. Types are derived from all addon catalogs
  2. Types are sorted by predefined priorities (movie, series, etc.)
  3. Selecting a type filters available catalogs

Catalog Selection

When SelectablePriority::Catalog is used:
  1. Catalogs are shown first
  2. Selecting a catalog filters available types
  3. Only types available in selected catalog are shown

Extra Filters

Extra properties from addon manifests:
  • Required extras must have a value selected
  • Optional extras can be None
  • Each option includes a request with that filter applied
  • Skip extra is handled specially for pagination

Pagination

Pagination uses the skip extra property:
1

First Page

Initial request has no skip property or skip=0
2

Calculate Skip

When all pages are loaded successfully, sum their content lengths
3

Next Page Request

Create request with skip= to load next page
4

Append Results

New page is appended to catalog array

Usage Example

use stremio_core::models::catalog_with_filters::CatalogWithFilters;
use stremio_core::runtime::UpdateWithCtx;
use stremio_core::types::resource::MetaItemPreview;

// Create catalog browser for meta items
let (mut catalog, effects) = CatalogWithFilters::<MetaItemPreview>::new(&profile);

// Load a specific catalog
let selected = Selected {
    request: ResourceRequest {
        base: "https://addon.example.com".parse().unwrap(),
        path: ResourcePath {
            resource: "catalog".to_string(),
            r#type: "movie".to_string(),
            id: "top".to_string(),
            extra: vec![],
        },
    },
};

let effects = catalog.update(
    &Msg::Action(Action::Load(ActionLoad::CatalogWithFilters(Some(selected)))),
    &ctx
);

// Load next page
if catalog.selectable.next_page.is_some() {
    let effects = catalog.update(
        &Msg::Action(Action::CatalogWithFilters(ActionCatalogWithFilters::LoadNextPage)),
        &ctx
    );
}

State Management

Catalog state persists until explicitly unloaded. Make sure to call Action::Unload when navigating away to free memory.
The model automatically removes the skip extra from selected requests to ensure consistent filter state.

See Also