feat: add allow_abr_only option
This commit is contained in:
parent
3596d07c8f
commit
f5e2407564
2 changed files with 54 additions and 0 deletions
|
@ -400,6 +400,7 @@ struct RustyPipeOpts {
|
|||
utc_offset_minutes: i16,
|
||||
report: bool,
|
||||
strict: bool,
|
||||
allow_abr_only: bool,
|
||||
auth: Option<bool>,
|
||||
visitor_data: Option<String>,
|
||||
}
|
||||
|
@ -556,6 +557,7 @@ impl Default for RustyPipeOpts {
|
|||
utc_offset_minutes: 0,
|
||||
report: false,
|
||||
strict: false,
|
||||
allow_abr_only: false,
|
||||
auth: None,
|
||||
visitor_data: None,
|
||||
}
|
||||
|
@ -962,6 +964,22 @@ impl RustyPipeBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
/// Allow fetching player data containing only the ABR (Adaptive bitrate) stream URL.
|
||||
///
|
||||
/// YouTube may return only the ABR stream URL and no URLs for individual streams
|
||||
/// when using desktop client. To access the streams, your application needs to support
|
||||
/// the ABR streaming protocol.
|
||||
///
|
||||
/// You also need to set the `allow_abr_only` option for the [`crate::param::StreamFilter`]
|
||||
/// to select streams without an URL.
|
||||
///
|
||||
/// **Info**: you can set this option for individual queries, too
|
||||
#[must_use]
|
||||
pub fn allow_abr_only(mut self) -> Self {
|
||||
self.default_opts.allow_abr_only = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Enable authentication for all requests
|
||||
///
|
||||
/// Depending on the client type RustyPipe uses either the authentication cookie or the
|
||||
|
@ -1780,6 +1798,20 @@ impl RustyPipeQuery {
|
|||
self
|
||||
}
|
||||
|
||||
/// Allow fetching player data containing only the ABR (Adaptive bitrate) stream URL.
|
||||
///
|
||||
/// YouTube may return only the ABR stream URL and no URLs for individual streams
|
||||
/// when using desktop client. To access the streams, your application needs to support
|
||||
/// the ABR streaming protocol.
|
||||
///
|
||||
/// You also need to set the `allow_abr_only` option for the [`crate::param::StreamFilter`]
|
||||
/// to select streams without an URL.
|
||||
#[must_use]
|
||||
pub fn allow_abr_only(mut self) -> Self {
|
||||
self.opts.allow_abr_only = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Enable authentication for this request
|
||||
///
|
||||
/// Depending on the client type RustyPipe uses either the authentication cookie or the
|
||||
|
@ -2356,6 +2388,7 @@ impl RustyPipeQuery {
|
|||
artist: ctx_src.artist.clone(),
|
||||
authenticated: self.opts.auth.unwrap_or_default(),
|
||||
session_po_token: ctx_src.session_po_token.clone(),
|
||||
allow_abr_only: self.opts.allow_abr_only,
|
||||
};
|
||||
|
||||
let request = self
|
||||
|
@ -2647,6 +2680,7 @@ struct MapRespCtx<'a> {
|
|||
artist: Option<ArtistId>,
|
||||
authenticated: bool,
|
||||
session_po_token: Option<PoToken>,
|
||||
allow_abr_only: bool,
|
||||
}
|
||||
|
||||
/// Options to give to the mapper when making requests;
|
||||
|
@ -2675,6 +2709,7 @@ impl<'a> MapRespCtx<'a> {
|
|||
artist: None,
|
||||
authenticated: false,
|
||||
session_po_token: None,
|
||||
allow_abr_only: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -384,6 +384,24 @@ impl MapResponse<VideoPlayer> for response::Player {
|
|||
)));
|
||||
}
|
||||
|
||||
// Sometimes YouTube Desktop does not output any URLs for adaptive streams.
|
||||
// Since this is currently rare, it is best to retry the request in this case
|
||||
// unless ABR streaming is explicitly requested.
|
||||
if !ctx.allow_abr_only
|
||||
&& !is_live
|
||||
&& !streaming_data.adaptive_formats.c.is_empty()
|
||||
&& streaming_data
|
||||
.adaptive_formats
|
||||
.c
|
||||
.iter()
|
||||
.all(|f| f.url.is_none() && f.signature_cipher.is_none())
|
||||
{
|
||||
return Err(ExtractionError::Unavailable {
|
||||
reason: UnavailabilityReason::TryAgain,
|
||||
msg: "no adaptive stream URLs".to_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
let video_info = VideoPlayerDetails {
|
||||
id: video_details.video_id,
|
||||
name: video_details.title,
|
||||
|
@ -1009,6 +1027,7 @@ mod tests {
|
|||
artist: None,
|
||||
authenticated: false,
|
||||
session_po_token: None,
|
||||
allow_abr_only: false,
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue