Skip to content

Commit

Permalink
fix issue sile#64
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed Oct 1, 2021
1 parent 6c694d1 commit 3a742a9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ impl<'a> Iterator for AttributePairs<'a> {
// NOTE: it is okay to add 1 to the index, because an `=` is exactly 1 byte.
self.index = end + 1;

&self.string[start..end]
// NOTE: See https://github.com/sile/hls_m3u8/issues/64
self.string[start..end].trim()
};

let value = {
Expand Down Expand Up @@ -66,7 +67,8 @@ impl<'a> Iterator for AttributePairs<'a> {
self.index += end;
self.index -= start;

&self.string[start..end]
// NOTE: See https://github.com/sile/hls_m3u8/issues/64
self.string[start..end].trim()
};

Some((key, value))
Expand Down Expand Up @@ -190,7 +192,7 @@ mod test {
assert_eq!((1, Some(1)), pairs.size_hint());
assert_eq!(
pairs.next(),
Some(("ध्वनि स्थिति और्४५० नीचे ", "देखने लाभो द्वारा करके(विशेष"))
Some(("ध्वनि स्थिति और्४५० नीचे", "देखने लाभो द्वारा करके(विशेष"))
);

assert_eq!((0, Some(0)), pairs.size_hint());
Expand Down
8 changes: 1 addition & 7 deletions src/tags/master_playlist/variant_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,7 @@ impl<'a> TryFrom<&'a str> for VariantStream<'a> {
fn try_from(input: &'a str) -> Result<Self, Self::Error> {
if let Ok(input) = tag(input, Self::PREFIX_EXTXIFRAME) {
let uri = AttributePairs::new(input)
.find_map(|(key, value)| {
if key == "URI" {
Some(unquote(value))
} else {
None
}
})
.find_map(|(key, value)| (key == "URI").then(|| unquote(value)))
.ok_or_else(|| Error::missing_value("URI"))?;

Ok(Self::ExtXIFrame {
Expand Down
3 changes: 3 additions & 0 deletions tests/issues/assets/issue_00064.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=10000000
https://995107575.cloudvdn.com/a.m3u8?cdn=cn-gotcha03&domain=d1--cn-gotcha103.bilivideo.com&expires=1614619920&len=0&oi=1891753406&order=1&player=70YAALwcl0b9RGgW&pt=h5&ptype=0&qn=10000&secondToken=secondToken%3ACZ4ggpPHomuwcnT8XWDjJUp9eh8&sign=325afc8bc3b01ccbadeac084004ece64&sigparams=cdn%2Cexpires%2Clen%2Coi%2Cpt%2Cqn%2Ctrid&sl=1&src=4&streamid=live-qn%3Alive-qn%2Flive_402401719_42665292&trid=20d9f245179b4ef3a7e3635afaaa87ea&v3=1
34 changes: 34 additions & 0 deletions tests/issues/issue_00064.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// The relevant issue:
// https://github.com/sile/hls_m3u8/issues/55
use std::convert::TryFrom;

use hls_m3u8::tags::VariantStream;
use hls_m3u8::types::StreamData;
use hls_m3u8::MasterPlaylist;

use pretty_assertions::assert_eq;

#[test]
fn parse() {
let file = include_str!("assets/issue_00064.m3u8");

assert_eq!(
MasterPlaylist::try_from(file).unwrap(),
MasterPlaylist::builder()
.variant_streams(vec![
VariantStream::ExtXStreamInf {
uri: "https://995107575.cloudvdn.com/a.m3u8?cdn=cn-gotcha03&domain=d1--cn-gotcha103.bilivideo.com&expires=1614619920&len=0&oi=1891753406&order=1&player=70YAALwcl0b9RGgW&pt=h5&ptype=0&qn=10000&secondToken=secondToken%3ACZ4ggpPHomuwcnT8XWDjJUp9eh8&sign=325afc8bc3b01ccbadeac084004ece64&sigparams=cdn%2Cexpires%2Clen%2Coi%2Cpt%2Cqn%2Ctrid&sl=1&src=4&streamid=live-qn%3Alive-qn%2Flive_402401719_42665292&trid=20d9f245179b4ef3a7e3635afaaa87ea&v3=1".into(),
frame_rate: None,
audio: None,
subtitles: None,
closed_captions: None,
stream_data: StreamData::builder()
.bandwidth(10000000)
.build()
.unwrap()
}
])
.build()
.unwrap()
);
}

0 comments on commit 3a742a9

Please sign in to comment.