diff --git a/src/playlist.rs b/src/playlist.rs index 6cd24ab..3bcb69f 100644 --- a/src/playlist.rs +++ b/src/playlist.rs @@ -874,6 +874,8 @@ pub enum MediaSegmentType { Full(MediaSegment), /// HLS-LL: Partial segment (#EXT-X-PART) Partial(Part), + /// HLS-LL: Preload hint (#EXT-X-PRELOAD-HINT) + PreloadHint(PreloadHint), } impl MediaSegmentType { @@ -881,6 +883,7 @@ impl MediaSegmentType { match self { MediaSegmentType::Full(s) => s.write_to(w), MediaSegmentType::Partial(s) => s.write_to(w), + MediaSegmentType::PreloadHint(s) => s.write_to(w), } } } @@ -1413,7 +1416,8 @@ impl Skip { pub struct PreloadHint { pub hint_type: String, pub uri: String, - pub byte_range: Option, + pub byte_range_start: Option, + pub byte_range_length: Option, } impl PreloadHint { @@ -1424,11 +1428,15 @@ impl PreloadHint { .ok_or_else(|| String::from("EXT-X-PRELOAD-HINT without mandatory TYPE attribute"))?; let uri = quoted_string!(attrs, "URI") .ok_or_else(|| String::from("EXT-X-PRELOAD-HINT without mandatory URI attribute"))?; - let byte_range = quoted_string_parse!(attrs, "BYTERANGE", |s: &str| s.parse::()); + let byte_range_start = + quoted_string_parse!(attrs, "BYTERANGE-START", |s: &str| s.parse::()); + let byte_range_length = + quoted_string_parse!(attrs, "BYTERANGE-LENGTH", |s: &str| s.parse::()); Ok(PreloadHint { hint_type, uri, - byte_range, + byte_range_start, + byte_range_length, }) } @@ -1438,10 +1446,11 @@ impl PreloadHint { "#EXT-X-PRELOAD-HINT:TYPE={},URI=\"{}\"", self.hint_type, self.uri )?; - if let Some(ref byte_range) = self.byte_range { - write!(w, ",BYTERANGE=\"")?; - byte_range.write_value_to(w)?; - write!(w, "\"")?; + if let Some(ref r) = self.byte_range_start { + write!(w, ",BYTERANGE-START=\"{}\"", r)?; + } + if let Some(ref r) = self.byte_range_length { + write!(w, ",BYTERANGE-LENGTH=\"{}\"", r)?; } writeln!(w) } diff --git a/tests/lib.rs b/tests/lib.rs index 5dd161c..f54839e 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -577,10 +577,8 @@ fn create_and_parse_media_playlist_llhls() { preload_hint: Some(PreloadHint { hint_type: "PART".into(), uri: "next_part.ts".into(), - byte_range: Some(ByteRange { - length: 50000, - offset: Some(100000), - }), + byte_range_start: Some(50000), + byte_range_length: Some(60000), }), rendition_report: Some(RenditionReport { uri: "rendition.m3u8".into(),