Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion crates/remux-server/src/api/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,10 +1034,13 @@ pub fn db_media_to_item(media: db::Media, hide_sources: bool) -> BaseItemDto {
item.external_urls = external_urls;

// several dlients require at least one stream
// `Stream` is here because Android TV refetches an item by MediaSource id
// when switching versions; without it that response has no MediaSources.
if !hide_sources
&& (media.kind == db::MediaKind::Movie
|| media.kind == db::MediaKind::Episode
|| media.kind == db::MediaKind::Track)
|| media.kind == db::MediaKind::Track
|| media.kind == db::MediaKind::Stream)
{
item.can_download = Some(true);
item.media_sources = match media
Expand Down Expand Up @@ -1211,3 +1214,33 @@ pub struct RemoteSubtitleInfo {
pub ai_translated: Option<bool>,
pub machine_translated: Option<bool>,
}

#[cfg(test)]
mod tests {
use super::*;

/// Regression: `GET /Items/{id}` on a MediaSource id — what Android TV
/// requests when switching versions — omitted `MediaSources` entirely,
/// which the client dereferences unguarded and crashes on.
#[test]
fn db_media_to_item_emits_media_sources_for_a_stream_row() {
let row = db::Media {
kind: db::MediaKind::Stream,
title: "1080p WEB-DL".into(),
..Default::default()
};
// What `item_for_user` does for a Stream: the row is its own source.
let mut media = row.clone();
media.sources = Some(vec![row]);

let item = db_media_to_item(media, false);
let sources = item
.media_sources
.expect("a Stream row must carry MediaSources, not omit the field");
assert_eq!(
sources.len(),
1,
"clients select MediaSources[0] with no PlaybackInfo round-trip"
);
}
}
Loading