fix: only use auth-enabled clients for fetching player with auth option enabled
This commit is contained in:
parent
addeb82110
commit
2b2b4af0b2
2 changed files with 24 additions and 11 deletions
|
|
@ -1712,14 +1712,14 @@ impl RustyPipeQuery {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the first client type from the given list which has login credentials available.
|
||||
///
|
||||
/// Returns [`None`] if authentication has been disabled or there are no available client types.
|
||||
pub fn auth_enabled_client(&self, clients: &[ClientType]) -> Option<ClientType> {
|
||||
if self.opts.auth == Some(false) {
|
||||
return None;
|
||||
}
|
||||
let (has_cookie, has_token) = {
|
||||
/// Filter the given list of client types and iterate over those which have login credentials available.
|
||||
pub fn auth_enabled_clients<'a>(
|
||||
&self,
|
||||
clients: &'a [ClientType],
|
||||
) -> impl Iterator<Item = ClientType> + 'a {
|
||||
let (has_cookie, has_token) = if self.opts.auth == Some(false) {
|
||||
(false, false)
|
||||
} else {
|
||||
let auth_cookie = self.client.inner.cache.auth_cookie.read().unwrap();
|
||||
let oauth_token = self.client.inner.cache.oauth_token.read().unwrap();
|
||||
(auth_cookie.is_some(), oauth_token.is_some())
|
||||
|
|
@ -1727,7 +1727,7 @@ impl RustyPipeQuery {
|
|||
|
||||
clients
|
||||
.iter()
|
||||
.find(|c| {
|
||||
.filter(move |c| {
|
||||
if c.is_web() {
|
||||
has_cookie
|
||||
} else if **c == ClientType::Tv {
|
||||
|
|
@ -1739,6 +1739,13 @@ impl RustyPipeQuery {
|
|||
.copied()
|
||||
}
|
||||
|
||||
/// Return the first client type from the given list which has login credentials available.
|
||||
///
|
||||
/// Returns [`None`] if authentication has been disabled or there are no available client types.
|
||||
pub fn auth_enabled_client(&self, clients: &[ClientType]) -> Option<ClientType> {
|
||||
self.auth_enabled_clients(clients).next()
|
||||
}
|
||||
|
||||
/// Create a new context object, which is included in every request to
|
||||
/// the YouTube API and contains language, country and device parameters.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -79,8 +79,14 @@ impl RustyPipeQuery {
|
|||
let video_id = video_id.as_ref();
|
||||
let mut last_e = Error::Other("no clients".into());
|
||||
|
||||
for client in clients {
|
||||
let res = self.player_from_client(video_id, *client).await;
|
||||
let clients_iter: Box<dyn Iterator<Item = ClientType>> = if self.opts.auth == Some(true) {
|
||||
Box::new(self.auth_enabled_clients(clients))
|
||||
} else {
|
||||
Box::new(clients.iter().cloned())
|
||||
};
|
||||
|
||||
for client in clients_iter {
|
||||
let res = self.player_from_client(video_id, client).await;
|
||||
match res {
|
||||
Ok(res) => return Ok(res),
|
||||
Err(Error::Extraction(e)) => {
|
||||
|
|
|
|||
Reference in a new issue