fix: clippy warnings
This commit is contained in:
parent
63d2a0fb36
commit
05f609e247
11 changed files with 97 additions and 118 deletions
|
|
@ -253,7 +253,7 @@ impl RustyPipe {
|
|||
reporter: Option<Box<dyn Reporter + Sync + Send>>,
|
||||
user_agent: Option<String>,
|
||||
) -> Self {
|
||||
let user_agent = user_agent.unwrap_or(DEFAULT_UA.to_owned());
|
||||
let user_agent = user_agent.unwrap_or_else(|| DEFAULT_UA.to_owned());
|
||||
|
||||
let http = ClientBuilder::new()
|
||||
.user_agent(user_agent.to_owned())
|
||||
|
|
@ -563,6 +563,7 @@ impl RustyPipeQuery {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn execute_request_deobf<
|
||||
R: DeserializeOwned + MapResponse<M> + Debug,
|
||||
M,
|
||||
|
|
@ -767,7 +768,7 @@ async fn extract_desktop_client_version(http: Client, consent_cookie: String) ->
|
|||
.context("Failed to download sw.js")?;
|
||||
|
||||
util::get_cg_from_regexes(CLIENT_VERSION_REGEXES.iter(), &swjs, 1)
|
||||
.ok_or(anyhow!("Could not find desktop client version in sw.js"))
|
||||
.ok_or_else(|| anyhow!("Could not find desktop client version in sw.js"))
|
||||
};
|
||||
|
||||
let from_html = async {
|
||||
|
|
@ -780,9 +781,8 @@ async fn extract_desktop_client_version(http: Client, consent_cookie: String) ->
|
|||
.await
|
||||
.context("Failed to get YT Desktop page")?;
|
||||
|
||||
util::get_cg_from_regexes(CLIENT_VERSION_REGEXES.iter(), &html, 1).ok_or(anyhow!(
|
||||
"Could not find desktop client version on html page"
|
||||
))
|
||||
util::get_cg_from_regexes(CLIENT_VERSION_REGEXES.iter(), &html, 1)
|
||||
.ok_or_else(|| anyhow!("Could not find desktop client version on html page"))
|
||||
};
|
||||
|
||||
match from_swjs.await {
|
||||
|
|
@ -806,7 +806,7 @@ async fn extract_music_client_version(http: Client, consent_cookie: String) -> R
|
|||
.context("Failed to download sw.js")?;
|
||||
|
||||
util::get_cg_from_regexes(CLIENT_VERSION_REGEXES.iter(), &swjs, 1)
|
||||
.ok_or(anyhow!("Could not find desktop client version in sw.js"))
|
||||
.ok_or_else(|| anyhow!("Could not find desktop client version in sw.js"))
|
||||
};
|
||||
|
||||
let from_html = async {
|
||||
|
|
@ -817,9 +817,8 @@ async fn extract_music_client_version(http: Client, consent_cookie: String) -> R
|
|||
.await
|
||||
.context("Failed to get YT Desktop page")?;
|
||||
|
||||
util::get_cg_from_regexes(CLIENT_VERSION_REGEXES.iter(), &html, 1).ok_or(anyhow!(
|
||||
"Could not find desktop client version on html page"
|
||||
))
|
||||
util::get_cg_from_regexes(CLIENT_VERSION_REGEXES.iter(), &html, 1)
|
||||
.ok_or_else(|| anyhow!("Could not find desktop client version on html page"))
|
||||
};
|
||||
|
||||
match from_swjs.await {
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ fn deobf_nsig(
|
|||
let nsig: String;
|
||||
match url_params.get("n") {
|
||||
Some(n) => {
|
||||
nsig = if n.to_owned() == last_nsig[0] {
|
||||
nsig = if n == &last_nsig[0] {
|
||||
last_nsig[1].to_owned()
|
||||
} else {
|
||||
let nsig = deobf.deobfuscate_nsig(n)?;
|
||||
|
|
@ -503,7 +503,7 @@ fn parse_mime(mime: &str) -> Option<(&str, Vec<&str>)> {
|
|||
static PATTERN: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r#"(\w+/\w+);\scodecs="([a-zA-Z-0-9.,\s]*)""#).unwrap());
|
||||
|
||||
let captures = some_or_bail!(PATTERN.captures(&mime).ok().flatten(), None);
|
||||
let captures = some_or_bail!(PATTERN.captures(mime).ok().flatten(), None);
|
||||
Some((
|
||||
captures.get(1).unwrap().as_str(),
|
||||
captures
|
||||
|
|
|
|||
|
|
@ -183,21 +183,15 @@ impl MapResponse<Playlist> for response::Playlist {
|
|||
let description = self.header.playlist_header_renderer.description_text;
|
||||
|
||||
let channel = match self.header.playlist_header_renderer.owner_text {
|
||||
Some(owner_text) => match owner_text {
|
||||
TextLink::Browse {
|
||||
text,
|
||||
page_type,
|
||||
browse_id,
|
||||
} => match page_type {
|
||||
PageType::Channel => Some(Channel {
|
||||
id: browse_id,
|
||||
name: text,
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
},
|
||||
None => None,
|
||||
Some(TextLink::Browse {
|
||||
text,
|
||||
page_type: PageType::Channel,
|
||||
browse_id,
|
||||
}) => Some(Channel {
|
||||
id: browse_id,
|
||||
name: text,
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let mut warnings = video_items.warnings.to_owned();
|
||||
|
|
@ -256,7 +250,7 @@ impl MapResponse<(Vec<Video>, Option<String>)> for response::PlaylistCont {
|
|||
}
|
||||
|
||||
fn map_playlist_items(
|
||||
items: &Vec<response::VideoListItem<response::playlist::PlaylistVideo>>,
|
||||
items: &[response::VideoListItem<response::playlist::PlaylistVideo>],
|
||||
) -> (Vec<Video>, Option<String>) {
|
||||
let mut ctoken: Option<String> = None;
|
||||
let videos = items
|
||||
|
|
@ -265,30 +259,27 @@ fn map_playlist_items(
|
|||
response::VideoListItem::GridVideoRenderer { video } => match &video.channel {
|
||||
TextLink::Browse {
|
||||
text,
|
||||
page_type,
|
||||
page_type: PageType::Channel,
|
||||
browse_id,
|
||||
} => match page_type {
|
||||
PageType::Channel => Some(Video {
|
||||
id: video.video_id.to_owned(),
|
||||
title: video.title.to_owned(),
|
||||
length: video.length_seconds,
|
||||
thumbnails: video
|
||||
.thumbnail
|
||||
.thumbnails
|
||||
.iter()
|
||||
.map(|t| Thumbnail {
|
||||
url: t.url.to_owned(),
|
||||
width: t.width,
|
||||
height: t.height,
|
||||
})
|
||||
.collect(),
|
||||
channel: Channel {
|
||||
id: browse_id.to_string(),
|
||||
name: text.to_owned(),
|
||||
},
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
} => Some(Video {
|
||||
id: video.video_id.to_owned(),
|
||||
title: video.title.to_owned(),
|
||||
length: video.length_seconds,
|
||||
thumbnails: video
|
||||
.thumbnail
|
||||
.thumbnails
|
||||
.iter()
|
||||
.map(|t| Thumbnail {
|
||||
url: t.url.to_owned(),
|
||||
width: t.width,
|
||||
height: t.height,
|
||||
})
|
||||
.collect(),
|
||||
channel: Channel {
|
||||
id: browse_id.to_string(),
|
||||
name: text.to_owned(),
|
||||
},
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
response::VideoListItem::ContinuationItemRenderer {
|
||||
|
|
|
|||
|
|
@ -215,20 +215,20 @@ pub struct MusicContinuationData {
|
|||
pub continuation: String,
|
||||
}
|
||||
|
||||
impl Into<crate::model::Thumbnail> for Thumbnail {
|
||||
fn into(self) -> crate::model::Thumbnail {
|
||||
impl From<Thumbnail> for crate::model::Thumbnail {
|
||||
fn from(tn: Thumbnail) -> Self {
|
||||
crate::model::Thumbnail {
|
||||
url: self.url,
|
||||
width: self.width,
|
||||
height: self.height,
|
||||
url: tn.url,
|
||||
width: tn.width,
|
||||
height: tn.height,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Vec<crate::model::Thumbnail>> for Thumbnails {
|
||||
fn into(self) -> Vec<crate::model::Thumbnail> {
|
||||
impl From<Thumbnails> for Vec<crate::model::Thumbnail> {
|
||||
fn from(ts: Thumbnails) -> Self {
|
||||
let mut thumbnails = vec![];
|
||||
for t in self.thumbnails {
|
||||
for t in ts.thumbnails {
|
||||
thumbnails.push(t.into());
|
||||
}
|
||||
thumbnails
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
#![allow(clippy::enum_variant_names)]
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde_with::serde_as;
|
||||
use serde_with::{DefaultOnError, VecSkipError};
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ fn get_sig_fn_name(player_js: &str) -> Result<String> {
|
|||
}
|
||||
|
||||
fn caller_function(fn_name: &str) -> String {
|
||||
"var ".to_owned() + DEOBFUSCATION_FUNC_NAME + "=" + &fn_name + ";"
|
||||
format!("var {}={};", DEOBFUSCATION_FUNC_NAME, fn_name)
|
||||
}
|
||||
|
||||
fn get_sig_fn(player_js: &str) -> Result<String> {
|
||||
|
|
@ -353,7 +353,7 @@ fn get_sts(player_js: &str) -> Result<String> {
|
|||
Lazy::new(|| Regex::new("signatureTimestamp[=:](\\d+)").unwrap());
|
||||
|
||||
Ok(some_or_bail!(
|
||||
STS_PATTERN.captures(&player_js)?,
|
||||
STS_PATTERN.captures(player_js)?,
|
||||
Err(anyhow!("could not find sts"))
|
||||
)
|
||||
.get(1)
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ fn get_download_range(offset: u64, size: Option<u64>) -> Range<u64> {
|
|||
let chunk_size = rng.gen_range(CHUNK_SIZE_MIN..CHUNK_SIZE_MAX);
|
||||
let mut chunk_end = offset + chunk_size;
|
||||
|
||||
if size.is_some() {
|
||||
chunk_end = chunk_end.min(size.unwrap() - 1)
|
||||
if let Some(size) = size {
|
||||
chunk_end = chunk_end.min(size - 1)
|
||||
}
|
||||
|
||||
Range {
|
||||
|
|
@ -41,7 +41,7 @@ fn parse_cr_header(cr_header: &str) -> Result<(u64, u64)> {
|
|||
static PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new(r#"bytes (\d+)-(\d+)/(\d+)"#).unwrap());
|
||||
|
||||
let captures = some_or_bail!(
|
||||
PATTERN.captures(&cr_header).ok().flatten(),
|
||||
PATTERN.captures(cr_header).ok().flatten(),
|
||||
Err(anyhow!(
|
||||
"Content-Range header '{}' does not match pattern.",
|
||||
cr_header
|
||||
|
|
@ -77,10 +77,7 @@ async fn download_single_file<P: Into<PathBuf>>(
|
|||
let (url_base, url_params) = util::url_to_params(url)?;
|
||||
let is_gvideo = url_base.ends_with(".googlevideo.com/videoplayback");
|
||||
if is_gvideo {
|
||||
size = url_params
|
||||
.get("clen")
|
||||
.map(|s| s.parse::<u64>().ok())
|
||||
.flatten();
|
||||
size = url_params.get("clen").and_then(|s| s.parse::<u64>().ok());
|
||||
}
|
||||
|
||||
// Check if file is partially downloaded
|
||||
|
|
@ -257,6 +254,7 @@ struct StreamDownload {
|
|||
video_codec: Option<VideoCodec>,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn download_video(
|
||||
player_data: &VideoPlayer,
|
||||
output_dir: &str,
|
||||
|
|
@ -327,7 +325,7 @@ pub async fn download_video(
|
|||
_ => {
|
||||
let mut downloads: Vec<StreamDownload> = Vec::new();
|
||||
|
||||
video.map(|v| {
|
||||
if let Some(v) = video {
|
||||
downloads.push(StreamDownload {
|
||||
file: download_dir.join(format!(
|
||||
"{}.video{}",
|
||||
|
|
@ -338,8 +336,8 @@ pub async fn download_video(
|
|||
video_codec: Some(v.codec),
|
||||
audio_codec: None,
|
||||
});
|
||||
});
|
||||
audio.map(|a| {
|
||||
}
|
||||
if let Some(a) = audio {
|
||||
downloads.push(StreamDownload {
|
||||
file: download_dir.join(format!(
|
||||
"{}.audio{}",
|
||||
|
|
@ -350,7 +348,7 @@ pub async fn download_video(
|
|||
video_codec: None,
|
||||
audio_codec: Some(a.codec),
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
pb.set_message(format!("Downloading {}", title));
|
||||
download_streams(&downloads, http, pb.clone()).await?;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#![allow(dead_code)]
|
||||
#![warn(clippy::todo)]
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
|
|
|||
|
|
@ -223,11 +223,7 @@ impl<'de> DeserializeAs<'de, Vec<TextLink>> for TextLinks {
|
|||
D: Deserializer<'de>,
|
||||
{
|
||||
let link = TextLinkInternal::deserialize(deserializer)?;
|
||||
Ok(link
|
||||
.runs
|
||||
.iter()
|
||||
.filter_map(|r| map_text_linkrun(r))
|
||||
.collect())
|
||||
Ok(link.runs.iter().filter_map(map_text_linkrun).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,24 +52,24 @@ impl Mul<u8> for TimeAgo {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<DateTime<Local>> for TimeAgo {
|
||||
fn into(self) -> DateTime<Local> {
|
||||
impl From<TimeAgo> for DateTime<Local> {
|
||||
fn from(ta: TimeAgo) -> Self {
|
||||
let ts = Local::now();
|
||||
match self.unit {
|
||||
TimeUnit::Second => ts - Duration::seconds(self.n as i64),
|
||||
TimeUnit::Minute => ts - Duration::minutes(self.n as i64),
|
||||
TimeUnit::Hour => ts - Duration::hours(self.n as i64),
|
||||
TimeUnit::Day => ts - Duration::days(self.n as i64),
|
||||
TimeUnit::Week => ts - Duration::weeks(self.n as i64),
|
||||
TimeUnit::Month => chronoutil::shift_months(ts, -(self.n as i32)),
|
||||
TimeUnit::Year => chronoutil::shift_years(ts, -(self.n as i32)),
|
||||
match ta.unit {
|
||||
TimeUnit::Second => ts - Duration::seconds(ta.n as i64),
|
||||
TimeUnit::Minute => ts - Duration::minutes(ta.n as i64),
|
||||
TimeUnit::Hour => ts - Duration::hours(ta.n as i64),
|
||||
TimeUnit::Day => ts - Duration::days(ta.n as i64),
|
||||
TimeUnit::Week => ts - Duration::weeks(ta.n as i64),
|
||||
TimeUnit::Month => chronoutil::shift_months(ts, -(ta.n as i32)),
|
||||
TimeUnit::Year => chronoutil::shift_years(ts, -(ta.n as i32)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<DateTime<Local>> for ParsedDate {
|
||||
fn into(self) -> DateTime<Local> {
|
||||
match self {
|
||||
impl From<ParsedDate> for DateTime<Local> {
|
||||
fn from(date: ParsedDate) -> Self {
|
||||
match date {
|
||||
ParsedDate::Absolute(date) => Local
|
||||
.from_local_datetime(&NaiveDateTime::new(date, NaiveTime::from_hms(0, 0, 0)))
|
||||
.unwrap(),
|
||||
|
|
@ -103,29 +103,23 @@ fn parse_ta_token(entry: &dictionary::Entry, nd: bool, filtered_str: &str) -> Op
|
|||
|
||||
if entry.by_char {
|
||||
filtered_str.chars().find_map(|word| {
|
||||
tokens
|
||||
.get(&word.to_string())
|
||||
.map(|t| match t.unit {
|
||||
Some(unit) => Some(TimeAgo { n: t.n * qu, unit }),
|
||||
None => {
|
||||
qu = t.n;
|
||||
None
|
||||
}
|
||||
})
|
||||
.flatten()
|
||||
tokens.get(&word.to_string()).and_then(|t| match t.unit {
|
||||
Some(unit) => Some(TimeAgo { n: t.n * qu, unit }),
|
||||
None => {
|
||||
qu = t.n;
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
filtered_str.split_whitespace().find_map(|word| {
|
||||
tokens
|
||||
.get(word)
|
||||
.map(|t| match t.unit {
|
||||
Some(unit) => Some(TimeAgo { n: t.n * qu, unit }),
|
||||
None => {
|
||||
qu = t.n;
|
||||
None
|
||||
}
|
||||
})
|
||||
.flatten()
|
||||
tokens.get(word).and_then(|t| match t.unit {
|
||||
Some(unit) => Some(TimeAgo { n: t.n * qu, unit }),
|
||||
None => {
|
||||
qu = t.n;
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -137,7 +131,7 @@ fn parse_textual_month(entry: &dictionary::Entry, filtered_str: &str) -> Option<
|
|||
} else {
|
||||
filtered_str
|
||||
.split_whitespace()
|
||||
.find_map(|word| entry.months.get(word).map(|n| *n))
|
||||
.find_map(|word| entry.months.get(word).copied())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +139,7 @@ pub fn parse_timeago(lang: Language, textual_date: &str) -> Option<TimeAgo> {
|
|||
let entry = dictionary::entry(lang);
|
||||
let filtered_str = filter_str(textual_date);
|
||||
|
||||
let qu: u8 = util::parse_numeric(&textual_date).unwrap_or(1);
|
||||
let qu: u8 = util::parse_numeric(textual_date).unwrap_or(1);
|
||||
|
||||
parse_ta_token(&entry, false, &filtered_str).map(|ta| ta * qu)
|
||||
}
|
||||
|
|
@ -163,8 +157,7 @@ pub fn parse_textual_date(lang: Language, textual_date: &str) -> Option<ParsedDa
|
|||
match nums.len() {
|
||||
0 => match parse_ta_token(&entry, true, &filtered_str) {
|
||||
Some(timeago) => Some(ParsedDate::Relative(timeago)),
|
||||
None => parse_ta_token(&entry, false, &filtered_str)
|
||||
.map(|timeago| ParsedDate::Relative(timeago)),
|
||||
None => parse_ta_token(&entry, false, &filtered_str).map(ParsedDate::Relative),
|
||||
},
|
||||
1 => parse_ta_token(&entry, false, &filtered_str)
|
||||
.map(|timeago| ParsedDate::Relative(timeago * nums[0] as u8)),
|
||||
|
|
@ -189,7 +182,7 @@ pub fn parse_textual_date(lang: Language, textual_date: &str) -> Option<ParsedDa
|
|||
match (y, m, d) {
|
||||
(Some(y), Some(m), Some(d)) => {
|
||||
NaiveDate::from_ymd_opt(y.into(), m.into(), d.into())
|
||||
.map(|d| ParsedDate::Absolute(d))
|
||||
.map(ParsedDate::Absolute)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,16 +41,15 @@ pub fn generate_content_playback_nonce() -> String {
|
|||
///
|
||||
/// `example.com/api?k1=v1&k2=v2 => example.com/api; {k1: v1, k2: v2}`
|
||||
pub fn url_to_params(url: &str) -> Result<(String, BTreeMap<String, String>)> {
|
||||
let parsed_url = Url::parse(url)?;
|
||||
let mut parsed_url = Url::parse(url)?;
|
||||
let url_params: BTreeMap<String, String> = parsed_url
|
||||
.query_pairs()
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect();
|
||||
|
||||
let mut url_base = parsed_url.clone();
|
||||
url_base.set_query(None);
|
||||
parsed_url.set_query(None);
|
||||
|
||||
Ok((url_base.to_string(), url_params))
|
||||
Ok((parsed_url.to_string(), url_params))
|
||||
}
|
||||
|
||||
/// Parse a string after removing all non-numeric characters
|
||||
|
|
|
|||
Reference in a new issue