mirror of
https://github.com/sile/hls_m3u8.git
synced 2024-12-22 20:16:27 +00:00
commit
9ec0687f5e
11 changed files with 29 additions and 52 deletions
|
@ -220,13 +220,9 @@ impl<'a> MasterPlaylist<'a> {
|
|||
|
||||
/// Returns all streams, which have an audio group id.
|
||||
pub fn audio_streams(&self) -> impl Iterator<Item = &VariantStream<'a>> {
|
||||
self.variant_streams.iter().filter(|stream| {
|
||||
if let VariantStream::ExtXStreamInf { audio: Some(_), .. } = stream {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
self.variant_streams
|
||||
.iter()
|
||||
.filter(|stream| matches!(stream, VariantStream::ExtXStreamInf { audio: Some(_), .. }))
|
||||
}
|
||||
|
||||
/// Returns all streams, which have a video group id.
|
||||
|
@ -416,13 +412,11 @@ impl<'a> MasterPlaylistBuilder<'a> {
|
|||
}
|
||||
|
||||
fn check_media_group<T: AsRef<str>>(&self, media_type: MediaType, group_id: T) -> bool {
|
||||
if let Some(value) = &self.media {
|
||||
self.media.as_ref().map_or(false, |value| {
|
||||
value.iter().any(|media| {
|
||||
media.media_type == media_type && media.group_id().as_ref() == group_id.as_ref()
|
||||
})
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -315,12 +315,11 @@ impl<'a> MediaPlaylistBuilder<'a> {
|
|||
method, iv, format, ..
|
||||
})) = key
|
||||
{
|
||||
if *method == EncryptionMethod::Aes128 && *iv == InitializationVector::Missing {
|
||||
if format.is_none() {
|
||||
*iv = InitializationVector::Number(segment.number as u128);
|
||||
} else if let Some(KeyFormat::Identity) = format {
|
||||
*iv = InitializationVector::Number(segment.number as u128);
|
||||
}
|
||||
if *method == EncryptionMethod::Aes128
|
||||
&& *iv == InitializationVector::Missing
|
||||
&& (format.is_none() || &mut Some(KeyFormat::Identity) == format)
|
||||
{
|
||||
*iv = InitializationVector::Number(segment.number as u128);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,9 +223,9 @@ impl<'a> TryFrom<&'a str> for ExtXSessionData<'a> {
|
|||
if let Some(value) = session_value {
|
||||
if uri.is_some() {
|
||||
return Err(Error::custom("unexpected URI"));
|
||||
} else {
|
||||
SessionData::Value(value)
|
||||
}
|
||||
|
||||
SessionData::Value(value)
|
||||
} else if let Some(uri) = uri {
|
||||
SessionData::Uri(uri)
|
||||
} else {
|
||||
|
|
|
@ -379,7 +379,7 @@ impl<'a> TryFrom<&'a str> for VariantStream<'a> {
|
|||
"AUDIO" => audio = Some(unquote(value)),
|
||||
"SUBTITLES" => subtitles = Some(unquote(value)),
|
||||
"CLOSED-CAPTIONS" => {
|
||||
closed_captions = Some(ClosedCaptions::try_from(value).unwrap())
|
||||
closed_captions = Some(ClosedCaptions::try_from(value).unwrap());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -380,21 +380,21 @@ impl<'a> TryFrom<&'a str> for ExtXDateRange<'a> {
|
|||
"START-DATE" => {
|
||||
#[cfg(feature = "chrono")]
|
||||
{
|
||||
start_date = Some(unquote(value).parse().map_err(Error::chrono)?)
|
||||
start_date = Some(unquote(value).parse().map_err(Error::chrono)?);
|
||||
}
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
{
|
||||
start_date = Some(unquote(value))
|
||||
start_date = Some(unquote(value));
|
||||
}
|
||||
}
|
||||
"END-DATE" => {
|
||||
#[cfg(feature = "chrono")]
|
||||
{
|
||||
end_date = Some(unquote(value).parse().map_err(Error::chrono)?)
|
||||
end_date = Some(unquote(value).parse().map_err(Error::chrono)?);
|
||||
}
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
{
|
||||
end_date = Some(unquote(value))
|
||||
end_date = Some(unquote(value));
|
||||
}
|
||||
}
|
||||
"DURATION" => {
|
||||
|
|
|
@ -354,11 +354,9 @@ impl_from_ranges![u64, u32, u16, u8, usize, i32];
|
|||
#[must_use]
|
||||
impl RangeBounds<usize> for ByteRange {
|
||||
fn start_bound(&self) -> Bound<&usize> {
|
||||
if let Some(start) = &self.start {
|
||||
Bound::Included(start)
|
||||
} else {
|
||||
Bound::Unbounded
|
||||
}
|
||||
self.start
|
||||
.as_ref()
|
||||
.map_or(Bound::Unbounded, Bound::Included)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -182,7 +182,7 @@ impl ::core::hash::Hash for Float {
|
|||
} else {
|
||||
// I do not think it matters to differentiate between architectures, that use
|
||||
// big endian by default and those, that use little endian.
|
||||
state.write(&self.to_be_bytes())
|
||||
state.write(&self.to_be_bytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ use crate::RequiredVersion;
|
|||
/// ```
|
||||
///
|
||||
/// [`KeyFormat`]: crate::types::KeyFormat
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct KeyFormatVersions {
|
||||
// NOTE(Luro02): if the current array is not big enough one can easily increase
|
||||
// the number of elements or change the type to something bigger,
|
||||
|
@ -295,7 +295,7 @@ impl Extend<u8> for KeyFormatVersions {
|
|||
|
||||
impl<'a> Extend<&'a u8> for KeyFormatVersions {
|
||||
fn extend<I: IntoIterator<Item = &'a u8>>(&mut self, iter: I) {
|
||||
<Self as Extend<u8>>::extend(self, iter.into_iter().copied())
|
||||
<Self as Extend<u8>>::extend(self, iter.into_iter().copied());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -346,17 +346,7 @@ impl FromIterator<u8> for KeyFormatVersions {
|
|||
|
||||
impl<'a> FromIterator<&'a u8> for KeyFormatVersions {
|
||||
fn from_iter<I: IntoIterator<Item = &'a u8>>(iter: I) -> Self {
|
||||
<Self as FromIterator<u8>>::from_iter(iter.into_iter().copied())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for KeyFormatVersions {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
buffer: [0; 9],
|
||||
len: 0,
|
||||
}
|
||||
iter.into_iter().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,7 +403,7 @@ impl fmt::Display for KeyFormatVersions {
|
|||
}
|
||||
|
||||
impl<T: AsRef<[usize]>> From<T> for KeyFormatVersions {
|
||||
fn from(value: T) -> Self { Self::from_iter(value.as_ref().iter().map(|i| *i as u8)) }
|
||||
fn from(value: T) -> Self { value.as_ref().iter().map(|i| *i as u8).collect() }
|
||||
}
|
||||
|
||||
/// `Iterator` for [`KeyFormatVersions`].
|
||||
|
|
|
@ -323,12 +323,12 @@ impl<'a> TryFrom<&'a str> for StreamData<'a> {
|
|||
value
|
||||
.parse::<u64>()
|
||||
.map_err(|e| Error::parse_int(value, e))?,
|
||||
)
|
||||
);
|
||||
}
|
||||
"CODECS" => codecs = Some(TryFrom::try_from(unquote(value))?),
|
||||
"RESOLUTION" => resolution = Some(value.parse()?),
|
||||
"HDCP-LEVEL" => {
|
||||
hdcp_level = Some(value.parse::<HdcpLevel>().map_err(Error::strum)?)
|
||||
hdcp_level = Some(value.parse::<HdcpLevel>().map_err(Error::strum)?);
|
||||
}
|
||||
"VIDEO" => video = Some(unquote(value)),
|
||||
_ => {
|
||||
|
|
|
@ -193,7 +193,7 @@ impl ::core::hash::Hash for UFloat {
|
|||
|
||||
// I do not think it matters to differentiate between architectures, that use
|
||||
// big endian by default and those, that use little endian.
|
||||
state.write(&self.to_be_bytes())
|
||||
state.write(&self.to_be_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,11 +73,7 @@ pub(crate) fn unquote(value: &str) -> Cow<'_, str> {
|
|||
if value.starts_with('"') && value.ends_with('"') {
|
||||
let result = Cow::Borrowed(&value[1..value.len() - 1]);
|
||||
|
||||
if result
|
||||
.chars()
|
||||
.find(|c| *c == '"' || *c == '\n' || *c == '\r')
|
||||
.is_none()
|
||||
{
|
||||
if !result.chars().any(|c| c == '"' || c == '\n' || c == '\r') {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue