mirror of
https://github.com/sile/hls_m3u8.git
synced 2025-02-16 13:15:14 +00:00
some minor improvements
This commit is contained in:
parent
1b0eb56224
commit
5de47561b1
6 changed files with 56 additions and 17 deletions
|
@ -419,17 +419,18 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn too_large_segment_duration_test() {
|
||||
let playlist = r#"
|
||||
#EXTM3U
|
||||
#EXT-X-TARGETDURATION:8
|
||||
#EXT-X-VERSION:3
|
||||
#EXTINF:9.009,
|
||||
http://media.example.com/first.ts
|
||||
#EXTINF:9.509,
|
||||
http://media.example.com/second.ts
|
||||
#EXTINF:3.003,
|
||||
http://media.example.com/third.ts
|
||||
#EXT-X-ENDLIST"#;
|
||||
let playlist = concat!(
|
||||
"#EXTM3U\n",
|
||||
"#EXT-X-TARGETDURATION:8\n",
|
||||
"#EXT-X-VERSION:3\n",
|
||||
"#EXTINF:9.009,\n",
|
||||
"http://media.example.com/first.ts\n",
|
||||
"#EXTINF:9.509,\n",
|
||||
"http://media.example.com/second.ts\n",
|
||||
"#EXTINF:3.003,\n",
|
||||
"http://media.example.com/third.ts\n",
|
||||
"#EXT-X-ENDLIST\n"
|
||||
);
|
||||
|
||||
// Error (allowable segment duration = target duration = 8)
|
||||
assert!(playlist.parse::<MediaPlaylist>().is_err());
|
||||
|
|
|
@ -53,6 +53,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_parser() {
|
||||
assert_eq!("#EXTM3U".parse::<ExtM3u>().unwrap(), ExtM3u);
|
||||
assert!("#EXTM2U".parse::<ExtM3u>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -14,6 +14,7 @@ use crate::{Error, RequiredVersion};
|
|||
/// # Examples
|
||||
///
|
||||
/// Parsing from a [`str`]:
|
||||
///
|
||||
/// ```
|
||||
/// # use hls_m3u8::tags::ExtXVersion;
|
||||
/// #
|
||||
|
@ -25,7 +26,9 @@ use crate::{Error, RequiredVersion};
|
|||
/// );
|
||||
/// # Ok::<(), Box<dyn ::std::error::Error>>(())
|
||||
/// ```
|
||||
///
|
||||
/// Converting to a [`str`]:
|
||||
///
|
||||
/// ```
|
||||
/// # use hls_m3u8::tags::ExtXVersion;
|
||||
/// #
|
||||
|
@ -49,6 +52,7 @@ impl ExtXVersion {
|
|||
/// Makes a new [`ExtXVersion`] tag.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use hls_m3u8::tags::ExtXVersion;
|
||||
/// use hls_m3u8::types::ProtocolVersion;
|
||||
|
@ -60,6 +64,7 @@ impl ExtXVersion {
|
|||
/// Returns the [`ProtocolVersion`] of the playlist, containing this tag.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use hls_m3u8::tags::ExtXVersion;
|
||||
/// use hls_m3u8::types::ProtocolVersion;
|
||||
|
@ -78,11 +83,14 @@ impl RequiredVersion for ExtXVersion {
|
|||
}
|
||||
|
||||
impl fmt::Display for ExtXVersion {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) }
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
//
|
||||
write!(f, "{}{}", Self::PREFIX, self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ExtXVersion {
|
||||
fn default() -> Self { Self(ProtocolVersion::V1) }
|
||||
fn default() -> Self { Self(ProtocolVersion::default()) }
|
||||
}
|
||||
|
||||
impl From<ProtocolVersion> for ExtXVersion {
|
||||
|
|
|
@ -27,8 +27,8 @@ pub struct ExtXIFrameStreamInf {
|
|||
stream_inf: StreamInf,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq)]
|
||||
/// Builder for [`ExtXIFrameStreamInf`].
|
||||
#[derive(Default, Debug, Clone, PartialEq)]
|
||||
pub struct ExtXIFrameStreamInfBuilder {
|
||||
uri: Option<String>,
|
||||
stream_inf: StreamInfBuilder,
|
||||
|
|
|
@ -67,7 +67,10 @@ impl RequiredVersion for ExtXDiscontinuitySequence {
|
|||
}
|
||||
|
||||
impl fmt::Display for ExtXDiscontinuitySequence {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) }
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
//
|
||||
write!(f, "{}{}", Self::PREFIX, self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for ExtXDiscontinuitySequence {
|
||||
|
|
30
src/utils.rs
30
src/utils.rs
|
@ -90,6 +90,7 @@ pub(crate) fn quote<T: ToString>(value: T) -> String {
|
|||
/// it will remove it and return the rest of the input.
|
||||
///
|
||||
/// # Error
|
||||
///
|
||||
/// This function will return `Error::MissingTag`, if the input doesn't start
|
||||
/// with the tag, that has been passed to this function.
|
||||
pub(crate) fn tag<T>(input: &str, tag: T) -> crate::Result<&str>
|
||||
|
@ -99,8 +100,8 @@ where
|
|||
if !input.trim().starts_with(tag.as_ref()) {
|
||||
return Err(Error::missing_tag(tag.as_ref(), input));
|
||||
}
|
||||
let result = input.split_at(tag.as_ref().len()).1;
|
||||
Ok(result)
|
||||
|
||||
Ok(input.trim().split_at(tag.as_ref().len()).1)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -145,5 +146,30 @@ mod tests {
|
|||
assert_eq!(input, "SampleString");
|
||||
|
||||
assert!(tag(input, "B").is_err());
|
||||
|
||||
assert_eq!(
|
||||
tag(
|
||||
concat!(
|
||||
"\n #EXTM3U\n",
|
||||
" #EXT-X-TARGETDURATION:5220\n",
|
||||
" #EXTINF:0,\n",
|
||||
" http://media.example.com/entire1.ts\n",
|
||||
" #EXTINF:5220,\n",
|
||||
" http://media.example.com/entire2.ts\n",
|
||||
" #EXT-X-ENDLIST"
|
||||
),
|
||||
"#EXTM3U"
|
||||
)
|
||||
.unwrap(),
|
||||
concat!(
|
||||
"\n",
|
||||
" #EXT-X-TARGETDURATION:5220\n",
|
||||
" #EXTINF:0,\n",
|
||||
" http://media.example.com/entire1.ts\n",
|
||||
" #EXTINF:5220,\n",
|
||||
" http://media.example.com/entire2.ts\n",
|
||||
" #EXT-X-ENDLIST"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue