Skip to main content

Overview

The Calendar model displays upcoming episode releases for content in the user’s library. It loads meta items from addons, organizes them by release date, and provides a month-based calendar interface for browsing upcoming content.

Structure

Fields

selected
Option<Selected>
Currently selected year and month
selectable
Selectable
required
Navigation options for previous and next month
meta_items
Vec<ResourceLoadable<Vec<MetaItem>>>
required
Meta items loaded from addons for library content
month_info
MonthInfo
required
Information about the selected month (days, first weekday, today)
items
Vec<Item>
required
Calendar items organized by day, containing videos releasing that day

Selected

pub struct YearMonthDate {
    pub month: u32,
    pub year: i32,
}
month
u32
required
Month number (1-12)
year
i32
required
Year

Conversion

The type can be created from:
  • NaiveDate
  • DateTime<Utc>
  • Option<DateTime<Utc>> (defaults to default values if None)
Source: src/models/calendar.rs:37

Selectable

pub struct Selectable {
    pub prev: YearMonthDate,
    pub next: YearMonthDate,
}
prev
YearMonthDate
required
Previous month selection
next
YearMonthDate
required
Next month selection

MonthInfo

pub struct MonthInfo {
    pub today: Option<u32>,
    pub days: u32,
    pub first_weekday: u32,
}
today
Option<u32>
Current day of month if the selected month is the current month
days
u32
required
Number of days in the selected month (28-31)
first_weekday
u32
required
Weekday of the first day (0=Monday, 6=Sunday)
This information is used for rendering a calendar grid. Source: src/models/calendar.rs:98

Item

pub struct Item {
    pub date: FullDate,
    pub items: Vec<ContentItem>,
}
date
FullDate
required
The date for this calendar day
items
Vec<ContentItem>
required
Videos releasing on this date

FullDate

pub struct FullDate {
    pub day: u32,
    pub month: u32,
    pub year: i32,
}
A complete date representation for a specific day.

ContentItem

pub struct ContentItem {
    pub meta_item: MetaItem,
    pub video: Video,
}
meta_item
MetaItem
required
The meta item (series) this video belongs to
video
Video
required
The video (episode) releasing on this date

Update Implementation

Implements UpdateWithCtx<E> for calendar operations:

Supported Messages

Loads calendar for a specific month (or current month if None):
  • Loads meta items for library content (once)
  • Sets selected month
  • Computes month info
  • Organizes videos by release date
  • Updates navigation options
Source: src/models/calendar.rs:119
Clears all calendar state:
  • Clears meta items
  • Resets selection
  • Clears month info
  • Clears items
Source: src/models/calendar.rs:139
Processes meta item responses:
  • Updates meta_items with loaded data
  • Reorganizes items by date
Source: src/models/calendar.rs:152

Loading Meta Items

Meta items are loaded once using the CALENDAR_IDS_EXTRA_PROP:
1

Gather Library IDs

Collect IDs and types from library items (excluding removed and temp items)
2

Sort by Recency

Sort by modification time (most recent first)
3

Create Catalog Request

Use AggrRequest::CatalogsFiltered with ExtraType::Ids
4

Limit Results

Limit to CALENDAR_ITEMS_COUNT items
5

Load from Addons

Send request to all addons that support catalog with ids extra
Source: src/models/calendar.rs:288

Items Organization

Videos are organized by release date:
1

Iterate Days

For each day in the month (1 to days)
2

Filter Videos

Find videos where video.released matches the day, month, and year
3

Create ContentItems

Combine meta item and video into ContentItem
4

Create Day Item

Create an Item for the day with all matching videos
Source: src/models/calendar.rs:239

Month Selection

When loading:
  1. If a specific month is provided, use it
  2. Otherwise, default to current month and year
  3. Compute month info (days, first weekday, today marker)
  4. Calculate prev/next month for navigation
Source: src/models/calendar.rs:172

Usage Example

use stremio_core::models::calendar::Calendar;
use stremio_core::runtime::UpdateWithCtx;

let mut calendar = Calendar::default();

// Load current month (None means current month)
let effects = calendar.update(
    &Msg::Action(Action::Load(ActionLoad::Calendar(None))),
    &ctx
);

// Access calendar data
for item in &calendar.items {
    if !item.items.is_empty() {
        println!("Date: {}/{}/{}", item.date.year, item.date.month, item.date.day);
        for content in &item.items {
            println!("  - {} ({})", content.video.title, content.meta_item.preview.name);
        }
    }
}
use stremio_core::models::calendar::{Calendar, YearMonthDate};

let mut calendar = Calendar::default();

// Load January 2024
let selected = YearMonthDate {
    month: 1,
    year: 2024,
};

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

// Navigate to next month
let next = calendar.selectable.next.clone();
let effects = calendar.update(
    &Msg::Action(Action::Load(ActionLoad::Calendar(Some(next)))),
    &ctx
);

// Navigate to previous month  
let prev = calendar.selectable.prev.clone();
let effects = calendar.update(
    &Msg::Action(Action::Load(ActionLoad::Calendar(Some(prev)))),
    &ctx
);
// Use month_info to render calendar
let month_info = &calendar.month_info;

println!("First weekday: {} (0=Monday)", month_info.first_weekday);
println!("Days in month: {}", month_info.days);

if let Some(today) = month_info.today {
    println!("Today is day {}", today);
}

// Create grid with empty cells for alignment
let empty_cells = month_info.first_weekday;
let total_days = month_info.days;

// Render calendar grid...

Caching Strategy

Meta items are loaded once when the calendar is first loaded and cached for the entire session. Changing months does not reload meta items, only reorganizes them by date.
To refresh meta items, unload and reload the calendar:
// Unload
let effects = calendar.update(
    &Msg::Action(Action::Unload),
    &ctx
);

// Reload
let effects = calendar.update(
    &Msg::Action(Action::Load(ActionLoad::Calendar(None))),
    &ctx
);

Limitations

  • Only shows content from the user’s library
  • Limited to CALENDAR_ITEMS_COUNT items (performance)
  • Relies on addons providing accurate video.released dates
  • Does not automatically update when library changes

Constants

  • CALENDAR_IDS_EXTRA_PROP - Extra property name for requesting by IDs
  • CALENDAR_ITEMS_COUNT - Maximum number of meta items to load
Defined in src/constants.rs

Month Navigation

Previous/next month calculation uses chrono::Months:
let date = NaiveDate::from_ymd_opt(*year, *month, 1).unwrap_or_default();

let prev_date = date - Months::new(1);
let next_date = date + Months::new(1);

Selectable {
    prev: YearMonthDate::from(prev_date),
    next: YearMonthDate::from(next_date),
}
Source: src/models/calendar.rs:220

See Also

Build docs developers (and LLMs) love