2019-09-15 08:40:45 +00:00
|
|
|
//! Credits go to
|
|
|
|
//! - https://github.com/globocom/m3u8/blob/master/tests/playlists.py
|
|
|
|
use hls_m3u8::tags::*;
|
|
|
|
use hls_m3u8::MediaPlaylist;
|
|
|
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_simple_playlist() {
|
2020-02-10 12:20:39 +00:00
|
|
|
let playlist = concat!(
|
|
|
|
"#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\n"
|
|
|
|
);
|
2019-09-15 08:40:45 +00:00
|
|
|
|
|
|
|
let media_playlist = playlist.parse::<MediaPlaylist>().unwrap();
|
|
|
|
assert_eq!(
|
2020-02-10 12:20:39 +00:00
|
|
|
media_playlist.target_duration(),
|
2019-09-15 08:40:45 +00:00
|
|
|
ExtXTargetDuration::new(Duration::from_secs(5220))
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(media_playlist.segments().len(), 2);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
media_playlist.segments()[0].inf_tag(),
|
|
|
|
&ExtInf::new(Duration::from_secs(0))
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
media_playlist.segments()[1].inf_tag(),
|
|
|
|
&ExtInf::new(Duration::from_secs(5220))
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
media_playlist.segments()[0].uri(),
|
2019-09-21 10:11:36 +00:00
|
|
|
&"http://media.example.com/entire1.ts".to_string()
|
2019-09-15 08:40:45 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
media_playlist.segments()[1].uri(),
|
2019-09-21 10:11:36 +00:00
|
|
|
&"http://media.example.com/entire2.ts".to_string()
|
2019-09-15 08:40:45 +00:00
|
|
|
);
|
|
|
|
}
|