implimented first itteration of drill down

This commit is contained in:
2026-02-14 03:14:12 -06:00
parent 0ee5922ba6
commit 3facd00721
2 changed files with 134 additions and 19 deletions

View File

@@ -123,7 +123,7 @@ impl JellyfinClient {
.get(url) .get(url)
.header("X-Emby-Authorization", self.auth_header_value()) .header("X-Emby-Authorization", self.auth_header_value())
.query(&[ .query(&[
("Recursive", "true"), ("Recursive", if query.recursive { "true" } else { "false" }),
("StartIndex", &start_index.to_string()), ("StartIndex", &start_index.to_string()),
("Limit", &limit.to_string()), ("Limit", &limit.to_string()),
("Fields", "PrimaryImageAspectRatio,SortName,ProductionYear"), ("Fields", "PrimaryImageAspectRatio,SortName,ProductionYear"),
@@ -131,6 +131,17 @@ impl JellyfinClient {
("SortOrder", "Ascending"), ("SortOrder", "Ascending"),
]); ]);
if let Some(types) = query.include_item_types.as_deref() {
req = req.query(&[("IncludeItemTypes", types)]);
}
if let Some(parent) = query.parent_id.as_deref() {
req = req.query(&[("ParentId", parent)]);
}
if let Some(term) = query.search_term.as_deref() {
req = req.query(&[("SearchTerm", term)]);
}
// apply query (movie/series/etc) // apply query (movie/series/etc)
if let Some(types) = query.include_item_types.as_deref() { if let Some(types) = query.include_item_types.as_deref() {
req = req.query(&[("IncludeItemTypes", types)]); req = req.query(&[("IncludeItemTypes", types)]);
@@ -159,32 +170,69 @@ impl JellyfinClient {
} }
} }
/// What kind of library list we want.
#[derive(Clone)] #[derive(Clone)]
pub struct LibraryQuery { pub struct LibraryQuery {
pub include_item_types: Option<String>, pub include_item_types: Option<String>, // e.g. Some("Movie".into())
pub search_term: Option<String>, pub parent_id: Option<String>, // e.g. Some(series_id)
pub search_term: Option<String>, // e.g. Some("matrix".into())
pub recursive: bool, // true for big lists, false for drilldown
} }
impl LibraryQuery { impl LibraryQuery {
pub fn movies() -> Self { pub fn movies() -> Self {
Self { include_item_types: Some("Movie".into()), search_term: None } Self {
include_item_types: Some("Movie".into()),
parent_id: None,
search_term: None,
recursive: true,
}
} }
pub fn shows() -> Self { pub fn shows() -> Self {
Self { include_item_types: Some("Series".into()), search_term: None } Self {
include_item_types: Some("Series".into()),
parent_id: None,
search_term: None,
recursive: true,
}
} }
pub fn music() -> Self { pub fn music() -> Self {
Self { include_item_types: Some("Audio".into()), search_term: None } Self {
include_item_types: Some("Audio".into()),
parent_id: None,
search_term: None,
recursive: true,
} }
pub fn all() -> Self {
Self { include_item_types: None, search_term: None }
} }
pub fn with_search(mut self, term: String) -> Self { // true "All" (no filter)
self.search_term = Some(term); pub fn all() -> Self {
Self {
include_item_types: None,
parent_id: None,
search_term: None,
recursive: true,
}
}
pub fn with_parent(mut self, parent_id: impl Into<String>) -> Self {
self.parent_id = Some(parent_id.into());
self.recursive = false; // drilldown is usually direct children
self
}
pub fn with_search(mut self, term: impl Into<String>) -> Self {
self.search_term = Some(term.into());
self
}
pub fn with_item_types(mut self, types: impl Into<String>) -> Self {
self.include_item_types = Some(types.into());
self self
} }
} }
pub struct PagedItems { pub struct PagedItems {
pub items: Vec<JfItem>, pub items: Vec<JfItem>,
pub total: usize, pub total: usize,

View File

@@ -432,10 +432,50 @@ fn handle_key(app: &mut App, code: KeyCode) {
} }
} }
} }
View::Library { title, items, selected, .. } => {
if items.is_empty() { return; }
let it = &items[*selected];
let ty = it.item_type.as_deref().unwrap_or("");
// Shows -> Seasons -> Episodes
if ty == "Series" {
let q = core::jellyfin::LibraryQuery::all()
.with_parent(it.id.clone())
.with_item_types("Season");
open_children(app, format!("{} > {}", title, it.name), q);
return;
}
if ty == "Season" {
let q = core::jellyfin::LibraryQuery::all()
.with_parent(it.id.clone())
.with_item_types("Episode");
open_children(app, format!("{} > {}", title, it.name), q);
return;
}
// MusicArtist -> MusicAlbum -> Audio
if ty == "MusicArtist" {
let q = core::jellyfin::LibraryQuery::all()
.with_parent(it.id.clone())
.with_item_types("MusicAlbum");
open_children(app, format!("{} > {}", title, it.name), q);
return;
}
if ty == "MusicAlbum" {
let q = core::jellyfin::LibraryQuery::all()
.with_parent(it.id.clone())
.with_item_types("Audio");
open_children(app, format!("{} > {}", title, it.name), q);
return;
}
// Otherwise: later we can make Enter “play”, “details”, etc.
app.status = format!("No drilldown for type: {}", ty);
}
_ => {} _ => {}
} }
} }
KeyCode::Esc | KeyCode::Backspace => { KeyCode::Esc | KeyCode::Backspace => {
if app.view_stack.len() > 1 { if app.view_stack.len() > 1 {
app.view_stack.pop(); app.view_stack.pop();
@@ -443,7 +483,6 @@ fn handle_key(app: &mut App, code: KeyCode) {
app.selected = 0; app.selected = 0;
} }
} }
KeyCode::Up | KeyCode::Char('k') => { KeyCode::Up | KeyCode::Char('k') => {
match app.view_stack.last_mut().unwrap() { match app.view_stack.last_mut().unwrap() {
View::Categories => { View::Categories => {
@@ -475,7 +514,6 @@ fn handle_key(app: &mut App, code: KeyCode) {
_ => {} _ => {}
} }
} }
KeyCode::Down | KeyCode::Char('j') => { KeyCode::Down | KeyCode::Char('j') => {
match app.view_stack.last_mut().unwrap() { match app.view_stack.last_mut().unwrap() {
View::Categories => { View::Categories => {
@@ -510,7 +548,6 @@ fn handle_key(app: &mut App, code: KeyCode) {
_ => {} _ => {}
} }
} }
KeyCode::Char('/') => { KeyCode::Char('/') => {
let scope = match app.current_view() { let scope = match app.current_view() {
View::Categories => SearchScope::All, View::Categories => SearchScope::All,
@@ -527,12 +564,10 @@ fn handle_key(app: &mut App, code: KeyCode) {
input: String::new(), input: String::new(),
}); });
} }
_ => {} _ => {}
} }
} }
fn load_next_library_page(app: &mut App) { fn load_next_library_page(app: &mut App) {
// pull info + mark loading // pull info + mark loading
let (query, next_start, total, page_size) = match app.view_stack.last_mut() { let (query, next_start, total, page_size) = match app.view_stack.last_mut() {
@@ -580,7 +615,6 @@ fn finish_loading(app: &mut App) {
} }
} }
fn maybe_prefetch(app: &mut App) { fn maybe_prefetch(app: &mut App) {
const PREFETCH_ROWS: usize = 0; const PREFETCH_ROWS: usize = 0;
@@ -615,7 +649,6 @@ fn ensure_loaded_to_end(app: &mut App) {
} }
} }
fn ui(frame: &mut Frame, app: &App) { fn ui(frame: &mut Frame, app: &App) {
let area = frame.area(); let area = frame.area();
let panes = layout(area); let panes = layout(area);
@@ -805,6 +838,40 @@ fn render_library(
); );
} }
fn open_children(app: &mut App, title: String, query: core::jellyfin::LibraryQuery) {
let cfg = match &app.config {
Some(c) => c.clone(),
None => { app.status = "No config loaded".into(); return; }
};
let user_id = match cfg.user_id.as_deref() {
Some(u) => u,
None => { app.status = "Missing user_id in config (login again)".into(); return; }
};
let client = match core::jellyfin::JellyfinClient::from_config(&cfg) {
Ok(c) => c,
Err(e) => { app.status = e; return; }
};
app.status = format!("Fetching {}...", title);
match client.list_items(user_id, query.clone(), 0, PAGE_SIZE) {
Ok(page) => {
app.view_stack.push(View::Library {
title,
query,
items: page.items,
selected: 0,
start_index: 0,
total: page.total,
page_size: PAGE_SIZE,
loading: false,
});
app.status = "Loaded".into();
}
Err(e) => app.status = format!("Fetch failed: {e}"),
}
}
struct Panes { struct Panes {
top: Rect, top: Rect,
left_main: Rect, left_main: Rect,