feat(core,app,android,ios): more like this and browse by genre, studio, person

pstr_core::discover scores every title against another by shared
director, studio, genres, leading tags and format, leaves out its own
franchise and keeps one title per other franchise. It drives a "More
like this" row under a title's episodes and, seeded by the title most
recently watched to the end, a "Because you watched" row on the library
of titles not yet started.

Genre chips on the title page now open a page of every title with that
genre, and the studios and director move from the line of facts onto
chips of their own that do the same. The desktop has a Browse page whose
back link returns to the title; Android and iOS show it over the library
pane. The bridge exposes more_like, browse and facet_kind.

Also moves a doc comment the My List commit left on the wrong function.
This commit is contained in:
nvrl committed 2026-10-30 22:46:08 +01:00
1 parent f66faf6b75
commit fafe0c3087
23 files changed
+1139 -92

No files matched your search

+61 -4
View File
@@ -50,6 +50,7 @@ impl FrameTimer {
Page::Library => "library",
Page::History => "history",
Page::Title(_) => "title",
Page::Browse { .. } => "browse",
Page::Shares => "shares",
Page::Downloads => "downloads",
Page::Settings => "settings",
@@ -97,6 +98,12 @@ pub enum Page {
History,
/// One title, by [`pstr_core::library::Title::key`].
Title(String),
/// The titles a genre, studio or person chip stands for, with the title
/// it was opened from, for the way back.
Browse {
facet: pstr_core::discover::Facet,
from: Option<String>,
},
Shares,
Downloads,
/// How the app looks, how it plays, and what it looks up.
@@ -420,6 +427,9 @@ pub struct LibraryView {
pub badges: HashMap<String, String>,
/// The keys on My List.
pub listed: std::collections::HashSet<String>,
/// "More like this" for the title page open, worked out once per title:
/// its key, and the keys of the titles like it.
pub similar: Option<(String, Vec<String>)>,
/// The library or what is known about it changed under the lists.
stale: bool,
/// Only watch state changed: the shelves and franchises still stand,
@@ -457,6 +467,7 @@ impl Default for LibraryView {
resumable: Vec::new(),
badges: HashMap::new(),
listed: std::collections::HashSet::new(),
similar: None,
stale: false,
progressed: false,
}
@@ -483,6 +494,9 @@ pub struct ViewInputs<'a> {
/// How many shelves the library shows above the grid.
const SHELVES: usize = 4;
/// How many titles a title page's "More like this" row offers.
const SIMILAR: usize = 12;
impl LibraryView {
fn refresh(&mut self, library: &Library, inputs: ViewInputs<'_>) {
use pstr_core::library::Title;
@@ -506,6 +520,7 @@ impl LibraryView {
}
let metadata = inputs.metadata;
if self.stale {
self.similar = None;
let all: Vec<&Title> = library.titles.iter().collect();
self.franchises = pstr_core::franchise::group(&all, metadata)
.into_iter()
@@ -533,6 +548,7 @@ impl LibraryView {
self.shelves = pstr_core::shelves::home(
&library.titles,
metadata,
inputs.names,
inputs.list,
inputs.first_seen,
inputs.now,
@@ -1722,7 +1738,10 @@ impl App {
}
Action::WatchToEnd => self.up_next.dismissed = true,
Action::FocusSearch => {
if !matches!(self.page, Page::Library | Page::Title(_)) {
if !matches!(
self.page,
Page::Library | Page::Title(_) | Page::Browse { .. }
) {
self.page = Page::Library;
}
self.focus_search = true;
@@ -1741,8 +1760,11 @@ impl App {
self.my_list = self.engine.set_on_list(&key, on);
self.view.stale = true;
}
Action::Back => match self.page {
Action::Back => match &self.page {
Page::Title(_) => self.page = Page::Library,
Page::Browse { from, .. } => {
self.page = from.clone().map_or(Page::Library, Page::Title)
}
// Back out of a search before out of anything else: it is the
// last thing the viewer did.
Page::Library if !self.search.is_empty() => self.search.clear(),
@@ -2131,7 +2153,10 @@ impl App {
);
ui.add_space(theme::space::L);
let on_library = matches!(self.page, Page::Library | Page::Title(_));
let on_library = matches!(
self.page,
Page::Library | Page::Title(_) | Page::Browse { .. }
);
let active = self
.downloads
.iter()
@@ -2452,6 +2477,18 @@ impl eframe::App for App {
now: crate::engine::unix_now(),
},
);
// After the refresh, which forgets it when the library changed.
if let Page::Title(key) = &self.page
&& self.view.similar.as_ref().is_none_or(|(of, _)| of != key)
{
let keys = pstr_core::discover::more_like(
key,
&self.library.titles,
&self.metadata,
SIMILAR,
);
self.view.similar = Some((key.clone(), keys));
}
let crawl = self.crawling.then(|| crawl_label(&self.crawl_progress));
let App {
@@ -2580,6 +2617,12 @@ impl eframe::App for App {
key,
ui::title::Context {
franchise: view.franchises.get(key.as_str()).map(Vec::as_slice),
similar: view
.similar
.as_ref()
.filter(|(of, _)| of == key)
.map(|(_, keys)| keys.as_slice())
.unwrap_or_default(),
on_list: view.listed.contains(key.as_str()),
},
ui::title::OfflineView {
@@ -2588,6 +2631,18 @@ impl eframe::App for App {
},
&mut actions,
),
Page::Browse { facet, from } => ui::library::browse(
ui,
&mut art,
library,
ui::library::Browsing {
facet,
from: from.as_deref(),
},
view,
engine.appearance().tiles,
&mut actions,
),
Page::Shares => ui::shares::show(
ui,
shares,
@@ -2939,7 +2994,9 @@ fn global_shortcuts(ctx: &egui::Context, page: &Page, actions: &mut Vec<Action>)
}
if input.consume_key(Modifiers::ALT, Key::ArrowLeft)
|| input.pointer.button_pressed(egui::PointerButton::Extra1)
|| (!typing && matches!(page, Page::Title(_)) && input.key_pressed(Key::Escape))
|| (!typing
&& matches!(page, Page::Title(_) | Page::Browse { .. })
&& input.key_pressed(Key::Escape))
|| (!typing && *page == Page::Library && input.key_pressed(Key::Backspace))
{
actions.push(Action::Back);
+49 -1
View File
@@ -123,7 +123,51 @@ pub fn show(ui: &mut egui::Ui, art: &mut Art<'_>, shelves: Shelves<'_>, actions:
return;
}
grid(ui, art, &matches, view, tiles, actions);
grid(ui, art, &matches, view, tiles, true, actions);
});
}
/// What a chip on a title page opened.
pub struct Browsing<'a> {
pub facet: &'a pstr_core::discover::Facet,
/// The title it was opened from, which is where back goes.
pub from: Option<&'a str>,
}
/// Every title sharing a genre, a studio or a director, as the library grid.
pub fn browse(
ui: &mut egui::Ui,
art: &mut Art<'_>,
library: &Library,
browsing: Browsing<'_>,
view: &LibraryView,
tiles: Tiles,
actions: &mut Vec<Action>,
) {
let Browsing { facet, from } = browsing;
let back = from
.and_then(|key| library.get(key))
.map_or("Library", |title| art.name(title))
.to_owned();
if ui::title::back_link(ui, &back).clicked() {
actions.push(Action::Back);
}
ui.add_space(theme::space::S);
let keys = facet.titles(&library.titles, art.metadata);
let titles: Vec<&Title> = keys.iter().filter_map(|key| library.get(key)).collect();
egui::ScrollArea::vertical()
.auto_shrink([false, false])
.show(ui, |ui| {
ui.label(ui::muted(facet.kind()));
ui.label(theme::Role::Display.rich(facet.name()).color(theme::text()));
ui.label(ui::muted(plural(titles.len(), "title")));
ui.add_space(theme::space::L);
if titles.is_empty() {
// A recrawl or a new match took the last one away.
ui.label(ui::muted("Nothing in the library has this any more."));
return;
}
grid(ui, art, &titles, view, tiles, false, actions);
});
}
@@ -740,12 +784,15 @@ fn continue_row(
}
/// Every title, wrapped to the window.
/// `titles` as a wall of tiles. `folding` says they are the library grid's
/// own, whose folded franchises `view` counts.
fn grid(
ui: &mut egui::Ui,
art: &mut Art<'_>,
titles: &[&Title],
view: &LibraryView,
tiles: Tiles,
folding: bool,
actions: &mut Vec<Action>,
) {
let (minimum, aspect) = tile_shape(tiles);
@@ -780,6 +827,7 @@ fn grid(
let folded = view
.matches
.get(row * grid.columns + column)
.filter(|_| folding)
.and_then(|index| view.folded.get(index))
.copied();
let response = ui::card(
+95 -26
View File
@@ -20,6 +20,8 @@ pub struct OfflineView<'a> {
pub struct Context<'a> {
/// The keys of its whole franchise in release order, if it has one.
pub franchise: Option<&'a [String]>,
/// The keys of the titles most like it, best first.
pub similar: &'a [String],
pub on_list: bool,
}
@@ -32,7 +34,11 @@ pub fn show(
offline: OfflineView<'_>,
actions: &mut Vec<Action>,
) {
let Context { franchise, on_list } = context;
let Context {
franchise,
similar,
on_list,
} = context;
let Some(title) = library.get(key) else {
// The catalog was replaced under the page — a recrawl that dropped this
// title. Nothing to show, so go back rather than draw an empty shell.
@@ -40,7 +46,7 @@ pub fn show(
return;
};
if back_link(ui).clicked() {
if back_link(ui, "Library").clicked() {
actions.push(Action::Goto(Page::Library));
}
ui.add_space(theme::space::S);
@@ -55,7 +61,14 @@ pub fn show(
let members: Vec<&Title> = keys.iter().filter_map(|key| library.get(key)).collect();
if members.len() > 1 {
ui::section(ui, "In this franchise");
franchise_row(ui, art, title, &members, actions);
cover_row(
ui,
art,
("franchise", &title.key),
Some(title),
&members,
actions,
);
ui.add_space(theme::space::XL);
}
}
@@ -137,23 +150,35 @@ pub fn show(
episode_row(ui, art, title, season, episode, &offline, actions);
}
ui.add_space(theme::space::L);
// Under the episodes rather than over them: it is where to go
// once this one is done, not what the page is for.
let similar: Vec<&Title> = similar.iter().filter_map(|key| library.get(key)).collect();
if !similar.is_empty() {
ui.add_space(theme::space::L);
ui::section(ui, "More like this");
cover_row(ui, art, ("similar", &title.key), None, &similar, actions);
ui.add_space(theme::space::L);
}
});
}
/// Every title of the franchise, in release order, as covers — this one
/// marked rather than left out, so the row says where it sits in the story.
fn franchise_row(
/// A row of covers: every title of the franchise in release order, with
/// `current` marked rather than left out, so the row says where it sits in
/// the story — or, with no `current`, the titles like this one.
fn cover_row(
ui: &mut egui::Ui,
art: &mut Art<'_>,
current: &Title,
id: impl std::hash::Hash + std::fmt::Debug,
current: Option<&Title>,
members: &[&Title],
actions: &mut Vec<Action>,
) {
ui::shelf(ui, ("franchise", &current.key), |ui| {
ui::shelf(ui, id, |ui| {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = theme::CARD_GAP;
for member in members {
let here = member.key == current.key;
let here = current.is_some_and(|current| member.key == current.key);
let picture = art.poster(member);
let found = art
.metadata
@@ -217,9 +242,10 @@ fn poster(ui: &mut egui::Ui, texture: &egui::TextureHandle, progress: Option<f64
}
/// "← Library", as a link rather than a button: it is navigation, and a
/// filled button beside the page's real actions competed with them.
fn back_link(ui: &mut egui::Ui) -> egui::Response {
let text = theme::Role::Label.rich(format!("{} Library", egui_phosphor::regular::ARROW_LEFT));
/// filled button beside the page's real actions competed with them. `to`
/// names where it goes.
pub(crate) fn back_link(ui: &mut egui::Ui, to: &str) -> egui::Response {
let text = theme::Role::Label.rich(format!("{} {to}", egui_phosphor::regular::ARROW_LEFT));
let response = ui.add(egui::Label::new(text.color(theme::muted())).sense(egui::Sense::click()));
if response.hovered() {
ui.painter().hline(
@@ -495,7 +521,7 @@ fn header(
if let Some(found) = &found {
ui.add_space(theme::space::L);
description(ui, found);
description(ui, found, &title.key, actions);
}
});
});
@@ -610,17 +636,31 @@ fn band(
}
/// What the provider had to say. Only ever drawn under a match.
fn description(ui: &mut egui::Ui, found: &TitleMetadata) {
let tags = found
.details
.as_ref()
///
/// Its genres, studios and director are chips that open every title in the
/// library sharing them.
fn description(ui: &mut egui::Ui, found: &TitleMetadata, key: &str, actions: &mut Vec<Action>) {
use pstr_core::discover::Facet;
let browse = |facet: Facet| {
Action::Goto(Page::Browse {
facet,
from: Some(key.to_owned()),
})
};
let details = found.details.as_ref();
let tags = details
.map(|details| details.tags.as_slice())
.unwrap_or_default();
if !found.genres.is_empty() || !tags.is_empty() {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing.x = 6.0;
for genre in &found.genres {
ui::widgets::chip(ui, genre);
if ui::widgets::link_chip(ui, genre)
.on_hover_text(format!("Every {genre} title"))
.clicked()
{
actions.push(browse(Facet::Genre(genre.clone())));
}
}
// After the genres and quieter than them: a tag is the
// provider's community describing it, not what it is filed as.
@@ -630,6 +670,38 @@ fn description(ui: &mut egui::Ui, found: &TitleMetadata) {
});
ui.add_space(theme::space::M);
}
// Who made it, out of the grey line and onto chips, so the names lead
// somewhere.
let studios = details
.map(|details| &details.studios[..details.studios.len().min(2)])
.unwrap_or_default();
let directors = details
.map(|details| &details.directors[..details.directors.len().min(1)])
.unwrap_or_default();
if !studios.is_empty() || !directors.is_empty() {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing.x = 6.0;
for (label, names, facet) in [
("Studio", studios, Facet::Studio as fn(String) -> Facet),
("Director", directors, Facet::Person),
] {
if names.is_empty() {
continue;
}
ui.label(ui::muted(label));
for name in names {
if ui::widgets::link_chip(ui, name)
.on_hover_text(format!("Everything in the library by {name}"))
.clicked()
{
actions.push(browse(facet(name.clone())));
}
}
ui.add_space(theme::space::S);
}
});
ui.add_space(theme::space::M);
}
if let Some(overview) = &found.overview {
// Four lines, then "More". A provider's synopsis runs to three
// paragraphs on a long show, and all of them pushed the episodes —
@@ -711,14 +783,11 @@ fn meta_line(title: &Title, found: Option<&TitleMetadata>) -> String {
parts.push(format!("{watched} watched"));
}
if let Some(details) = found.and_then(|found| found.details.as_ref()) {
if let Some(season) = details.season_label() {
parts.push(season);
}
parts.extend(details.studios.iter().take(2).cloned());
if let Some(director) = details.directors.first() {
parts.push(format!("dir. {director}"));
}
if let Some(season) = found
.and_then(|found| found.details.as_ref())
.and_then(|details| details.season_label())
{
parts.push(season);
}
if let Some(found) = found {
if let Some(rating) = found.rating {
+26
View File
@@ -447,3 +447,29 @@ pub fn chip(ui: &mut egui::Ui, text: &str) -> egui::Response {
})
.response
}
/// A [`chip`] that opens something: lighter under the pointer, with a ring
/// when keyboard focus is on it.
pub fn link_chip(ui: &mut egui::Ui, text: &str) -> egui::Response {
let mut prepared = egui::Frame::new()
.corner_radius(CornerRadius::same(theme::radius::LG))
.inner_margin(egui::Margin::symmetric(9, 3))
.begin(ui);
prepared
.content_ui
.label(theme::Role::Caption.rich(text).color(theme::text()));
let response = prepared
.allocate_space(ui)
.interact(egui::Sense::click())
.on_hover_cursor(egui::CursorIcon::PointingHand);
prepared.frame.fill = if response.hovered() {
theme::card_hover()
} else {
theme::card_hover().gamma_multiply(0.8)
};
if response.has_focus() {
prepared.frame.stroke = egui::Stroke::new(1.5, theme::accent());
}
prepared.paint(ui);
response
}