add subtitle mapping
This commit is contained in:
parent
0b10e67ff5
commit
77675209d5
7 changed files with 50 additions and 8 deletions
|
|
@ -21,7 +21,10 @@ use super::{
|
|||
use crate::{
|
||||
client::response::player,
|
||||
deobfuscate::Deobfuscator,
|
||||
model::{AudioCodec, AudioStream, PlayerData, Thumbnail, VideoCodec, VideoInfo, VideoStream},
|
||||
model::{
|
||||
AudioCodec, AudioStream, PlayerData, Subtitle, Thumbnail, VideoCodec, VideoInfo,
|
||||
VideoStream,
|
||||
},
|
||||
util,
|
||||
};
|
||||
|
||||
|
|
@ -384,12 +387,30 @@ fn map_player_data(response: Player, deobf: &Deobfuscator) -> Result<PlayerData>
|
|||
video_only_streams.sort_by(cmp_video_streams);
|
||||
audio_streams.sort_by_key(|s| s.average_bitrate);
|
||||
|
||||
let subtitles = response.captions.map_or(vec![], |captions| {
|
||||
captions
|
||||
.player_captions_tracklist_renderer
|
||||
.caption_tracks
|
||||
.iter()
|
||||
.map(|caption| {
|
||||
let lang_auto = caption.name.strip_suffix(" (auto-generated)");
|
||||
|
||||
Subtitle {
|
||||
url: caption.base_url.to_owned(),
|
||||
lang: caption.language_code.to_owned(),
|
||||
lang_name: lang_auto.unwrap_or(&caption.name).to_owned(),
|
||||
auto_generated: lang_auto.is_some(),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
|
||||
Ok(PlayerData {
|
||||
info: video_info,
|
||||
video_streams,
|
||||
video_only_streams,
|
||||
audio_streams,
|
||||
subtitles: vec![],
|
||||
subtitles,
|
||||
expires_in_seconds: streaming_data.expires_in_seconds,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -289,6 +289,10 @@ audio_streams:
|
|||
end: 631
|
||||
mime: "audio/mp4; codecs=\"mp4a.40.2\""
|
||||
codec: mp4a
|
||||
subtitles: []
|
||||
subtitles:
|
||||
- url: "https://www.youtube.com/api/timedtext?v=pPvd8UxmSbQ&caps=asr&xoaf=5&hl=en&ip=0.0.0.0&ipbits=0&expire=1659484955&sparams=ip,ipbits,expire,v,caps,xoaf&signature=EBFE9BB6A8D01D674157DE1F45A3BEDCAB35496B.3ED931CA7233F0FF5B19062AA22F803CC3D78215&key=yt8&lang=en&fmt=srv3"
|
||||
lang: en
|
||||
lang_name: English
|
||||
auto_generated: false
|
||||
expires_in_seconds: 21540
|
||||
|
||||
|
|
|
|||
|
|
@ -391,6 +391,10 @@ audio_streams:
|
|||
end: 631
|
||||
mime: "audio/mp4; codecs=\"mp4a.40.2\""
|
||||
codec: mp4a
|
||||
subtitles: []
|
||||
subtitles:
|
||||
- url: "https://www.youtube.com/api/timedtext?v=pPvd8UxmSbQ&caps=asr&xoaf=5&hl=en&ip=0.0.0.0&ipbits=0&expire=1659484955&sparams=ip,ipbits,expire,v,caps,xoaf&signature=AEE666C3CB25B28A0990FAF6483CAEFCC3F3BCEA.BBAD928634677A2CF95FB67B14F362750449F8F5&key=yt8&lang=en"
|
||||
lang: en
|
||||
lang_name: English
|
||||
auto_generated: false
|
||||
expires_in_seconds: 21540
|
||||
|
||||
|
|
|
|||
|
|
@ -277,6 +277,10 @@ audio_streams:
|
|||
end: 631
|
||||
mime: "audio/mp4; codecs=\"mp4a.40.2\""
|
||||
codec: mp4a
|
||||
subtitles: []
|
||||
subtitles:
|
||||
- url: "https://www.youtube.com/api/timedtext?v=pPvd8UxmSbQ&caps=asr&xoaf=5&hl=en&ip=0.0.0.0&ipbits=0&expire=1659491074&sparams=ip,ipbits,expire,v,caps,xoaf&signature=3CE2AD03E73FC43D83E992060A96D7B12F8E08E5.66CE90B1F3337004848429E1091E8423497239BF&key=yt8&lang=en"
|
||||
lang: en
|
||||
lang_name: English
|
||||
auto_generated: false
|
||||
expires_in_seconds: 21540
|
||||
|
||||
|
|
|
|||
|
|
@ -111,6 +111,10 @@ audio_streams:
|
|||
end: 631
|
||||
mime: "audio/mp4; codecs=\"mp4a.40.2\""
|
||||
codec: mp4a
|
||||
subtitles: []
|
||||
subtitles:
|
||||
- url: "https://www.youtube.com/api/timedtext?v=pPvd8UxmSbQ&caps=asr&xoaf=5&hl=en&ip=0.0.0.0&ipbits=0&expire=1659484955&sparams=ip,ipbits,expire,v,caps,xoaf&signature=A9D9281218AFF99DC34B5AA2F44D33455F419673.44DBC65B8479A5F088D6136FC4364894EECB3E0E&key=yt8&lang=en"
|
||||
lang: en
|
||||
lang_name: English
|
||||
auto_generated: false
|
||||
expires_in_seconds: 21540
|
||||
|
||||
|
|
|
|||
|
|
@ -391,6 +391,10 @@ audio_streams:
|
|||
end: 631
|
||||
mime: "audio/mp4; codecs=\"mp4a.40.2\""
|
||||
codec: mp4a
|
||||
subtitles: []
|
||||
subtitles:
|
||||
- url: "https://www.youtube.com/api/timedtext?v=pPvd8UxmSbQ&caps=asr&xoaf=5&hl=en&ip=0.0.0.0&ipbits=0&expire=1659484955&sparams=ip,ipbits,expire,v,caps,xoaf&signature=DAB4A9E85FEBC1ED6E527CD113FB58F798859727.32748FCE40F82BE8A271BF5FF248C2B283B57F89&key=yt8&lang=en"
|
||||
lang: en
|
||||
lang_name: English
|
||||
auto_generated: false
|
||||
expires_in_seconds: 21540
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,8 @@ pub struct Thumbnail {
|
|||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct Subtitle {
|
||||
pub url: String,
|
||||
pub locale: Locale,
|
||||
pub lang: String,
|
||||
pub lang_name: String,
|
||||
pub auto_generated: bool,
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue