mirror of
https://github.com/narrrl/proton-stream.git
synced 2026-11-04 16:57:00 +01:00
feat(core,meta,app,android,cli): sort, group and shelve the library
The AniList query now keeps the start date, season, banner, popularity, status, next airing episode, tags, main studios, director and story relations, as TitleDetails in one JSON column (schema v10). Matches stored without them are fetched again by id, never searched, so hand-picked matches stay; refreshing the same entry keeps its episodes and fanart. Enrichment records the entries it walked. node_first_seen remembers when each file appeared, across recrawls. pstr_core::franchise groups titles that share a provider id. The grid folds each franchise into its lead with a +N badge, and the title page lists the whole franchise in release order. pstr_core::shelves picks rows by airing status, director, studio and genre. A row needs three franchises, so one franchise's titles never make a row on their own. Desktop: - Covers are the default grid (Settings > Appearance > Library tiles). - The hero and title band use fanart or banner decoded at 1920 px. - New sorts: recently added, newest, highest rated, most popular. - Titles can show the share's, English or romaji name; search matches all of them. Android carries TitleDetails through a hand-picked match; its screens are unchanged.
This commit is contained in:
1 parent
4c80076762
commit
6853725ca0
22 files changed
+2239
-187
No files matched your search
+298
-40
@@ -12,7 +12,7 @@ use pstr_core::Share;
|
||||
use pstr_core::appearance::Appearance;
|
||||
use pstr_core::config::AppDirs;
|
||||
use pstr_core::library::Library;
|
||||
use pstr_core::metadata::{EpisodeGuide, MetadataConfig, MetadataRecord};
|
||||
use pstr_core::metadata::{EpisodeGuide, MetadataConfig, MetadataRecord, TitleNames};
|
||||
|
||||
use crate::engine::{
|
||||
DownloadItem, DownloadKey, Engine, Event, ImageCache, describe_failures, watch_state,
|
||||
@@ -213,6 +213,8 @@ pub enum Action {
|
||||
FocusSearch,
|
||||
/// Show a different slice of the library, or in a different order.
|
||||
SetShelf(Filter, Sort),
|
||||
/// Fold each franchise into one tile, or show every title.
|
||||
SetGrouped(bool),
|
||||
/// Open or close the list of keyboard shortcuts.
|
||||
ToggleShortcuts,
|
||||
/// One page back: a title to the library, the library to nowhere.
|
||||
@@ -302,25 +304,55 @@ impl Matcher {
|
||||
/// every title by when it was last played. Neither is slow once; both were
|
||||
/// being done on every frame, and while a film plays under the transport bar
|
||||
/// that is the film's frame rate.
|
||||
#[derive(Default)]
|
||||
pub struct LibraryView {
|
||||
/// The query `matches` answers, as typed.
|
||||
query: String,
|
||||
/// Which titles the grid shows, and in what order.
|
||||
pub filter: Filter,
|
||||
pub sort: Sort,
|
||||
/// The filter and order `matches` was built with.
|
||||
built_with: (Filter, Sort),
|
||||
/// One tile per franchise rather than one per title. See
|
||||
/// `pstr_core::franchise`.
|
||||
pub grouped: bool,
|
||||
/// What `matches` was built with.
|
||||
built_with: Option<(Filter, Sort, bool, TitleNames)>,
|
||||
/// Indices into [`Library::titles`].
|
||||
pub matches: Vec<usize>,
|
||||
/// In a grouped grid, how many other titles a tile stands for, by index.
|
||||
pub folded: HashMap<usize, usize>,
|
||||
/// Every title in a franchise of more than one, by key: the keys of the
|
||||
/// whole franchise in release order, its own included.
|
||||
pub franchises: HashMap<String, Vec<String>>,
|
||||
/// The rows above the grid, as a heading and indices.
|
||||
pub shelves: Vec<(String, Vec<usize>)>,
|
||||
/// Every played episode, newest first, for the history page.
|
||||
pub history: Vec<ui::history::Entry>,
|
||||
/// The "Continue watching" shelf, most recent first, as indices.
|
||||
pub resumable: Vec<usize>,
|
||||
/// The library changed under the lists.
|
||||
/// The library or what is known about it changed under the lists.
|
||||
stale: bool,
|
||||
}
|
||||
|
||||
impl Default for LibraryView {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
query: String::new(),
|
||||
filter: Filter::default(),
|
||||
sort: Sort::default(),
|
||||
// On: a share holding a series and its three films is four tiles
|
||||
// of the same picture otherwise.
|
||||
grouped: true,
|
||||
built_with: None,
|
||||
matches: Vec::new(),
|
||||
folded: HashMap::new(),
|
||||
franchises: HashMap::new(),
|
||||
shelves: Vec::new(),
|
||||
history: Vec::new(),
|
||||
resumable: Vec::new(),
|
||||
stale: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Which titles the grid shows.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum Filter {
|
||||
@@ -353,49 +385,233 @@ impl Filter {
|
||||
/// What order the grid is in.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum Sort {
|
||||
/// The library's own order: by name, ignoring a leading article.
|
||||
/// By the name shown, ignoring a leading article.
|
||||
#[default]
|
||||
Name,
|
||||
/// Most recently played first.
|
||||
Recent,
|
||||
/// Newest first, undated last.
|
||||
Year,
|
||||
/// Most recently given a new file first.
|
||||
Added,
|
||||
/// Newest first by when it aired, undated last.
|
||||
Release,
|
||||
/// Best rated first, unrated last.
|
||||
Rating,
|
||||
/// Most followed at the provider first.
|
||||
Popularity,
|
||||
}
|
||||
|
||||
impl Sort {
|
||||
pub const ALL: [Self; 6] = [
|
||||
Self::Name,
|
||||
Self::Recent,
|
||||
Self::Added,
|
||||
Self::Release,
|
||||
Self::Rating,
|
||||
Self::Popularity,
|
||||
];
|
||||
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::Name => "A – Z",
|
||||
Self::Recent => "Recently watched",
|
||||
Self::Added => "Recently added",
|
||||
Self::Release => "Newest",
|
||||
Self::Rating => "Highest rated",
|
||||
Self::Popularity => "Most popular",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What the library view is built from, besides the library itself.
|
||||
pub struct ViewInputs<'a> {
|
||||
pub query: &'a str,
|
||||
pub metadata: &'a HashMap<String, MetadataRecord>,
|
||||
pub names: TitleNames,
|
||||
/// When each title last gained a file, by key.
|
||||
pub added: &'a HashMap<String, i64>,
|
||||
}
|
||||
|
||||
/// How many shelves the library shows above the grid.
|
||||
const SHELVES: usize = 4;
|
||||
|
||||
impl LibraryView {
|
||||
fn refresh(&mut self, library: &Library, query: &str) {
|
||||
if !self.stale && self.query == query && self.built_with == (self.filter, self.sort) {
|
||||
fn refresh(&mut self, library: &Library, inputs: ViewInputs<'_>) {
|
||||
use pstr_core::library::{Title, sort_name};
|
||||
|
||||
let built_with = (self.filter, self.sort, self.grouped, inputs.names);
|
||||
if !self.stale && self.query == inputs.query && self.built_with == Some(built_with) {
|
||||
return;
|
||||
}
|
||||
let index_of = |title: &pstr_core::library::Title| {
|
||||
library
|
||||
let metadata = inputs.metadata;
|
||||
let found = |title: &Title| {
|
||||
metadata
|
||||
.get(&title.key)
|
||||
.and_then(|record| record.metadata.as_ref())
|
||||
};
|
||||
let name = |title: &Title| ui::title_name(title, metadata, inputs.names).to_owned();
|
||||
|
||||
if self.stale {
|
||||
let all: Vec<&Title> = library.titles.iter().collect();
|
||||
self.franchises = pstr_core::franchise::group(&all, metadata)
|
||||
.into_iter()
|
||||
.filter(|franchise| franchise.members.len() > 1)
|
||||
.flat_map(|franchise| {
|
||||
let keys: Vec<String> = franchise
|
||||
.members
|
||||
.iter()
|
||||
.map(|&index| all[index].key.clone())
|
||||
.collect();
|
||||
keys.clone().into_iter().map(move |key| (key, keys.clone()))
|
||||
})
|
||||
.collect();
|
||||
let index: HashMap<&str, usize> = library
|
||||
.titles
|
||||
.iter()
|
||||
.position(|candidate| std::ptr::eq(candidate, title))
|
||||
};
|
||||
let mut matches: Vec<&pstr_core::library::Title> = library
|
||||
.search(query)
|
||||
.enumerate()
|
||||
.map(|(at, title)| (title.key.as_str(), at))
|
||||
.collect();
|
||||
self.shelves = pstr_core::shelves::pick(&library.titles, metadata, SHELVES)
|
||||
.into_iter()
|
||||
.map(|shelf| {
|
||||
let indices = shelf
|
||||
.keys
|
||||
.iter()
|
||||
.filter_map(|key| index.get(key.as_str()).copied())
|
||||
.collect();
|
||||
(shelf.label, indices)
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
|
||||
// A search finds a title by the provider's names for it as well as
|
||||
// the share's: a folder called `Sousou no Frieren` is found by typing
|
||||
// "Frieren: Beyond".
|
||||
let needle = inputs.query.trim().to_lowercase();
|
||||
let by_files: std::collections::HashSet<*const Title> = library
|
||||
.search(inputs.query)
|
||||
.into_iter()
|
||||
.filter(|title| self.filter.admits(title))
|
||||
.map(|title| title as *const Title)
|
||||
.collect();
|
||||
let mut titles: Vec<(usize, &Title)> = library
|
||||
.titles
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, title)| {
|
||||
by_files.contains(&(*title as *const Title))
|
||||
|| found(title).is_some_and(|found| {
|
||||
std::iter::once(found.name.as_str())
|
||||
.chain(found.original_name.as_deref())
|
||||
.chain(
|
||||
found
|
||||
.details
|
||||
.as_ref()
|
||||
.and_then(|details| details.romaji.as_deref()),
|
||||
)
|
||||
.any(|name| name.to_lowercase().contains(&needle))
|
||||
})
|
||||
})
|
||||
.filter(|(_, title)| self.filter.admits(title))
|
||||
.collect();
|
||||
titles.sort_by_cached_key(|(_, title)| sort_name(&name(title)));
|
||||
|
||||
// Each entry is the tile and every title it stands for.
|
||||
let entries: Vec<(usize, Vec<usize>)> = if self.grouped {
|
||||
let refs: Vec<&Title> = titles.iter().map(|(_, title)| *title).collect();
|
||||
pstr_core::franchise::group(&refs, metadata)
|
||||
.into_iter()
|
||||
.map(|franchise| {
|
||||
let lead = titles[franchise.lead(&refs)].0;
|
||||
let members = franchise
|
||||
.members
|
||||
.iter()
|
||||
.map(|&member| titles[member].0)
|
||||
.collect();
|
||||
(lead, members)
|
||||
})
|
||||
.collect()
|
||||
} else {
|
||||
titles
|
||||
.iter()
|
||||
.map(|&(index, _)| (index, vec![index]))
|
||||
.collect()
|
||||
};
|
||||
let mut entries = entries;
|
||||
let titles_of = |members: &[usize]| -> Vec<&Title> {
|
||||
members
|
||||
.iter()
|
||||
.map(|&index| &library.titles[index])
|
||||
.collect()
|
||||
};
|
||||
// Every sort is stable over the name order above, so ties and the
|
||||
// undated, unrated and unplayed keep their alphabetical order.
|
||||
match self.sort {
|
||||
Sort::Name => {}
|
||||
// Stable, so titles never played keep their alphabetical order
|
||||
// after the ones that have been.
|
||||
Sort::Recent => matches.sort_by_key(|title| std::cmp::Reverse(title.last_played())),
|
||||
Sort::Year => matches.sort_by_key(|title| std::cmp::Reverse(title.year.unwrap_or(0))),
|
||||
Sort::Recent => entries.sort_by_key(|(_, members)| {
|
||||
std::cmp::Reverse(
|
||||
titles_of(members)
|
||||
.iter()
|
||||
.map(|title| title.last_played())
|
||||
.max(),
|
||||
)
|
||||
}),
|
||||
Sort::Added => entries.sort_by_key(|(_, members)| {
|
||||
std::cmp::Reverse(
|
||||
titles_of(members)
|
||||
.iter()
|
||||
.filter_map(|title| inputs.added.get(&title.key))
|
||||
.max()
|
||||
.copied(),
|
||||
)
|
||||
}),
|
||||
Sort::Release => entries.sort_by_cached_key(|(_, members)| {
|
||||
std::cmp::Reverse(
|
||||
titles_of(members)
|
||||
.iter()
|
||||
.map(|title| pstr_core::franchise::release_key(title, metadata))
|
||||
// `~` is how the key says "undated"; it sorts last
|
||||
// here rather than first.
|
||||
.filter(|key| key != "~")
|
||||
.max(),
|
||||
)
|
||||
}),
|
||||
Sort::Rating => entries.sort_by_key(|(lead, _)| {
|
||||
std::cmp::Reverse(
|
||||
found(&library.titles[*lead])
|
||||
.and_then(|found| found.rating)
|
||||
.map(|rating| (rating * 100.0) as i64),
|
||||
)
|
||||
}),
|
||||
Sort::Popularity => entries.sort_by_key(|(lead, _)| {
|
||||
std::cmp::Reverse(
|
||||
found(&library.titles[*lead])
|
||||
.and_then(|found| found.details.as_ref())
|
||||
.and_then(|details| details.popularity),
|
||||
)
|
||||
}),
|
||||
}
|
||||
self.matches = matches.into_iter().filter_map(index_of).collect();
|
||||
self.built_with = (self.filter, self.sort);
|
||||
|
||||
self.folded = entries
|
||||
.iter()
|
||||
.filter(|(_, members)| members.len() > 1)
|
||||
.map(|(lead, members)| (*lead, members.len() - 1))
|
||||
.collect();
|
||||
self.matches = entries.into_iter().map(|(lead, _)| lead).collect();
|
||||
self.built_with = Some(built_with);
|
||||
if self.stale {
|
||||
self.history = ui::history::entries(library);
|
||||
let index_of = |title: &Title| {
|
||||
library
|
||||
.titles
|
||||
.iter()
|
||||
.position(|candidate| std::ptr::eq(candidate, title))
|
||||
};
|
||||
self.resumable = library
|
||||
.continue_watching()
|
||||
.into_iter()
|
||||
.filter_map(index_of)
|
||||
.collect();
|
||||
}
|
||||
self.query = query.to_owned();
|
||||
self.query = inputs.query.to_owned();
|
||||
self.stale = false;
|
||||
}
|
||||
}
|
||||
@@ -428,6 +644,8 @@ pub struct App {
|
||||
pub posters: ImageCache,
|
||||
/// What the providers have said, keyed by title key.
|
||||
pub metadata: HashMap<String, MetadataRecord>,
|
||||
/// When each title last gained a file, by key — for "Recently added".
|
||||
pub added: HashMap<String, i64>,
|
||||
/// What they said about the episodes under those titles.
|
||||
pub episodes: HashMap<String, EpisodeGuide>,
|
||||
pub settings: MetadataConfig,
|
||||
@@ -531,6 +749,7 @@ impl App {
|
||||
thumbs: ImageCache::default(),
|
||||
posters: ImageCache::default(),
|
||||
metadata: HashMap::new(),
|
||||
added: HashMap::new(),
|
||||
episodes: HashMap::new(),
|
||||
settings,
|
||||
api_key: String::new(),
|
||||
@@ -612,8 +831,9 @@ impl App {
|
||||
self.connecting = false;
|
||||
self.note(ctx, format!("could not open the shares: {error}"), true);
|
||||
}
|
||||
Event::LibraryLoaded(library) => {
|
||||
Event::LibraryLoaded(library, added) => {
|
||||
self.library = library;
|
||||
self.added = added;
|
||||
self.loaded = true;
|
||||
self.view.stale = true;
|
||||
}
|
||||
@@ -678,6 +898,8 @@ impl App {
|
||||
self.posters.forget(&key);
|
||||
}
|
||||
self.metadata = records;
|
||||
// Names, franchises and shelves all come from it.
|
||||
self.view.stale = true;
|
||||
}
|
||||
Event::EpisodeMetadata(episodes) => self.episodes = episodes,
|
||||
Event::MetadataConfig(config) => {
|
||||
@@ -975,6 +1197,7 @@ impl App {
|
||||
posters: &mut self.posters,
|
||||
metadata: &self.metadata,
|
||||
episodes: &self.episodes,
|
||||
names: self.engine.appearance().names,
|
||||
}
|
||||
.still(&title.key, episode)
|
||||
});
|
||||
@@ -1220,6 +1443,7 @@ impl App {
|
||||
self.view.filter = filter;
|
||||
self.view.sort = sort;
|
||||
}
|
||||
Action::SetGrouped(grouped) => self.view.grouped = grouped,
|
||||
Action::Back => match self.page {
|
||||
Page::Title(_) => self.page = Page::Library,
|
||||
// Back out of a search before out of anything else: it is the
|
||||
@@ -1652,6 +1876,7 @@ impl eframe::App for App {
|
||||
posters,
|
||||
metadata,
|
||||
episodes,
|
||||
names: engine.appearance().names,
|
||||
},
|
||||
open: *episode_drawer,
|
||||
});
|
||||
@@ -1750,7 +1975,15 @@ impl eframe::App for App {
|
||||
});
|
||||
self.search = search;
|
||||
self.focus_search = false;
|
||||
self.view.refresh(&self.library, &self.search);
|
||||
self.view.refresh(
|
||||
&self.library,
|
||||
ViewInputs {
|
||||
query: &self.search,
|
||||
metadata: &self.metadata,
|
||||
names: self.engine.appearance().names,
|
||||
added: &self.added,
|
||||
},
|
||||
);
|
||||
|
||||
let App {
|
||||
engine,
|
||||
@@ -1836,6 +2069,7 @@ impl eframe::App for App {
|
||||
posters: &mut *posters,
|
||||
metadata,
|
||||
episodes,
|
||||
names: engine.appearance().names,
|
||||
};
|
||||
match page {
|
||||
Page::Library => ui::library::show(
|
||||
@@ -1846,6 +2080,7 @@ impl eframe::App for App {
|
||||
view,
|
||||
loaded: *loaded,
|
||||
search,
|
||||
tiles: engine.appearance().tiles,
|
||||
},
|
||||
&mut actions,
|
||||
),
|
||||
@@ -1854,6 +2089,7 @@ impl eframe::App for App {
|
||||
&mut art,
|
||||
library,
|
||||
key,
|
||||
view.franchises.get(key.as_str()).map(Vec::as_slice),
|
||||
ui::title::OfflineView {
|
||||
downloads,
|
||||
files: offline_files,
|
||||
@@ -1883,6 +2119,7 @@ impl eframe::App for App {
|
||||
posters,
|
||||
metadata,
|
||||
episodes,
|
||||
names: engine.appearance().names,
|
||||
};
|
||||
ui::matcher::show(ctx, open, &mut art, settings.provider, &mut actions);
|
||||
}
|
||||
@@ -2036,7 +2273,8 @@ fn crawl_label(progress: &std::collections::BTreeMap<String, usize>) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Titles whose tile art is not what it was.
|
||||
/// Texture keys whose picture is not what it was: a title's tile art, its cover
|
||||
/// and its wide art each.
|
||||
///
|
||||
/// Compared by URL: the same URL is the same picture, and anything else —
|
||||
/// a different one, a new one, or none any more — has to be fetched or
|
||||
@@ -2045,19 +2283,27 @@ fn changed_art(
|
||||
before: &HashMap<String, MetadataRecord>,
|
||||
after: &HashMap<String, MetadataRecord>,
|
||||
) -> Vec<String> {
|
||||
let url = |records: &HashMap<String, MetadataRecord>, key: &str| {
|
||||
records
|
||||
.get(key)
|
||||
.and_then(|record| record.metadata.as_ref())
|
||||
.and_then(|metadata| metadata.tile_art())
|
||||
.map(|(url, _)| url.to_owned())
|
||||
// Every picture a title is drawn with, in the order of the keys below.
|
||||
let urls = |records: &HashMap<String, MetadataRecord>, key: &str| {
|
||||
let found = records.get(key).and_then(|record| record.metadata.as_ref());
|
||||
[
|
||||
found
|
||||
.and_then(|metadata| metadata.tile_art())
|
||||
.map(|(url, _)| url.to_owned()),
|
||||
found.and_then(|metadata| metadata.poster_url.clone()),
|
||||
found.and_then(|metadata| metadata.wide_art().map(str::to_owned)),
|
||||
]
|
||||
};
|
||||
let mut keys: Vec<String> = before
|
||||
.keys()
|
||||
.chain(after.keys())
|
||||
.filter(|key| url(before, key) != url(after, key))
|
||||
.cloned()
|
||||
.collect();
|
||||
let mut keys: Vec<String> = Vec::new();
|
||||
for key in before.keys().chain(after.keys()) {
|
||||
let (old, new) = (urls(before, key), urls(after, key));
|
||||
let texture_keys = [key.clone(), ui::poster_key(key), ui::wide_key(key)];
|
||||
for ((old, new), texture) in old.iter().zip(&new).zip(texture_keys) {
|
||||
if old != new {
|
||||
keys.push(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
keys.sort_unstable();
|
||||
keys.dedup();
|
||||
keys
|
||||
@@ -2306,6 +2552,7 @@ mod tests {
|
||||
genres: Vec::new(),
|
||||
episodes: None,
|
||||
url: None,
|
||||
details: None,
|
||||
});
|
||||
(
|
||||
key.into(),
|
||||
@@ -2395,9 +2642,20 @@ mod tests {
|
||||
record("added", Some("w")),
|
||||
]
|
||||
.into();
|
||||
// The tile and the cover are both drawn from the poster here; the
|
||||
// wide art has nothing to be.
|
||||
assert_eq!(
|
||||
changed_art(&before, &after),
|
||||
vec!["added", "dropped", "found", "moved"]
|
||||
vec![
|
||||
"added",
|
||||
"dropped",
|
||||
"found",
|
||||
"moved",
|
||||
"poster:added",
|
||||
"poster:dropped",
|
||||
"poster:found",
|
||||
"poster:moved"
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -160,6 +160,11 @@ struct PartialMarker {
|
||||
/// difference is VRAM held for every title in the library.
|
||||
const THUMBNAIL_MAX_EDGE: u32 = 640;
|
||||
|
||||
/// The longest edge of a picture drawn across the whole window. 1920 is what
|
||||
/// a provider's fanart is, so nothing is scaled up and a 4K screen gets the
|
||||
/// best there is.
|
||||
pub const WIDE_MAX_EDGE: u32 = 1920;
|
||||
|
||||
/// What the background side tells the UI.
|
||||
pub enum Event {
|
||||
/// The share list changed on disk.
|
||||
@@ -175,8 +180,9 @@ pub enum Event {
|
||||
},
|
||||
/// Shares could not be opened at all.
|
||||
ConnectFailed(String),
|
||||
/// The catalog was re-read.
|
||||
LibraryLoaded(Library),
|
||||
/// The catalog was re-read: the library, and when each title last
|
||||
/// gained a file.
|
||||
LibraryLoaded(Library, HashMap<String, i64>),
|
||||
/// A crawl finished for one share.
|
||||
Crawled {
|
||||
share_id: String,
|
||||
@@ -739,15 +745,16 @@ impl Engine {
|
||||
self.runtime.spawn_blocking(move || {
|
||||
let result = {
|
||||
let catalog = engine.catalog.lock();
|
||||
catalog
|
||||
.all_files()
|
||||
.and_then(|files| Ok((files, catalog.all_watch_states()?)))
|
||||
catalog.all_files().and_then(|files| {
|
||||
Ok((files, catalog.all_watch_states()?, catalog.first_seen()?))
|
||||
})
|
||||
};
|
||||
match result {
|
||||
Ok((files, watch)) => {
|
||||
Ok((files, watch, first_seen)) => {
|
||||
let library = Library::build(files, &watch);
|
||||
let targets = download_targets(&library);
|
||||
engine.emit(Event::LibraryLoaded(library));
|
||||
let added = library.added_at(&first_seen);
|
||||
engine.emit(Event::LibraryLoaded(library, added));
|
||||
engine.refresh_offline(Some(targets));
|
||||
}
|
||||
Err(error) => engine.fail("read the catalog", error),
|
||||
@@ -1914,7 +1921,14 @@ impl Engine {
|
||||
}
|
||||
};
|
||||
|
||||
let pending = pstr_meta::service::plan(titles, &stored, &enriched, provider, force);
|
||||
let pending = pstr_meta::service::plan(
|
||||
titles,
|
||||
&stored,
|
||||
&enriched,
|
||||
provider,
|
||||
service.has_details(),
|
||||
force,
|
||||
);
|
||||
if pending.is_empty() {
|
||||
return self.emit(Event::Status("everything is already matched".into()));
|
||||
}
|
||||
@@ -2088,15 +2102,26 @@ impl Engine {
|
||||
/// paths invalidates by itself and the same picture shared by two titles is
|
||||
/// fetched once.
|
||||
pub fn request_poster(&self, title_key: String, url: String) {
|
||||
self.request_art(title_key, url, THUMBNAIL_MAX_EDGE);
|
||||
}
|
||||
|
||||
/// [`Engine::request_poster`], for a picture drawn across the window —
|
||||
/// the library's hero, the title page's band — kept at up to `max_edge`
|
||||
/// pixels rather than a tile's 640. A 640 px still stretched to 1600 was
|
||||
/// most of why those looked soft.
|
||||
pub fn request_art(&self, title_key: String, url: String, max_edge: u32) {
|
||||
let engine = self.clone();
|
||||
let path = self
|
||||
.dirs
|
||||
.poster_cache()
|
||||
.join(format!("{}.img", digest(&url)));
|
||||
// A size of its own on disk: the tile-sized copy of the same URL is
|
||||
// already there under the plain name, scaled down.
|
||||
let name = match max_edge {
|
||||
THUMBNAIL_MAX_EDGE => format!("{}.img", digest(&url)),
|
||||
edge => format!("{}-{edge}.img", digest(&url)),
|
||||
};
|
||||
let path = self.dirs.poster_cache().join(name);
|
||||
|
||||
self.runtime.spawn(async move {
|
||||
if let Ok(bytes) = tokio::fs::read(&path).await {
|
||||
match decode_thumbnail(&bytes) {
|
||||
match decode_scaled(&bytes, max_edge) {
|
||||
Ok(decoded) => {
|
||||
if let Some(smaller) = &decoded.smaller {
|
||||
store_image(&path, smaller).await;
|
||||
@@ -2123,7 +2148,7 @@ impl Engine {
|
||||
}
|
||||
};
|
||||
|
||||
match decode_thumbnail(&bytes) {
|
||||
match decode_scaled(&bytes, max_edge) {
|
||||
Ok(decoded) => {
|
||||
store_image(&path, decoded.smaller.as_deref().unwrap_or(&bytes)).await;
|
||||
engine.emit(Event::Poster {
|
||||
@@ -2299,9 +2324,14 @@ struct Decoded {
|
||||
/// copy is handed back so the cache holds that instead, and the next launch
|
||||
/// decodes a picture already the size it is drawn at.
|
||||
fn decode_thumbnail(bytes: &[u8]) -> anyhow::Result<Decoded> {
|
||||
decode_scaled(bytes, THUMBNAIL_MAX_EDGE)
|
||||
}
|
||||
|
||||
/// [`decode_thumbnail`], to `max_edge` rather than a tile's size.
|
||||
fn decode_scaled(bytes: &[u8], max_edge: u32) -> anyhow::Result<Decoded> {
|
||||
let decoded = image::load_from_memory(bytes)?;
|
||||
let (decoded, smaller) = if decoded.width().max(decoded.height()) > THUMBNAIL_MAX_EDGE {
|
||||
let scaled = decoded.thumbnail(THUMBNAIL_MAX_EDGE, THUMBNAIL_MAX_EDGE);
|
||||
let (decoded, smaller) = if decoded.width().max(decoded.height()) > max_edge {
|
||||
let scaled = decoded.thumbnail(max_edge, max_edge);
|
||||
let encoded = encode_for_cache(&scaled);
|
||||
(scaled, encoded)
|
||||
} else {
|
||||
|
||||
@@ -35,6 +35,12 @@ pub const CARD_WIDTH: f32 = 232.0;
|
||||
/// Video stills are 16:9. A poster shape would letterbox every one of them.
|
||||
pub const CARD_ASPECT: f32 = 9.0 / 16.0;
|
||||
pub const CARD_GAP: f32 = 14.0;
|
||||
/// The poster grid's minimum width: narrower than a still, because a cover is
|
||||
/// read by its art rather than by detail, and six across a laptop screen is
|
||||
/// what makes a wall of covers look like a shelf.
|
||||
pub const POSTER_WIDTH: f32 = 168.0;
|
||||
/// Covers are 2:3.
|
||||
pub const POSTER_ASPECT: f32 = 3.0 / 2.0;
|
||||
|
||||
/// The type ramp, named once.
|
||||
///
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! The library page: what to watch, as a wall of stills.
|
||||
|
||||
use pstr_core::appearance::Tiles;
|
||||
use pstr_core::library::{Library, Title, TitleKind};
|
||||
|
||||
use crate::app::{Action, Filter, LibraryView, Page, Sort};
|
||||
@@ -16,6 +17,8 @@ pub struct Shelves<'a> {
|
||||
/// Whether the catalog has been read yet.
|
||||
pub loaded: bool,
|
||||
pub search: &'a str,
|
||||
/// The grid's shape.
|
||||
pub tiles: Tiles,
|
||||
}
|
||||
|
||||
pub fn show(ui: &mut egui::Ui, art: &mut Art<'_>, shelves: Shelves<'_>, actions: &mut Vec<Action>) {
|
||||
@@ -24,6 +27,7 @@ pub fn show(ui: &mut egui::Ui, art: &mut Art<'_>, shelves: Shelves<'_>, actions:
|
||||
view,
|
||||
loaded,
|
||||
search,
|
||||
tiles,
|
||||
} = shelves;
|
||||
if !loaded {
|
||||
return placeholder(ui);
|
||||
@@ -55,6 +59,16 @@ pub fn show(ui: &mut egui::Ui, art: &mut Art<'_>, shelves: Shelves<'_>, actions:
|
||||
continue_row(ui, art, &resumable, actions);
|
||||
ui.add_space(theme::space::XL);
|
||||
}
|
||||
// Only over the whole library: under a filter, a shelf of
|
||||
// titles the grid below is hiding reads as the filter not
|
||||
// working.
|
||||
if view.filter == Filter::All {
|
||||
for (label, indices) in &view.shelves {
|
||||
ui::section(ui, label);
|
||||
shelf_row(ui, art, label, &pick(indices), tiles, actions);
|
||||
ui.add_space(theme::space::XL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
@@ -86,7 +100,7 @@ pub fn show(ui: &mut egui::Ui, art: &mut Art<'_>, shelves: Shelves<'_>, actions:
|
||||
return;
|
||||
}
|
||||
|
||||
grid(ui, art, &matches, actions);
|
||||
grid(ui, art, &matches, view, tiles, actions);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -121,7 +135,7 @@ fn featured<'a>(
|
||||
metadata
|
||||
.get(&title.key)
|
||||
.and_then(|record| record.metadata.as_ref())
|
||||
.is_some_and(|found| found.backdrop_url.is_some())
|
||||
.is_some_and(|found| found.wide_art().is_some())
|
||||
})
|
||||
.collect();
|
||||
if pictured.is_empty() {
|
||||
@@ -144,7 +158,7 @@ fn hero(ui: &mut egui::Ui, art: &mut Art<'_>, title: &Title, actions: &mut Vec<A
|
||||
return;
|
||||
}
|
||||
let radius = egui::CornerRadius::same(theme::radius::LG);
|
||||
let picture = art.of(title);
|
||||
let picture = art.wide(title);
|
||||
let found = art
|
||||
.metadata
|
||||
.get(&title.key)
|
||||
@@ -252,7 +266,7 @@ fn hero(ui: &mut egui::Ui, art: &mut Art<'_>, title: &Title, actions: &mut Vec<A
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
theme::Role::Display
|
||||
.rich(&title.name)
|
||||
.rich(art.name(title))
|
||||
.strong()
|
||||
.color(theme::text()),
|
||||
)
|
||||
@@ -266,24 +280,20 @@ fn hero(ui: &mut egui::Ui, art: &mut Art<'_>, title: &Title, actions: &mut Vec<A
|
||||
}
|
||||
}
|
||||
|
||||
/// The filter pills and the order, at the right of the grid's heading.
|
||||
/// The filter pills, the order and the grouping, at the right of the grid's
|
||||
/// heading.
|
||||
fn shelf_controls(ui: &mut egui::Ui, view: &LibraryView, actions: &mut Vec<Action>) {
|
||||
// Right to left: the order first, so it ends up last.
|
||||
let sort = egui::ComboBox::from_id_salt("library-sort")
|
||||
.selected_text(match view.sort {
|
||||
Sort::Name => "A – Z",
|
||||
Sort::Recent => "Recently watched",
|
||||
Sort::Year => "Newest",
|
||||
})
|
||||
.selected_text(view.sort.label())
|
||||
.width(150.0)
|
||||
.show_ui(ui, |ui| {
|
||||
let mut picked = None;
|
||||
for (sort, label) in [
|
||||
(Sort::Name, "A – Z"),
|
||||
(Sort::Recent, "Recently watched"),
|
||||
(Sort::Year, "Newest"),
|
||||
] {
|
||||
if ui.selectable_label(view.sort == sort, label).clicked() {
|
||||
for sort in Sort::ALL {
|
||||
if ui
|
||||
.selectable_label(view.sort == sort, sort.label())
|
||||
.clicked()
|
||||
{
|
||||
picked = Some(sort);
|
||||
}
|
||||
}
|
||||
@@ -292,6 +302,19 @@ fn shelf_controls(ui: &mut egui::Ui, view: &LibraryView, actions: &mut Vec<Actio
|
||||
if let Some(Some(sort)) = sort.inner {
|
||||
actions.push(Action::SetShelf(view.filter, sort));
|
||||
}
|
||||
ui.add_space(theme::space::S);
|
||||
let mut grouped = view.grouped;
|
||||
if ui
|
||||
.toggle_value(&mut grouped, egui_phosphor::regular::STACK)
|
||||
.on_hover_text(if view.grouped {
|
||||
"One tile per franchise. Click to show every title"
|
||||
} else {
|
||||
"Every title. Click to fold each franchise into one tile"
|
||||
})
|
||||
.changed()
|
||||
{
|
||||
actions.push(Action::SetGrouped(grouped));
|
||||
}
|
||||
ui.add_space(theme::space::L);
|
||||
if let Some(filter) = ui::widgets::segmented(
|
||||
ui,
|
||||
@@ -308,6 +331,57 @@ fn shelf_controls(ui: &mut egui::Ui, view: &LibraryView, actions: &mut Vec<Actio
|
||||
}
|
||||
}
|
||||
|
||||
/// One shelf: titles that share something, scrolling sideways, in the grid's
|
||||
/// own shape.
|
||||
fn shelf_row(
|
||||
ui: &mut egui::Ui,
|
||||
art: &mut Art<'_>,
|
||||
label: &str,
|
||||
titles: &[&Title],
|
||||
tiles: Tiles,
|
||||
actions: &mut Vec<Action>,
|
||||
) {
|
||||
let (width, aspect) = tile_shape(tiles);
|
||||
egui::ScrollArea::horizontal()
|
||||
.id_salt(("shelf", label))
|
||||
.auto_shrink([false, true])
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::CARD_GAP;
|
||||
for title in titles {
|
||||
let picture = match tiles {
|
||||
Tiles::Posters => art.poster(title),
|
||||
Tiles::Stills => art.of(title),
|
||||
};
|
||||
let response = ui::card(
|
||||
ui,
|
||||
Card {
|
||||
art: picture,
|
||||
name: art.name(title),
|
||||
subtitle: subtitle(title),
|
||||
progress: title.resume().and_then(|e| e.progress()).map(|v| v as f32),
|
||||
badge: None,
|
||||
width,
|
||||
aspect,
|
||||
},
|
||||
);
|
||||
tile_menu(&response, title, false, actions);
|
||||
if response.clicked() {
|
||||
actions.push(Action::Goto(Page::Title(title.key.clone())));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// The minimum width and the picture's shape of a tile.
|
||||
fn tile_shape(tiles: Tiles) -> (f32, f32) {
|
||||
match tiles {
|
||||
Tiles::Posters => (theme::POSTER_WIDTH, theme::POSTER_ASPECT),
|
||||
Tiles::Stills => (theme::CARD_WIDTH, theme::CARD_ASPECT),
|
||||
}
|
||||
}
|
||||
|
||||
/// The top shelf: one card per part-watched title, scrolling sideways.
|
||||
fn continue_row(
|
||||
ui: &mut egui::Ui,
|
||||
@@ -337,17 +411,20 @@ fn continue_row(
|
||||
})
|
||||
.unwrap_or_else(|| episode.label());
|
||||
|
||||
let picture = art.of(title);
|
||||
let response = ui::card(
|
||||
ui,
|
||||
Card {
|
||||
art: art.of(title),
|
||||
name: &title.name,
|
||||
art: picture,
|
||||
name: art.name(title),
|
||||
subtitle: remaining,
|
||||
progress: episode.progress().map(|value| value as f32),
|
||||
badge: episode.numbering(),
|
||||
// A shelf that scrolls sideways has no right edge
|
||||
// to reach, so nothing to flex to.
|
||||
// to reach, so nothing to flex to. Always a
|
||||
// still: it is a frame from where they stopped.
|
||||
width: theme::CARD_WIDTH,
|
||||
aspect: theme::CARD_ASPECT,
|
||||
},
|
||||
);
|
||||
tile_menu(&response, title, true, actions);
|
||||
@@ -361,10 +438,18 @@ fn continue_row(
|
||||
}
|
||||
|
||||
/// Every title, wrapped to the window.
|
||||
fn grid(ui: &mut egui::Ui, art: &mut Art<'_>, titles: &[&Title], actions: &mut Vec<Action>) {
|
||||
let grid = ui::columns(ui.available_width());
|
||||
let row_height = ui::card_height(grid.width);
|
||||
for row in titles.chunks(grid.columns) {
|
||||
fn grid(
|
||||
ui: &mut egui::Ui,
|
||||
art: &mut Art<'_>,
|
||||
titles: &[&Title],
|
||||
view: &LibraryView,
|
||||
tiles: Tiles,
|
||||
actions: &mut Vec<Action>,
|
||||
) {
|
||||
let (minimum, aspect) = tile_shape(tiles);
|
||||
let grid = ui::columns_of(ui.available_width(), minimum);
|
||||
let row_height = ui::card_height(grid.width, aspect);
|
||||
for (row, chunk) in titles.chunks(grid.columns).enumerate() {
|
||||
// A row scrolled out of view is only its height. Laying it out anyway
|
||||
// costs a subtitle and an artwork lookup per card per frame, and while
|
||||
// a film plays under the transport bar a frame is every frame.
|
||||
@@ -385,18 +470,32 @@ fn grid(ui: &mut egui::Ui, art: &mut Art<'_>, titles: &[&Title], actions: &mut V
|
||||
// the difference times the column count is a visible drift towards
|
||||
// the left edge.
|
||||
ui.spacing_mut().item_spacing.x = theme::CARD_GAP;
|
||||
for title in row {
|
||||
for (column, title) in chunk.iter().enumerate() {
|
||||
let picture = match tiles {
|
||||
Tiles::Posters => art.poster(title),
|
||||
Tiles::Stills => art.of(title),
|
||||
};
|
||||
let folded = view
|
||||
.matches
|
||||
.get(row * grid.columns + column)
|
||||
.and_then(|index| view.folded.get(index))
|
||||
.copied();
|
||||
let response = ui::card(
|
||||
ui,
|
||||
Card {
|
||||
art: art.of(title),
|
||||
name: &title.name,
|
||||
subtitle: subtitle(title),
|
||||
art: picture,
|
||||
name: art.name(title),
|
||||
subtitle: match folded {
|
||||
Some(more) => format!("{} · +{more} more", subtitle(title)),
|
||||
None => subtitle(title),
|
||||
},
|
||||
progress: title.resume().and_then(|e| e.progress()).map(|v| v as f32),
|
||||
// What a film is says itself in the subtitle below the
|
||||
// card; a second `Film` over the poster is noise.
|
||||
badge: None,
|
||||
// card; a second `Film` over the poster is noise. A
|
||||
// folded franchise says how much is under it.
|
||||
badge: folded.map(|more| format!("+{more}")),
|
||||
width: grid.width,
|
||||
aspect,
|
||||
},
|
||||
);
|
||||
tile_menu(&response, title, false, actions);
|
||||
@@ -517,7 +616,7 @@ fn subtitle(title: &Title) -> String {
|
||||
/// fraction is a flash of something false.
|
||||
fn placeholder(ui: &mut egui::Ui) {
|
||||
let grid = ui::columns(ui.available_width());
|
||||
let height = ui::card_height(grid.width);
|
||||
let height = ui::card_height(grid.width, theme::CARD_ASPECT);
|
||||
ui::section(ui, "Library");
|
||||
for _ in 0..2 {
|
||||
ui.horizontal(|ui| {
|
||||
|
||||
+108
-11
@@ -20,9 +20,9 @@ use std::collections::HashMap;
|
||||
|
||||
use egui::{Align2, Color32, CornerRadius, Rect, Sense, Stroke, Vec2};
|
||||
use pstr_core::library::{Episode, Title};
|
||||
use pstr_core::metadata::{ArtShape, EpisodeGuide, EpisodeMetadata, MetadataRecord};
|
||||
use pstr_core::metadata::{ArtShape, EpisodeGuide, EpisodeMetadata, MetadataRecord, TitleNames};
|
||||
|
||||
use crate::engine::{Engine, ImageCache, thumbnail_key};
|
||||
use crate::engine::{Engine, ImageCache, WIDE_MAX_EDGE, thumbnail_key};
|
||||
use crate::theme;
|
||||
|
||||
/// Everything the pages need to draw one title's picture.
|
||||
@@ -40,6 +40,22 @@ pub struct Art<'a> {
|
||||
pub metadata: &'a HashMap<String, MetadataRecord>,
|
||||
/// What they said about the episodes under those titles.
|
||||
pub episodes: &'a HashMap<String, EpisodeGuide>,
|
||||
/// Which name a title goes by.
|
||||
pub names: TitleNames,
|
||||
}
|
||||
|
||||
/// The name to show for `title`: the provider's, in the form the viewer
|
||||
/// picked, else the share's.
|
||||
pub fn title_name<'a>(
|
||||
title: &'a Title,
|
||||
metadata: &'a HashMap<String, MetadataRecord>,
|
||||
names: TitleNames,
|
||||
) -> &'a str {
|
||||
metadata
|
||||
.get(&title.key)
|
||||
.and_then(|record| record.metadata.as_ref())
|
||||
.and_then(|found| found.display_name(names))
|
||||
.unwrap_or(&title.name)
|
||||
}
|
||||
|
||||
impl Art<'_> {
|
||||
@@ -74,6 +90,58 @@ impl Art<'_> {
|
||||
.texture(&thumbnail_key(node), || engine.request_thumbnail(node))
|
||||
}
|
||||
|
||||
/// The name to show for `title`. See [`title_name`].
|
||||
pub fn name<'t>(&'t self, title: &'t Title) -> &'t str {
|
||||
title_name(title, self.metadata, self.names)
|
||||
}
|
||||
|
||||
/// A 2:3 cover for `title`, for the poster grid; whatever [`Art::of`]
|
||||
/// has when there is none.
|
||||
pub fn poster(&mut self, title: &Title) -> Option<(egui::TextureHandle, ArtShape)> {
|
||||
let url = self
|
||||
.metadata
|
||||
.get(&title.key)
|
||||
.and_then(|record| record.metadata.as_ref())
|
||||
.and_then(|metadata| metadata.poster_url.clone());
|
||||
if let Some(url) = url {
|
||||
let key = poster_key(&title.key);
|
||||
let engine = self.engine;
|
||||
if let Some(texture) = self
|
||||
.posters
|
||||
.texture(&key, || engine.request_poster(key.clone(), url))
|
||||
{
|
||||
return Some((texture, ArtShape::Portrait));
|
||||
}
|
||||
}
|
||||
self.of(title)
|
||||
}
|
||||
|
||||
/// Art for a strip across the whole window, at full size: fanart, else
|
||||
/// AniList's banner, else whatever [`Art::of`] has.
|
||||
///
|
||||
/// Its own texture rather than the tile's: a 640 px tile picture
|
||||
/// stretched to a 1600 px hero is soft, and a 1920 px one in every tile
|
||||
/// would be most of the texture budget.
|
||||
pub fn wide(&mut self, title: &Title) -> Option<(egui::TextureHandle, ArtShape)> {
|
||||
let url = self
|
||||
.metadata
|
||||
.get(&title.key)
|
||||
.and_then(|record| record.metadata.as_ref())
|
||||
.and_then(|metadata| metadata.wide_art())
|
||||
.map(str::to_owned);
|
||||
if let Some(url) = url {
|
||||
let key = wide_key(&title.key);
|
||||
let engine = self.engine;
|
||||
if let Some(texture) = self
|
||||
.posters
|
||||
.texture(&key, || engine.request_art(key.clone(), url, WIDE_MAX_EDGE))
|
||||
{
|
||||
return Some((texture, ArtShape::Landscape));
|
||||
}
|
||||
}
|
||||
self.of(title)
|
||||
}
|
||||
|
||||
/// The picture for a title, and how to fit it.
|
||||
///
|
||||
/// Provider artwork first, then Proton's still, then nothing. That order is
|
||||
@@ -104,6 +172,17 @@ impl Art<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The texture key of a title's cover, beside [`Art::of`]'s, which is the
|
||||
/// title key itself.
|
||||
pub fn poster_key(title_key: &str) -> String {
|
||||
format!("poster:{title_key}")
|
||||
}
|
||||
|
||||
/// The texture key of a title's full-size wide art.
|
||||
pub fn wide_key(title_key: &str) -> String {
|
||||
format!("wide:{title_key}")
|
||||
}
|
||||
|
||||
/// `1:03:47`, or `4:12` for anything under an hour.
|
||||
pub fn format_time(seconds: f64) -> String {
|
||||
if !seconds.is_finite() || seconds < 0.0 {
|
||||
@@ -492,6 +571,9 @@ pub struct Card<'a> {
|
||||
/// sideways-scrolling shelf has no edge to reach and passes
|
||||
/// [`theme::CARD_WIDTH`].
|
||||
pub width: f32,
|
||||
/// The picture's height over its width: [`theme::CARD_ASPECT`] for a
|
||||
/// still, [`theme::POSTER_ASPECT`] for a cover.
|
||||
pub aspect: f32,
|
||||
}
|
||||
|
||||
/// Two lines of name plus one of subtitle. Fixed, because the tile is allocated
|
||||
@@ -499,10 +581,10 @@ pub struct Card<'a> {
|
||||
/// different height by title length reads as broken.
|
||||
const CARD_TEXT_HEIGHT: f32 = 54.0;
|
||||
|
||||
/// How tall [`card`] draws a tile of this width, so a grid can step over rows
|
||||
/// it does not draw.
|
||||
pub fn card_height(width: f32) -> f32 {
|
||||
(width * theme::CARD_ASPECT).round() + CARD_TEXT_HEIGHT
|
||||
/// How tall [`card`] draws a tile of this width and shape, so a grid can step
|
||||
/// over rows it does not draw.
|
||||
pub fn card_height(width: f32, aspect: f32) -> f32 {
|
||||
(width * aspect).round() + CARD_TEXT_HEIGHT
|
||||
}
|
||||
|
||||
/// Draw one tile and report whether it was clicked.
|
||||
@@ -515,7 +597,10 @@ pub fn card_height(width: f32) -> f32 {
|
||||
/// reads as deliberate in a way a stretched poster does not.
|
||||
pub fn card(ui: &mut egui::Ui, card: Card<'_>) -> egui::Response {
|
||||
let width = card.width;
|
||||
let image_height = (width * theme::CARD_ASPECT).round();
|
||||
let image_height = (width * card.aspect).round();
|
||||
// A cover fitted into a still-shaped tile is drawn whole; into a tile its
|
||||
// own shape, it fills it like anything else.
|
||||
let fit = card.aspect < 1.0;
|
||||
let text_height = CARD_TEXT_HEIGHT;
|
||||
let radius = CornerRadius::same(theme::radius::MD);
|
||||
|
||||
@@ -574,7 +659,7 @@ pub fn card(ui: &mut egui::Ui, card: Card<'_>) -> egui::Response {
|
||||
.with_texture(texture.id(), cover_uv(size, image_rect.size())),
|
||||
);
|
||||
}
|
||||
Some((texture, ArtShape::Portrait)) => {
|
||||
Some((texture, ArtShape::Portrait)) if fit => {
|
||||
painter.add(
|
||||
egui::epaint::RectShape::filled(
|
||||
contain_rect(texture.size_vec2(), image_rect),
|
||||
@@ -587,6 +672,14 @@ pub fn card(ui: &mut egui::Ui, card: Card<'_>) -> egui::Response {
|
||||
),
|
||||
);
|
||||
}
|
||||
Some((texture, ArtShape::Portrait)) => {
|
||||
painter.add(
|
||||
egui::epaint::RectShape::filled(image_rect, radius, ink).with_texture(
|
||||
texture.id(),
|
||||
cover_uv(texture.size_vec2(), image_rect.size()),
|
||||
),
|
||||
);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
@@ -777,9 +870,13 @@ pub struct Grid {
|
||||
/// dead space at the right of every row, and on a wide window that reads as a
|
||||
/// layout that failed to line up rather than as a margin.
|
||||
pub fn columns(available: f32) -> Grid {
|
||||
let columns = (((available + theme::CARD_GAP) / (theme::CARD_WIDTH + theme::CARD_GAP)).floor()
|
||||
as usize)
|
||||
.max(1);
|
||||
columns_of(available, theme::CARD_WIDTH)
|
||||
}
|
||||
|
||||
/// [`columns`], for cards at least `minimum` wide.
|
||||
pub fn columns_of(available: f32, minimum: f32) -> Grid {
|
||||
let columns =
|
||||
(((available + theme::CARD_GAP) / (minimum + theme::CARD_GAP)).floor() as usize).max(1);
|
||||
// The gaps come out of the width before it is split. Floored, because a
|
||||
// fraction of a point times four columns is enough to push the last card
|
||||
// onto a row of its own. A window too narrow for even one full card gets a
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
//! that manages Proton Drive links, and a page that is half link management and
|
||||
//! half preferences is two pages.
|
||||
|
||||
use pstr_core::appearance::{Accent, Appearance, Flavor};
|
||||
use pstr_core::metadata::{MetadataConfig, ProviderId};
|
||||
use pstr_core::appearance::{Accent, Appearance, Flavor, Tiles};
|
||||
use pstr_core::metadata::{MetadataConfig, ProviderId, TitleNames};
|
||||
|
||||
use crate::app::Action;
|
||||
use crate::desktop_prefs::{CACHE_CHOICES, DesktopPrefs};
|
||||
@@ -102,6 +102,41 @@ fn appearance_form(ui: &mut egui::Ui, appearance: Appearance, actions: &mut Vec<
|
||||
}
|
||||
});
|
||||
|
||||
ui::widgets::settings_row(
|
||||
ui,
|
||||
"Library tiles",
|
||||
Some("Covers, or 16:9 stills. Covers are the art every matched title has."),
|
||||
|ui| {
|
||||
let choices: Vec<(Tiles, &str)> = Tiles::ALL
|
||||
.iter()
|
||||
.map(|tiles| (*tiles, tiles.label()))
|
||||
.collect();
|
||||
if let Some(tiles) = ui::widgets::segmented(ui, appearance.tiles, &choices) {
|
||||
actions.push(Action::SetAppearance(Appearance {
|
||||
tiles,
|
||||
..appearance
|
||||
}));
|
||||
}
|
||||
},
|
||||
);
|
||||
ui::widgets::settings_row(
|
||||
ui,
|
||||
"Title names",
|
||||
Some("The name a matched title goes by. Its other names still find it in search."),
|
||||
|ui| {
|
||||
let choices: Vec<(TitleNames, &str)> = TitleNames::ALL
|
||||
.iter()
|
||||
.map(|names| (*names, names.label()))
|
||||
.collect();
|
||||
if let Some(names) = ui::widgets::segmented(ui, appearance.names, &choices) {
|
||||
actions.push(Action::SetAppearance(Appearance {
|
||||
names,
|
||||
..appearance
|
||||
}));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let mut gradients = appearance.gradients;
|
||||
ui::widgets::settings_row(
|
||||
ui,
|
||||
|
||||
+125
-15
@@ -20,6 +20,7 @@ pub fn show(
|
||||
art: &mut Art<'_>,
|
||||
library: &Library,
|
||||
key: &str,
|
||||
franchise: Option<&[String]>,
|
||||
offline: OfflineView<'_>,
|
||||
actions: &mut Vec<Action>,
|
||||
) {
|
||||
@@ -41,6 +42,15 @@ pub fn show(
|
||||
header(ui, art, title, &offline, actions);
|
||||
ui.add_space(theme::space::XL);
|
||||
|
||||
if let Some(keys) = franchise {
|
||||
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);
|
||||
ui.add_space(theme::space::XL);
|
||||
}
|
||||
}
|
||||
|
||||
// One season at a time, picked from a row of pills, rather than
|
||||
// every season stacked as a collapsing header: a four-season show
|
||||
// was a page of headers to scroll past to reach the one being
|
||||
@@ -100,6 +110,60 @@ pub fn show(
|
||||
});
|
||||
}
|
||||
|
||||
/// 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(
|
||||
ui: &mut egui::Ui,
|
||||
art: &mut Art<'_>,
|
||||
current: &Title,
|
||||
members: &[&Title],
|
||||
actions: &mut Vec<Action>,
|
||||
) {
|
||||
egui::ScrollArea::horizontal()
|
||||
.id_salt(("franchise", ¤t.key))
|
||||
.auto_shrink([false, true])
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::CARD_GAP;
|
||||
for member in members {
|
||||
let here = member.key == current.key;
|
||||
let picture = art.poster(member);
|
||||
let found = art
|
||||
.metadata
|
||||
.get(&member.key)
|
||||
.and_then(|record| record.metadata.as_ref());
|
||||
let what = found
|
||||
.and_then(|found| found.details.as_ref())
|
||||
.and_then(|details| details.format_label())
|
||||
.unwrap_or(match member.kind {
|
||||
TitleKind::Series => "Series",
|
||||
TitleKind::Film => "Film",
|
||||
});
|
||||
let year = found
|
||||
.and_then(|found| found.year)
|
||||
.or(member.year)
|
||||
.map(|year| format!(" · {year}"))
|
||||
.unwrap_or_default();
|
||||
let response = ui::card(
|
||||
ui,
|
||||
Card {
|
||||
art: picture,
|
||||
name: art.name(member),
|
||||
subtitle: format!("{what}{year}"),
|
||||
progress: member.resume().and_then(|e| e.progress()).map(|v| v as f32),
|
||||
badge: here.then(|| "Here".to_owned()),
|
||||
width: 128.0,
|
||||
aspect: theme::POSTER_ASPECT,
|
||||
},
|
||||
);
|
||||
if !here && response.clicked() {
|
||||
actions.push(Action::Goto(Page::Title(member.key.clone())));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// A title's poster, at the poster's own shape, with how far into it the
|
||||
/// viewer is along its foot.
|
||||
fn poster(ui: &mut egui::Ui, texture: &egui::TextureHandle, progress: Option<f64>) {
|
||||
@@ -190,16 +254,19 @@ fn header(
|
||||
let record = art.metadata.get(&title.key);
|
||||
let found = record.and_then(|record| record.metadata.clone());
|
||||
let by_hand = record.is_some_and(|record| record.manual);
|
||||
// Asked for once and used twice: the same picture is the poster beside the
|
||||
// text and the banner behind all of it.
|
||||
let picture = art.of(title);
|
||||
// The cover beside the text, and the widest, largest picture there is
|
||||
// behind all of it — two textures, because the band is drawn across the
|
||||
// whole window and a tile-sized one stretched that far is soft.
|
||||
let picture = art.poster(title);
|
||||
let wide = art.wide(title);
|
||||
|
||||
// Reserved before the header is laid out, because the band is as tall as
|
||||
// whatever the header comes to — a fixed height would clip a long overview
|
||||
// on one title and leave a gap under a short one on the next.
|
||||
let backdrop = picture
|
||||
let backdrop = wide
|
||||
.as_ref()
|
||||
.map(|(texture, _)| (texture.clone(), ui.painter().add(egui::Shape::Noop)));
|
||||
let shown = art.name(title).to_owned();
|
||||
|
||||
ui.add_space(theme::space::S);
|
||||
ui.horizontal_top(|ui| {
|
||||
@@ -214,11 +281,12 @@ fn header(
|
||||
ui,
|
||||
Card {
|
||||
art: picture,
|
||||
name: &title.name,
|
||||
name: &shown,
|
||||
subtitle: String::new(),
|
||||
progress: title.resume().and_then(|e| e.progress()).map(|v| v as f32),
|
||||
badge: None,
|
||||
width: theme::CARD_WIDTH,
|
||||
aspect: theme::CARD_ASPECT,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -229,16 +297,24 @@ fn header(
|
||||
// Text in a column a person can read, with the picture to the
|
||||
// right of it rather than under it.
|
||||
ui.set_max_width(ui.available_width().min(820.0));
|
||||
ui.label(theme::Role::Display.rich(&title.name).strong());
|
||||
// The provider's name for it, when it is not the one the files use.
|
||||
// Worth showing rather than replacing the filename's: a viewer
|
||||
// should be able to tell what the match actually matched.
|
||||
if let Some(found) = &found
|
||||
&& found.name != title.name
|
||||
{
|
||||
ui.label(theme::Role::Display.rich(&shown).strong());
|
||||
// Whichever of the share's name and the provider's is not the one
|
||||
// shown. Worth showing rather than only replacing: a viewer should
|
||||
// be able to tell what the match actually matched, and find the
|
||||
// folder it came from.
|
||||
let other = found
|
||||
.as_ref()
|
||||
.map(|found| {
|
||||
if shown == found.name {
|
||||
title.name.clone()
|
||||
} else {
|
||||
found.name.clone()
|
||||
}
|
||||
})
|
||||
.filter(|other| *other != shown);
|
||||
if let Some(other) = other {
|
||||
ui.label(ui::muted(format!(
|
||||
"also known as {}{}",
|
||||
found.name,
|
||||
"also known as {other}{}",
|
||||
if by_hand { " (chosen by hand)" } else { "" }
|
||||
)));
|
||||
}
|
||||
@@ -449,12 +525,22 @@ fn band(ui: &mut egui::Ui, texture: &egui::TextureHandle, index: egui::layers::S
|
||||
|
||||
/// What the provider had to say. Only ever drawn under a match.
|
||||
fn description(ui: &mut egui::Ui, found: &TitleMetadata) {
|
||||
if !found.genres.is_empty() {
|
||||
let tags = found
|
||||
.details
|
||||
.as_ref()
|
||||
.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);
|
||||
}
|
||||
// After the genres and quieter than them: a tag is the
|
||||
// provider's community describing it, not what it is filed as.
|
||||
for tag in tags.iter().take(5) {
|
||||
ui.label(ui::muted(tag));
|
||||
}
|
||||
});
|
||||
ui.add_space(theme::space::M);
|
||||
}
|
||||
@@ -530,6 +616,30 @@ 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}"));
|
||||
}
|
||||
let now = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map_or(0, |since| since.as_secs() as i64);
|
||||
if let Some((episode, at)) = details.next_airing(now) {
|
||||
let when = chrono::DateTime::from_timestamp(at, 0)
|
||||
.map(|at| {
|
||||
at.with_timezone(&chrono::Local)
|
||||
.format("%a %-d %b, %H:%M")
|
||||
.to_string()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
parts.push(format!("episode {episode} airs {when}"));
|
||||
} else if details.is_airing() {
|
||||
parts.push("airing".to_owned());
|
||||
}
|
||||
}
|
||||
if let Some(found) = found {
|
||||
if let Some(rating) = found.rating {
|
||||
parts.push(format!("{} {rating:.1}", egui_phosphor::regular::STAR));
|
||||
|
||||
Reference in new issue
Block a user