From 006f36ff47f1417dbd5678c198d06ae07bc48729 Mon Sep 17 00:00:00 2001 From: Luro02 <24826124+Luro02@users.noreply.github.com> Date: Sun, 2 Feb 2020 13:50:56 +0100 Subject: [PATCH] collect unsupported tags #36 closes #36 --- src/master_playlist.rs | 15 ++++++++++++++- src/media_playlist.rs | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/master_playlist.rs b/src/master_playlist.rs index b081256..ce56b7c 100644 --- a/src/master_playlist.rs +++ b/src/master_playlist.rs @@ -68,6 +68,13 @@ pub struct MasterPlaylist { /// This tag is optional. #[builder(default)] session_key_tags: Vec, + /// A list of tags that are unknown. + /// + /// # Note + /// + /// This tag is optional. + #[builder(default)] + unknown_tags: Vec, } impl MasterPlaylist { @@ -244,6 +251,10 @@ impl fmt::Display for MasterPlaylist { writeln!(f, "{}", value)?; } + for t in &self.unknown_tags { + writeln!(f, "{}", t)?; + } + Ok(()) } } @@ -259,6 +270,7 @@ impl FromStr for MasterPlaylist { let mut i_frame_stream_inf_tags = vec![]; let mut session_data_tags = vec![]; let mut session_key_tags = vec![]; + let mut unknown_tags = vec![]; for (i, line) in input.parse::()?.into_iter().enumerate() { match line { @@ -320,7 +332,7 @@ impl FromStr for MasterPlaylist { _ => { // [6.3.1. General Client Responsibilities] // > ignore any unrecognized tags. - // TODO: collect custom tags + unknown_tags.push(tag.to_string()); } } } @@ -335,6 +347,7 @@ impl FromStr for MasterPlaylist { builder.i_frame_stream_inf_tags(i_frame_stream_inf_tags); builder.session_data_tags(session_data_tags); builder.session_key_tags(session_key_tags); + builder.unknown_tags(unknown_tags); builder.build().map_err(Error::builder) } diff --git a/src/media_playlist.rs b/src/media_playlist.rs index f0c5bab..680d6c5 100644 --- a/src/media_playlist.rs +++ b/src/media_playlist.rs @@ -98,6 +98,13 @@ pub struct MediaPlaylist { /// `Duration::from_secs(0)`. #[builder(default = "Duration::from_secs(0)")] allowable_excess_duration: Duration, + /// A list of unknown tags. + /// + /// # Note + /// + /// This field is optional. + #[builder(default)] + unknown_tags: Vec, } impl MediaPlaylistBuilder { @@ -257,6 +264,10 @@ impl fmt::Display for MediaPlaylist { writeln!(f, "{}", value)?; } + for value in &self.unknown_tags { + writeln!(f, "{}", value)?; + } + Ok(()) } } @@ -270,6 +281,7 @@ fn parse_media_playlist( let mut has_partial_segment = false; let mut has_discontinuity_tag = false; + let mut unknown_tags = vec![]; let mut available_key_tags: Vec = vec![]; @@ -369,9 +381,11 @@ fn parse_media_playlist( Tag::ExtXStart(t) => { builder.start_tag(t); } - Tag::Unknown(_) | Tag::ExtXVersion(_) => { + Tag::ExtXVersion(_) => {} + Tag::Unknown(_) => { // [6.3.1. General Client Responsibilities] // > ignore any unrecognized tags. + unknown_tags.push(tag.to_string()); } } } @@ -389,6 +403,7 @@ fn parse_media_playlist( return Err(Error::invalid_input()); } + builder.unknown_tags(unknown_tags); builder.segments(segments); builder.build().map_err(Error::builder) }