fix: add livestream extraction

This commit is contained in:
ThetaDev 2022-09-27 23:12:14 +02:00
parent fe5468313a
commit 1297bcb641
8 changed files with 63 additions and 35 deletions

View file

@ -116,11 +116,9 @@ impl MapResponse<VideoPlayer> for response::Player {
let mut warnings = vec![];
// Check playability status
match self.playability_status {
let is_live = match self.playability_status {
response::player::PlayabilityStatus::Ok { live_streamability } => {
if live_streamability.is_some() {
bail!("Active livestreams are not supported")
}
live_streamability.is_some()
}
response::player::PlayabilityStatus::Unplayable { reason } => {
bail!("Video is unplayable. Reason: {}", reason)
@ -192,43 +190,45 @@ impl MapResponse<VideoPlayer> for response::Player {
let mut formats = streaming_data.formats.c;
formats.append(&mut streaming_data.adaptive_formats.c);
warnings.append(&mut streaming_data.formats.warnings);
warnings.append(&mut streaming_data.adaptive_formats.warnings);
let mut last_nsig: [String; 2] = [String::new(), String::new()];
let mut video_streams: Vec<VideoStream> = Vec::new();
let mut video_only_streams: Vec<VideoStream> = Vec::new();
let mut audio_streams: Vec<AudioStream> = Vec::new();
for f in formats {
if f.format_type == player::FormatType::FormatStreamTypeOtf {
continue;
}
if !is_live {
let mut last_nsig: [String; 2] = [String::new(), String::new()];
match (f.is_video(), f.is_audio()) {
(true, true) => {
let mut map_res = map_video_stream(f, deobf, &mut last_nsig);
warnings.append(&mut map_res.warnings);
if let Some(c) = map_res.c {
video_streams.push(c);
};
warnings.append(&mut streaming_data.formats.warnings);
warnings.append(&mut streaming_data.adaptive_formats.warnings);
for f in formats {
if f.format_type == player::FormatType::FormatStreamTypeOtf {
continue;
}
(true, false) => {
let mut map_res = map_video_stream(f, deobf, &mut last_nsig);
warnings.append(&mut map_res.warnings);
if let Some(c) = map_res.c {
video_only_streams.push(c);
};
match (f.is_video(), f.is_audio()) {
(true, true) => {
let mut map_res = map_video_stream(f, deobf, &mut last_nsig);
warnings.append(&mut map_res.warnings);
if let Some(c) = map_res.c {
video_streams.push(c);
};
}
(true, false) => {
let mut map_res = map_video_stream(f, deobf, &mut last_nsig);
warnings.append(&mut map_res.warnings);
if let Some(c) = map_res.c {
video_only_streams.push(c);
};
}
(false, true) => {
let mut map_res = map_audio_stream(f, deobf, &mut last_nsig);
warnings.append(&mut map_res.warnings);
if let Some(c) = map_res.c {
audio_streams.push(c);
};
}
(false, false) => warnings.push(format!("invalid stream: itag {}", f.itag)),
}
(false, true) => {
let mut map_res = map_audio_stream(f, deobf, &mut last_nsig);
warnings.append(&mut map_res.warnings);
if let Some(c) = map_res.c {
audio_streams.push(c);
};
}
(false, false) => warnings.push(format!("invalid stream: itag {}", f.itag)),
}
}
@ -261,6 +261,8 @@ impl MapResponse<VideoPlayer> for response::Player {
audio_streams,
subtitles,
expires_in_seconds: streaming_data.expires_in_seconds,
hls_manifest_url: streaming_data.hls_manifest_url,
dash_manifest_url: streaming_data.dash_manifest_url,
},
warnings,
})
@ -731,6 +733,21 @@ mod tests {
assert!(player_data.expires_in_seconds > 10000);
}
/*
#[rstest]
#[case::desktop(ClientType::Desktop)]
// #[case::tv_html5_embed(ClientType::TvHtml5Embed)]
// #[case::android(ClientType::Android)]
// #[case::ios(ClientType::Ios)]
#[test_log::test(tokio::test)]
async fn get_player_live(#[case] client_type: ClientType) {
let rp = RustyPipe::builder().strict().build();
let player_data = rp.query().player("86YLFOog4GM", client_type).await.unwrap();
dbg!(&player_data);
}
*/
#[test]
fn t_cipher_to_url() {
let signature_cipher = "s=w%3DAe%3DA6aDNQLkViKS7LOm9QtxZJHKwb53riq9qEFw-ecBWJCAiA%3DcEg0tn3dty9jEHszfzh4Ud__bg9CEHVx4ix-7dKsIPAhIQRw8JQ0qOA&sp=sig&url=https://rr5---sn-h0jelnez.googlevideo.com/videoplayback%3Fexpire%3D1659376413%26ei%3Dvb7nYvH5BMK8gAfBj7ToBQ%26ip%3D2003%253Ade%253Aaf06%253A6300%253Ac750%253A1b77%253Ac74a%253A80e3%26id%3Do-AB_BABwrXZJN428ZwDxq5ScPn2AbcGODnRlTVhCQ3mj2%26itag%3D251%26source%3Dyoutube%26requiressl%3Dyes%26mh%3DhH%26mm%3D31%252C26%26mn%3Dsn-h0jelnez%252Csn-4g5ednsl%26ms%3Dau%252Conr%26mv%3Dm%26mvi%3D5%26pl%3D37%26initcwndbps%3D1588750%26spc%3DlT-Khi831z8dTejFIRCvCEwx_6romtM%26vprv%3D1%26mime%3Daudio%252Fwebm%26ns%3Db_Mq_qlTFcSGlG9RpwpM9xQH%26gir%3Dyes%26clen%3D3781277%26dur%3D229.301%26lmt%3D1655510291473933%26mt%3D1659354538%26fvip%3D5%26keepalive%3Dyes%26fexp%3D24001373%252C24007246%26c%3DWEB%26rbqsm%3Dfr%26txp%3D4532434%26n%3Dd2g6G2hVqWIXxedQ%26sparams%3Dexpire%252Cei%252Cip%252Cid%252Citag%252Csource%252Crequiressl%252Cspc%252Cvprv%252Cmime%252Cns%252Cgir%252Cclen%252Cdur%252Clmt%26lsparams%3Dmh%252Cmm%252Cmn%252Cms%252Cmv%252Cmvi%252Cpl%252Cinitcwndbps%26lsig%3DAG3C_xAwRQIgCKCGJ1iu4wlaGXy3jcJyU3inh9dr1FIfqYOZEG_MdmACIQCbungkQYFk7EhD6K2YvLaHFMjKOFWjw001_tLb0lPDtg%253D%253D";