diff --git a/Cargo.toml b/Cargo.toml index d37b563..4e2f85c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ travis-ci = {repository = "sile/hls_m3u8"} codecov = {repository = "sile/hls_m3u8"} [dependencies] -getset = "0.0.8" failure = "0.1.5" derive_builder = "0.7.2" url = "2.1.0" diff --git a/src/tags/master_playlist/i_frame_stream_inf.rs b/src/tags/master_playlist/i_frame_stream_inf.rs index 1567c07..cbd60b8 100644 --- a/src/tags/master_playlist/i_frame_stream_inf.rs +++ b/src/tags/master_playlist/i_frame_stream_inf.rs @@ -1,8 +1,6 @@ use std::fmt; use std::str::FromStr; -use getset::{Getters, MutGetters, Setters}; - use crate::attribute::AttributePairs; use crate::types::{DecimalResolution, HdcpLevel, ProtocolVersion}; use crate::utils::parse_u64; @@ -12,39 +10,14 @@ use crate::Error; /// [4.3.4.3. EXT-X-I-FRAME-STREAM-INF] /// /// [4.3.4.3. EXT-X-I-FRAME-STREAM-INF]: https://tools.ietf.org/html/rfc8216#section-4.3.4.3 -#[derive(Getters, Setters, MutGetters, Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExtXIFrameStreamInf { - #[get = "pub"] - #[set = "pub"] - #[get_mut = "pub"] - /// The URI, that identifies the associated media playlist. uri: String, - #[get = "pub"] - #[set = "pub"] - #[get_mut = "pub"] - /// The peak segment bit rate of the variant stream. bandwidth: u64, - #[get = "pub"] - #[set = "pub"] - #[get_mut = "pub"] - /// The average segment bit rate of the variant stream. average_bandwidth: Option, - #[get = "pub"] - #[set = "pub"] - #[get_mut = "pub"] - /// A string that represents the list of codec types contained the variant stream. codecs: Option, - /// The optimal pixel resolution at which to display all the video in the variant stream. resolution: Option, - #[get = "pub"] - #[set = "pub"] - #[get_mut = "pub"] - /// The HDCP level of the variant stream. hdcp_level: Option, - #[get = "pub"] - #[set = "pub"] - #[get_mut = "pub"] - /// The group identifier for the video in the variant stream. video: Option, } @@ -64,7 +37,160 @@ impl ExtXIFrameStreamInf { } } - /// The optimal pixel resolution at which to display all the video in the variant stream. + /// Returns the URI, that identifies the associated media playlist. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// assert_eq!(stream.uri(), &"https://www.example.com".to_string()); + /// ``` + pub const fn uri(&self) -> &String { + &self.uri + } + + /// Sets the URI, that identifies the associated media playlist. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// + /// stream.set_uri("../new/uri"); + /// assert_eq!(stream.uri(), &"../new/uri".to_string()); + /// ``` + pub fn set_uri(&mut self, value: T) -> &mut Self { + self.uri = value.to_string(); + self + } + + /// Returns the peak segment bit rate of the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// assert_eq!(stream.bandwidth(), 20); + /// ``` + pub const fn bandwidth(&self) -> u64 { + self.bandwidth + } + + /// Sets the group identifier for the video in the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// + /// stream.set_video(Some("video")); + /// assert_eq!(stream.video(), &Some("video".to_string())); + /// ``` + pub fn set_video(&mut self, value: Option) -> &mut Self { + self.video = value.map(|v| v.to_string()); + self + } + + /// Returns the group identifier for the video in the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// assert_eq!(stream.video(), &None); + /// ``` + pub const fn video(&self) -> &Option { + &self.video + } + + /// Sets the peak segment bit rate of the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// + /// stream.set_bandwidth(5); + /// assert_eq!(stream.bandwidth(), 5); + /// ``` + pub fn set_bandwidth(&mut self, value: u64) -> &mut Self { + self.bandwidth = value; + self + } + + /// Returns the average segment bit rate of the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// assert_eq!(stream.average_bandwidth(), None); + /// ``` + pub const fn average_bandwidth(&self) -> Option { + self.average_bandwidth + } + + /// Sets the average segment bit rate of the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// + /// stream.set_average_bandwidth(Some(300)); + /// assert_eq!(stream.average_bandwidth(), Some(300)); + /// ``` + pub fn set_average_bandwidth(&mut self, value: Option) -> &mut Self { + self.average_bandwidth = value; + self + } + + /// A string that represents the list of codec types contained the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// assert_eq!(stream.codecs(), &None); + /// ``` + pub const fn codecs(&self) -> &Option { + &self.codecs + } + + /// A string that represents the list of codec types contained the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// + /// stream.set_uri("../new/uri"); + /// assert_eq!(stream.uri(), &"../new/uri".to_string()); + /// ``` + pub fn set_codecs(&mut self, value: Option) -> &mut Self { + self.codecs = value.map(|v| v.to_string()); + self + } + + /// Returns the resolution of the stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// assert_eq!(stream.resolution(), None); + /// ``` pub fn resolution(&self) -> Option<(usize, usize)> { if let Some(res) = &self.resolution { Some((res.width(), res.height())) @@ -73,7 +199,17 @@ impl ExtXIFrameStreamInf { } } - /// Sets the optimal pixel resolution at which to display all the video in the variant stream. + /// Sets the resolution of the stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// + /// stream.set_resolution(1920, 1080); + /// assert_eq!(stream.resolution(), Some((1920, 1080))); + /// ``` pub fn set_resolution(&mut self, width: usize, height: usize) -> &mut Self { if let Some(res) = &mut self.resolution { res.set_width(width); @@ -83,6 +219,36 @@ impl ExtXIFrameStreamInf { } self } + + /// The HDCP level of the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// assert_eq!(stream.uri(), &"https://www.example.com".to_string()); + /// ``` + pub const fn hdcp_level(&self) -> Option { + self.hdcp_level + } + + /// The HDCP level of the variant stream. + /// + /// # Example + /// ``` + /// # use hls_m3u8::tags::ExtXIFrameStreamInf; + /// # + /// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20); + /// + /// stream.set_uri("../new/uri"); + /// assert_eq!(stream.uri(), &"../new/uri".to_string()); + /// ``` + pub fn set_hdcp_level>(&mut self, value: Option) -> &mut Self { + self.hdcp_level = value.map(|v| v.into()); + self + } + /// Returns the protocol compatibility version that this tag requires. pub const fn requires_version(&self) -> ProtocolVersion { ProtocolVersion::V1 @@ -179,7 +345,7 @@ mod test { ); assert_eq!(i_frame_stream_inf.uri(), "foo"); - assert_eq!(*i_frame_stream_inf.bandwidth(), 1000); + assert_eq!(i_frame_stream_inf.bandwidth(), 1000); // TODO: test all the optional fields } diff --git a/src/tags/media_segment/byte_range.rs b/src/tags/media_segment/byte_range.rs index e7a895a..c1bf2ce 100644 --- a/src/tags/media_segment/byte_range.rs +++ b/src/tags/media_segment/byte_range.rs @@ -114,7 +114,7 @@ mod test { } #[test] - fn test_parse() { + fn test_parser() { let byte_range = ExtXByteRange::new(99999, Some(2)); assert_eq!( byte_range, @@ -132,7 +132,7 @@ mod test { fn test_deref() { let byte_range = ExtXByteRange::new(0, Some(22)); - assert_eq!(*byte_range.length(), 0); - assert_eq!(*byte_range.start(), Some(22)); + assert_eq!(byte_range.length(), 0); + assert_eq!(byte_range.start(), Some(22)); } } diff --git a/src/tags/media_segment/date_range.rs b/src/tags/media_segment/date_range.rs index d1c4fbd..4f17db3 100644 --- a/src/tags/media_segment/date_range.rs +++ b/src/tags/media_segment/date_range.rs @@ -4,7 +4,6 @@ use std::str::FromStr; use std::time::Duration; use chrono::{DateTime, FixedOffset}; -use getset::{Getters, MutGetters, Setters}; use crate::attribute::AttributePairs; use crate::types::{DecimalFloatingPoint, ProtocolVersion}; @@ -17,10 +16,7 @@ use crate::Error; /// /// TODO: Implement properly #[allow(missing_docs)] -#[derive(Debug, Clone, PartialEq, Eq, Hash, Getters, MutGetters, Setters)] -#[get = "pub"] -#[set = "pub"] -#[get_mut = "pub"] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExtXDateRange { /// A string that uniquely identifies a Date Range in the Playlist. /// This attribute is REQUIRED. diff --git a/src/types/byte_range.rs b/src/types/byte_range.rs index 09f3535..36b0a74 100644 --- a/src/types/byte_range.rs +++ b/src/types/byte_range.rs @@ -1,8 +1,6 @@ use std::fmt; use std::str::FromStr; -use getset::{Getters, MutGetters, Setters}; - use crate::Error; /// Byte range. @@ -10,14 +8,9 @@ use crate::Error; /// See: [4.3.2.2. EXT-X-BYTERANGE] /// /// [4.3.2.2. EXT-X-BYTERANGE]: https://tools.ietf.org/html/rfc8216#section-4.3.2.2 -#[derive(Getters, Setters, MutGetters, Debug, Clone, Copy, PartialEq, Eq, Hash)] -#[get = "pub"] -#[set = "pub"] -#[get_mut = "pub"] +#[derive(Copy, Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)] pub struct ByteRange { - /// The length of the range. length: usize, - /// The start of the range. start: Option, } @@ -26,6 +19,60 @@ impl ByteRange { pub const fn new(length: usize, start: Option) -> Self { Self { length, start } } + + /// Returns the length of the range. + /// # Example + /// ``` + /// # use hls_m3u8::types::ByteRange; + /// # + /// assert_eq!(ByteRange::new(20, Some(3)).length(), 20); + /// ``` + pub const fn length(&self) -> usize { + self.length + } + + /// Sets the length of the range. + /// # Example + /// ``` + /// # use hls_m3u8::types::ByteRange; + /// # + /// let mut range = ByteRange::new(20, Some(3)); + /// + /// # assert_eq!(range.length(), 20); + /// range.set_length(10); + /// assert_eq!(range.length(), 10); + /// ``` + pub fn set_length(&mut self, value: usize) -> &mut Self { + self.length = value; + self + } + + /// Returns the start of the range. + /// # Example + /// ``` + /// # use hls_m3u8::types::ByteRange; + /// # + /// assert_eq!(ByteRange::new(20, Some(3)).start(), Some(3)); + /// ``` + pub const fn start(&self) -> Option { + self.start + } + + /// Sets the start of the range. + /// # Example + /// ``` + /// # use hls_m3u8::types::ByteRange; + /// # + /// let mut range = ByteRange::new(20, None); + /// + /// # assert_eq!(range.start(), None); + /// range.set_start(Some(3)); + /// assert_eq!(range.start(), Some(3)); + /// ``` + pub fn set_start(&mut self, value: Option) -> &mut Self { + self.start = value; + self + } } impl fmt::Display for ByteRange { @@ -86,7 +133,7 @@ mod tests { } #[test] - fn test_parse() { + fn test_parser() { let byte_range = ByteRange { length: 99999, start: Some(2),