another backup

This commit is contained in:
2026-02-16 22:34:22 -06:00
parent 62d408337e
commit 8c97c2911c
2 changed files with 251 additions and 105 deletions
+76
View File
@@ -52,6 +52,34 @@ struct PlaylistItemsResponse {
total_record_count: Option<usize>,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "PascalCase")]
struct PlaybackInfoDto<'a> {
user_id: Option<&'a str>,
max_streaming_bitrate: Option<i32>,
enable_direct_play: Option<bool>,
enable_direct_stream: Option<bool>,
enable_transcoding: Option<bool>,
allow_video_stream_copy: Option<bool>,
allow_audio_stream_copy: Option<bool>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
struct PlaybackInfoResponse {
media_sources: Vec<MediaSourceInfo>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
struct MediaSourceInfo {
transcoding_url: Option<String>,
// (We don't need more fields.)
}
impl JellyfinClient {
pub fn from_config(cfg: &Config) -> Result<Self, String> {
let token = cfg
@@ -143,6 +171,54 @@ impl JellyfinClient {
false
}
pub fn playback_transcoding_url(
&self,
item_id: &str,
user_id: Option<&str>,
max_streaming_bitrate_bps: i32,
force_transcode: bool,
) -> Result<Option<String>, String> {
let url = format!("{}/Items/{}/PlaybackInfo", self.base_url.trim_end_matches('/'), item_id);
let body = if force_transcode {
PlaybackInfoDto {
user_id,
max_streaming_bitrate: Some(max_streaming_bitrate_bps),
enable_direct_play: Some(false),
enable_direct_stream: Some(false),
enable_transcoding: Some(true),
allow_video_stream_copy: Some(false),
allow_audio_stream_copy: Some(false),
}
} else {
PlaybackInfoDto {
user_id,
max_streaming_bitrate: Some(max_streaming_bitrate_bps),
enable_direct_play: None,
enable_direct_stream: None,
enable_transcoding: None,
allow_video_stream_copy: None,
allow_audio_stream_copy: None,
}
};
let resp: PlaybackInfoResponse = self
.client
.post(url)
// IMPORTANT: authenticated call
.header("X-Emby-Authorization", self.auth_header_value())
.json(&body)
.send()
.map_err(|e| format!("PlaybackInfo request failed: {e}"))?
.error_for_status()
.map_err(|e| format!("PlaybackInfo HTTP error: {e}"))?
.json()
.map_err(|e| format!("PlaybackInfo json parse failed: {e}"))?;
Ok(resp.media_sources.into_iter().find_map(|ms| ms.transcoding_url))
}
pub fn list_views(&self, user_id: &str) -> Result<Vec<JfItem>, String> {
let url = format!("{}/Users/{}/Views", self.base_url, user_id);