Playlist Integration!!!

This commit is contained in:
2026-02-14 17:34:23 -06:00
parent 56ba176615
commit 529ea7b49a
2 changed files with 80 additions and 2 deletions
+46
View File
@@ -42,6 +42,14 @@ pub struct ViewsResponse {
pub items: Vec<JfItem>,
}
#[derive(Deserialize)]
struct PlaylistItemsResponse {
#[serde(rename = "Items", default)]
items: Vec<JfItem>,
#[serde(rename = "TotalRecordCount")]
total_record_count: Option<usize>,
}
impl JellyfinClient {
pub fn from_config(cfg: &Config) -> Result<Self, String> {
let token = cfg
@@ -200,6 +208,44 @@ impl JellyfinClient {
total: parsed.total_record_count.unwrap_or(0),
})
}
pub fn playlist_items(
&self,
user_id: &str,
playlist_id: &str,
start_index: usize,
limit: usize,
) -> Result<PagedItems, String> {
let url = format!("{}/Playlists/{}/Items", self.base_url, playlist_id);
let resp = self
.client
.get(url)
.header("X-Emby-Authorization", self.auth_header_value())
.query(&[
("UserId", user_id),
("StartIndex", &start_index.to_string()),
("Limit", &limit.to_string()),
("Fields", "PrimaryImageAspectRatio,SortName,ProductionYear,IndexNumber,ParentIndexNumber"),
])
.send()
.map_err(|e| format!("request failed: {e}"))?;
if !resp.status().is_success() {
let status = resp.status();
let text = resp.text().unwrap_or_default();
return Err(format!("playlist_items failed: {status} {text}"));
}
let parsed: PlaylistItemsResponse = resp
.json()
.map_err(|e| format!("bad response json: {e}"))?;
Ok(PagedItems {
items: parsed.items,
total: parsed.total_record_count.unwrap_or(0),
})
}
}
/// What kind of library list we want.