Skip to content
Merged
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
33 changes: 32 additions & 1 deletion crates/ersatztv/src/xmltv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::LineupState;
use crate::channel_model::ChannelModel;

struct ChannelMeta {
pub number: String,
pub name: String,
pub tvg_id: String,
pub logo: Option<String>,
Expand All @@ -18,6 +19,7 @@ struct ChannelMeta {
impl From<&ChannelModel> for ChannelMeta {
fn from(model: &ChannelModel) -> Self {
Self {
number: model.number().to_string(),
name: model.name().to_string(),
tvg_id: model.tvg_id().to_string(),
logo: model.logo().map(|s| s.to_string()),
Expand Down Expand Up @@ -46,9 +48,21 @@ fn generate_blocking(
w.create_element("channel")
.with_attribute(("id", channel.tvg_id.as_str()))
.write_inner_content(|inner_writer| {
let channel_num = channel.number.as_str();
let channel_name = channel.name.as_str();
let display_name = format!("{channel_num} {channel_name}");

inner_writer
.create_element("display-name")
.write_text_content(BytesText::new(&display_name))?;

inner_writer
.create_element("display-name")
.write_text_content(BytesText::new(channel_num))?;

inner_writer
.create_element("display-name")
.write_text_content(BytesText::new(channel.name.as_str()))?;
.write_text_content(BytesText::new(channel_name))?;

if let Some(logo) = &channel.logo {
inner_writer
Expand Down Expand Up @@ -160,4 +174,21 @@ mod tests {
"child element dropped: {output}"
);
}

#[test]
fn generate_blocking_includes_display_names() {
let channels = vec![ChannelMeta {
number: "1.1".to_string(),
name: "Test Channel".to_string(),
tvg_id: "test.1".to_string(),
logo: None,
}];

let result = generate_blocking(None, &channels).unwrap();
let output = String::from_utf8(result).unwrap();

assert!(output.contains("<display-name>1.1 Test Channel</display-name>"));
assert!(output.contains("<display-name>1.1</display-name>"));
assert!(output.contains("<display-name>Test Channel</display-name>"));
}
}