Expose unknown tags

This commit is contained in:
Rafael Caricio 2021-03-11 21:15:22 +01:00 committed by Rutger Schoorstra
parent 302ff22f31
commit 3e74f7787f
2 changed files with 29 additions and 14 deletions

View file

@ -69,7 +69,8 @@ pub struct MasterPlaylist {
pub session_key: Option<SessionKey>, pub session_key: Option<SessionKey>,
pub start: Option<Start>, pub start: Option<Start>,
pub independent_segments: bool, pub independent_segments: bool,
pub alternatives: Vec<AlternativeMedia> // EXT-X-MEDIA tags pub alternatives: Vec<AlternativeMedia>, // EXT-X-MEDIA tags
pub unknown_tags: Vec<ExtTag>
} }
impl MasterPlaylist { impl MasterPlaylist {
@ -105,8 +106,8 @@ impl MasterPlaylist {
MasterPlaylistTag::IndependentSegments => { MasterPlaylistTag::IndependentSegments => {
master_playlist.independent_segments = true; master_playlist.independent_segments = true;
} }
MasterPlaylistTag::Unknown(_) => { MasterPlaylistTag::Unknown(unknown) => {
// println!("Unknown master tag \n{:?}\n", t); master_playlist.unknown_tags.push(unknown);
} }
_ => (), _ => (),
} }
@ -142,6 +143,9 @@ impl MasterPlaylist {
if self.independent_segments { if self.independent_segments {
writeln!(w, "#EXT-X-INDEPENDENT-SEGMENTS")?; writeln!(w, "#EXT-X-INDEPENDENT-SEGMENTS")?;
} }
for unknown_tag in &self.unknown_tags {
write!(w, "#EXT-{}:{}\n", unknown_tag.tag, unknown_tag.rest)?;
}
Ok(()) Ok(())
} }
@ -405,6 +409,8 @@ pub struct MediaPlaylist {
pub start: Option<Start>, pub start: Option<Start>,
/// `#EXT-X-INDEPENDENT-SEGMENTS` /// `#EXT-X-INDEPENDENT-SEGMENTS`
pub independent_segments: bool, pub independent_segments: bool,
/// `#EXT-X-`
pub unknown_tags: Vec<ExtTag>
} }
impl MediaPlaylist { impl MediaPlaylist {
@ -469,6 +475,9 @@ impl MediaPlaylist {
SegmentTag::DateRange(d) => { SegmentTag::DateRange(d) => {
next_segment.daterange = Some(d); next_segment.daterange = Some(d);
} }
SegmentTag::Unknown(t) => {
media_playlist.unknown_tags.push(t);
}
SegmentTag::Uri(u) => { SegmentTag::Uri(u) => {
next_segment.key = encryption_key.clone(); next_segment.key = encryption_key.clone();
next_segment.map = map.clone(); next_segment.map = map.clone();
@ -516,6 +525,9 @@ impl MediaPlaylist {
for segment in &self.segments { for segment in &self.segments {
segment.write_to(w)?; segment.write_to(w)?;
} }
for unknown_tag in &self.unknown_tags {
write!(w, "#EXT-{}:{}\n", unknown_tag.tag, unknown_tag.rest)?;
}
Ok(()) Ok(())
} }
@ -789,8 +801,9 @@ impl Start {
} }
/// A simple `#EXT-` tag /// A simple `#EXT-` tag
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, PartialEq, Clone)]
pub struct ExtTag { pub struct ExtTag {
pub tag: String, pub tag: String,
pub rest: String, pub rest: String,
} }

View file

@ -350,6 +350,7 @@ fn create_and_parse_master_playlist_full() {
precise: Some("YES".into()), precise: Some("YES".into()),
}), }),
independent_segments: true, independent_segments: true,
unknown_tags: vec![],
}); });
let playlist_parsed = print_create_and_parse_playlist(&mut playlist_original); let playlist_parsed = print_create_and_parse_playlist(&mut playlist_original);
assert_eq!(playlist_original, playlist_parsed); assert_eq!(playlist_original, playlist_parsed);
@ -417,6 +418,7 @@ fn create_and_parse_media_playlist_full() {
daterange: None, daterange: None,
}, },
], ],
unknown_tags: vec![],
}); });
let playlist_parsed = print_create_and_parse_playlist(&mut playlist_original); let playlist_parsed = print_create_and_parse_playlist(&mut playlist_original);
assert_eq!(playlist_original, playlist_parsed); assert_eq!(playlist_original, playlist_parsed);