diff --git a/src/line.rs b/src/line.rs index 1c675e4..f7d1616 100644 --- a/src/line.rs +++ b/src/line.rs @@ -5,6 +5,7 @@ use core::str::FromStr; use derive_more::Display; use crate::tags; +use crate::types::PlaylistType; use crate::Error; #[derive(Debug, Clone)] @@ -70,7 +71,7 @@ pub(crate) enum Tag<'a> { ExtXMediaSequence(tags::ExtXMediaSequence), ExtXDiscontinuitySequence(tags::ExtXDiscontinuitySequence), ExtXEndList(tags::ExtXEndList), - ExtXPlaylistType(tags::ExtXPlaylistType), + PlaylistType(PlaylistType), ExtXIFramesOnly(tags::ExtXIFramesOnly), ExtXMedia(tags::ExtXMedia), ExtXSessionData(tags::ExtXSessionData), @@ -109,8 +110,8 @@ impl<'a> TryFrom<&'a str> for Tag<'a> { input.parse().map(Self::ExtXDiscontinuitySequence) } else if input.starts_with(tags::ExtXEndList::PREFIX) { input.parse().map(Self::ExtXEndList) - } else if input.starts_with(tags::ExtXPlaylistType::PREFIX) { - input.parse().map(Self::ExtXPlaylistType) + } else if input.starts_with(PlaylistType::PREFIX) { + input.parse().map(Self::PlaylistType) } else if input.starts_with(tags::ExtXIFramesOnly::PREFIX) { input.parse().map(Self::ExtXIFramesOnly) } else if input.starts_with(tags::ExtXMedia::PREFIX) { diff --git a/src/master_playlist.rs b/src/master_playlist.rs index 272a5b7..641c434 100644 --- a/src/master_playlist.rs +++ b/src/master_playlist.rs @@ -493,7 +493,7 @@ impl FromStr for MasterPlaylist { | Tag::ExtXMediaSequence(_) | Tag::ExtXDiscontinuitySequence(_) | Tag::ExtXEndList(_) - | Tag::ExtXPlaylistType(_) + | Tag::PlaylistType(_) | Tag::ExtXIFramesOnly(_) => { return Err(Error::unexpected_tag(tag)); } diff --git a/src/media_playlist.rs b/src/media_playlist.rs index bd58c9f..9eb76b0 100644 --- a/src/media_playlist.rs +++ b/src/media_playlist.rs @@ -10,9 +10,9 @@ use crate::line::{Line, Lines, Tag}; use crate::media_segment::MediaSegment; use crate::tags::{ ExtM3u, ExtXDiscontinuitySequence, ExtXEndList, ExtXIFramesOnly, ExtXIndependentSegments, - ExtXKey, ExtXMediaSequence, ExtXPlaylistType, ExtXStart, ExtXTargetDuration, ExtXVersion, + ExtXKey, ExtXMediaSequence, ExtXStart, ExtXTargetDuration, ExtXVersion, }; -use crate::types::{EncryptionMethod, ProtocolVersion}; +use crate::types::{EncryptionMethod, PlaylistType, ProtocolVersion}; use crate::utils::tag; use crate::{Error, RequiredVersion}; @@ -43,13 +43,13 @@ pub struct MediaPlaylist { /// This field is optional. #[builder(default)] discontinuity_sequence: Option, - /// Sets the [`ExtXPlaylistType`] tag. + /// Sets the [`PlaylistType`] tag. /// /// # Note /// /// This field is optional. #[builder(default)] - playlist_type: Option, + playlist_type: Option, /// Sets the [`ExtXIFramesOnly`] tag. /// /// # Note @@ -392,7 +392,7 @@ fn parse_media_playlist( Tag::ExtXEndList(t) => { builder.end_list(t); } - Tag::ExtXPlaylistType(t) => { + Tag::PlaylistType(t) => { builder.playlist_type(t); } Tag::ExtXIFramesOnly(t) => { diff --git a/src/types/mod.rs b/src/types/mod.rs index 65ffcf4..9a3c299 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -13,6 +13,7 @@ mod protocol_version; mod resolution; mod stream_data; mod value; +pub(crate) mod playlist_type; mod float; mod ufloat; @@ -27,6 +28,7 @@ pub use in_stream_id::*; pub use key_format::*; pub use key_format_versions::*; pub use media_type::*; +pub use playlist_type::*; pub use protocol_version::*; pub use resolution::*; pub use stream_data::*; diff --git a/src/tags/media_playlist/playlist_type.rs b/src/types/playlist_type.rs similarity index 62% rename from src/tags/media_playlist/playlist_type.rs rename to src/types/playlist_type.rs index f81ad10..36127f3 100644 --- a/src/tags/media_playlist/playlist_type.rs +++ b/src/types/playlist_type.rs @@ -7,36 +7,36 @@ use crate::{Error, RequiredVersion}; /// # [4.3.3.5. EXT-X-PLAYLIST-TYPE] /// -/// The [`ExtXPlaylistType`] tag provides mutability information about the +/// The [`PlaylistType`] tag provides mutability information about the /// [`MediaPlaylist`]. It applies to the entire [`MediaPlaylist`]. /// /// [`MediaPlaylist`]: crate::MediaPlaylist /// [4.3.3.5. EXT-X-PLAYLIST-TYPE]: https://tools.ietf.org/html/rfc8216#section-4.3.3.5 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub enum ExtXPlaylistType { - /// If the [`ExtXPlaylistType`] is Event, [`MediaSegment`]s +pub enum PlaylistType { + /// If the [`PlaylistType`] is Event, [`MediaSegment`]s /// can only be added to the end of the [`MediaPlaylist`]. /// /// [`MediaSegment`]: crate::MediaSegment /// [`MediaPlaylist`]: crate::MediaPlaylist Event, - /// If the [`ExtXPlaylistType`] is Video On Demand (Vod), + /// If the [`PlaylistType`] is Video On Demand (Vod), /// the [`MediaPlaylist`] cannot change. /// /// [`MediaPlaylist`]: crate::MediaPlaylist Vod, } -impl ExtXPlaylistType { +impl PlaylistType { pub(crate) const PREFIX: &'static str = "#EXT-X-PLAYLIST-TYPE:"; } /// This tag requires [`ProtocolVersion::V1`]. -impl RequiredVersion for ExtXPlaylistType { +impl RequiredVersion for PlaylistType { fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } -impl fmt::Display for ExtXPlaylistType { +impl fmt::Display for PlaylistType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match &self { Self::Event => write!(f, "{}EVENT", Self::PREFIX), @@ -45,7 +45,7 @@ impl fmt::Display for ExtXPlaylistType { } } -impl FromStr for ExtXPlaylistType { +impl FromStr for PlaylistType { type Err = Error; fn from_str(input: &str) -> Result { @@ -53,7 +53,7 @@ impl FromStr for ExtXPlaylistType { match input { "EVENT" => Ok(Self::Event), "VOD" => Ok(Self::Vod), - _ => Err(Error::custom(format!("Unknown playlist type: {:?}", input))), + _ => Err(Error::custom(format!("unknown playlist type: {:?}", input))), } } } @@ -66,48 +66,38 @@ mod test { #[test] fn test_parser() { assert_eq!( - "#EXT-X-PLAYLIST-TYPE:VOD" - .parse::() - .unwrap(), - ExtXPlaylistType::Vod, + "#EXT-X-PLAYLIST-TYPE:VOD".parse::().unwrap(), + PlaylistType::Vod, ); assert_eq!( "#EXT-X-PLAYLIST-TYPE:EVENT" - .parse::() + .parse::() .unwrap(), - ExtXPlaylistType::Event, + PlaylistType::Event, ); - assert!("#EXT-X-PLAYLIST-TYPE:H" - .parse::() - .is_err()); + assert!("#EXT-X-PLAYLIST-TYPE:H".parse::().is_err()); - assert!("garbage".parse::().is_err()); + assert!("garbage".parse::().is_err()); } #[test] fn test_display() { assert_eq!( "#EXT-X-PLAYLIST-TYPE:VOD".to_string(), - ExtXPlaylistType::Vod.to_string(), + PlaylistType::Vod.to_string(), ); assert_eq!( "#EXT-X-PLAYLIST-TYPE:EVENT".to_string(), - ExtXPlaylistType::Event.to_string(), + PlaylistType::Event.to_string(), ); } #[test] fn test_required_version() { - assert_eq!( - ExtXPlaylistType::Vod.required_version(), - ProtocolVersion::V1 - ); - assert_eq!( - ExtXPlaylistType::Event.required_version(), - ProtocolVersion::V1 - ); + assert_eq!(PlaylistType::Vod.required_version(), ProtocolVersion::V1); + assert_eq!(PlaylistType::Event.required_version(), ProtocolVersion::V1); } } diff --git a/tests/media_playlist.rs b/tests/media_playlist.rs index 126b0c5..338ead9 100644 --- a/tests/media_playlist.rs +++ b/tests/media_playlist.rs @@ -5,9 +5,8 @@ use std::time::Duration; -use hls_m3u8::tags::{ - ExtInf, ExtXByteRange, ExtXEndList, ExtXMediaSequence, ExtXPlaylistType, ExtXTargetDuration, -}; +use hls_m3u8::tags::{ExtInf, ExtXByteRange, ExtXEndList, ExtXMediaSequence, ExtXTargetDuration}; +use hls_m3u8::types::PlaylistType; use hls_m3u8::{MediaPlaylist, MediaSegment}; use pretty_assertions::assert_eq; @@ -72,7 +71,7 @@ generate_tests! { }, test_absolute_uris => { MediaPlaylist::builder() - .playlist_type(ExtXPlaylistType::Vod) + .playlist_type(PlaylistType::Vod) .target_duration(ExtXTargetDuration::new(Duration::from_secs(10))) .segments(vec![ MediaSegment::builder() @@ -123,7 +122,7 @@ generate_tests! { MediaPlaylist::builder() .target_duration(Duration::from_secs(10)) .media_sequence(0) - .playlist_type(ExtXPlaylistType::Vod) + .playlist_type(PlaylistType::Vod) .segments(vec![ MediaSegment::builder() .inf(ExtInf::new(Duration::from_secs(10))) @@ -137,7 +136,6 @@ generate_tests! { .uri("hls_450k_video.ts") .build() .unwrap(), - MediaSegment::builder() .inf(ExtInf::new(Duration::from_secs(10))) .byte_range(1_110_328..1_823_412) @@ -315,5 +313,4 @@ generate_tests! { "#EXT-X-ENDLIST\n" ) }, - }