pub mod common;
use std::fs;
use std::env;
use ffprobe::ffprobe;
use file_format::FileFormat;
use dash_mpd::fetch::DashDownloader;
use common::{check_file_size_approx, setup_logging};
#[tokio::test]
async fn test_role_main() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "https://dash.akamaized.net/dash264/TestCasesIOP41/MultiTrack/alternative_content/2/manifest_alternative_content_ondemand.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("role-main.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.prefer_roles(vec!["main".to_string()])
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 189_121_991);
let format = FileFormat::from_file(&out).unwrap();
assert_eq!(format, FileFormat::Mpeg4Part14Video);
let meta = ffprobe(out).unwrap();
assert_eq!(meta.streams.len(), 2);
let video = meta.streams.iter()
.find(|s| s.codec_type.eq(&Some(String::from("video"))))
.expect("finding video stream");
assert_eq!(video.pix_fmt, Some(String::from("yuv420p10le")));
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
async fn test_role_alternate() {
if env::var("CI").is_ok() {
return;
}
let mpd_url = "https://dash.akamaized.net/dash264/TestCasesIOP41/MultiTrack/alternative_content/2/manifest_alternative_content_ondemand.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("role-alternate.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.prefer_roles(vec!["alternate".to_string(), "imaginary".to_string()])
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 196_041_016);
let meta = ffprobe(&out).unwrap();
assert_eq!(meta.streams.len(), 2);
let video = meta.streams.iter()
.find(|s| s.codec_type.eq(&Some(String::from("video"))))
.expect("finding video stream");
assert_eq!(video.pix_fmt, Some(String::from("yuv420p")));
let format = FileFormat::from_file(&out).unwrap();
assert_eq!(format, FileFormat::Mpeg4Part14Video);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}