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