From 05669cab6830330ff564e66a066885cedd53134d Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Tue, 20 Apr 2021 01:55:02 +1000 Subject: [PATCH] Support multiple session data and key tags. Collect Vecs of session_data and session_key tags to allow for multiples of each. Doesn't do any validation as to disallowed duplicated values. Fixes #20 --- src/playlist.rs | 13 ++++++------- tests/lib.rs | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/playlist.rs b/src/playlist.rs index cdecb13..af937c1 100644 --- a/src/playlist.rs +++ b/src/playlist.rs @@ -65,8 +65,8 @@ impl Playlist { pub struct MasterPlaylist { pub version: usize, pub variants: Vec, - pub session_data: Option, - pub session_key: Option, + pub session_data: Vec, + pub session_key: Vec, pub start: Option, pub independent_segments: bool, pub alternatives: Vec, // EXT-X-MEDIA tags @@ -74,7 +74,6 @@ pub struct MasterPlaylist { } impl MasterPlaylist { - pub fn from_tags(mut tags: Vec) -> MasterPlaylist { let mut master_playlist = MasterPlaylist::default(); @@ -95,10 +94,10 @@ impl MasterPlaylist { } } MasterPlaylistTag::SessionData(data) => { - master_playlist.session_data = Some(data); + master_playlist.session_data.push(data); } MasterPlaylistTag::SessionKey(key) => { - master_playlist.session_key = Some(key); + master_playlist.session_key.push(key); } MasterPlaylistTag::Start(s) => { master_playlist.start = Some(s); @@ -131,10 +130,10 @@ impl MasterPlaylist { for variant in &self.variants { variant.write_to(w)?; } - if let Some(ref session_data) = self.session_data { + for session_data in &self.session_data { session_data.write_to(w)?; } - if let Some(ref session_key) = self.session_key { + for session_key in &self.session_key { session_key.write_to(w)?; } if let Some(ref start) = self.start { diff --git a/tests/lib.rs b/tests/lib.rs index 1b04afe..601ff43 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -333,20 +333,22 @@ fn create_and_parse_master_playlist_full() { closed_captions: Some("closed_captions".into()), } ], - session_data: Some( + session_data: vec![ SessionData { data_id: "****".into(), field: SessionDataField::Value("%%%%".to_string()), language: Some("SessionDataLanguage".into()), } - ), - session_key: Some(SessionKey(Key { - method: "AES-128".into(), - uri: Some("https://secure.domain.com".into()), - iv: Some("0xb059217aa2649ce170b734".into()), - keyformat: Some("xXkeyformatXx".into()), - keyformatversions: Some("xXFormatVers".into()), - })), + ], + session_key: vec![ + SessionKey(Key { + method: "AES-128".into(), + uri: Some("https://secure.domain.com".into()), + iv: Some("0xb059217aa2649ce170b734".into()), + keyformat: Some("xXkeyformatXx".into()), + keyformatversions: Some("xXFormatVers".into()), + }) + ], start: Some(Start { time_offset: "123123123".into(), precise: Some("YES".into()),