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