fix: v1.67 clippy lints (inline format strings)

This commit is contained in:
ThetaDev 2023-01-27 21:19:08 +01:00
parent 15dad0c428
commit 331a13568a
33 changed files with 200 additions and 288 deletions

View file

@ -52,13 +52,14 @@ async fn download_single_video(
let pb = multi.add(ProgressBar::new(1));
pb.set_style(ProgressStyle::with_template("{msg}\n{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})").unwrap()
.progress_chars("#>-"));
pb.set_message(format!("Fetching player data for {}", video_title));
pb.set_message(format!("Fetching player data for {video_title}"));
let res = async {
let player_data = rp.query().player(video_id.as_str()).await.context(format!(
"Failed to fetch player data for video {}",
video_id
))?;
let player_data = rp
.query()
.player(video_id.as_str())
.await
.context(format!("Failed to fetch player data for video {video_id}"))?;
let mut filter = StreamFilter::new();
if let Some(res) = resolution {
@ -124,7 +125,7 @@ async fn download_video(
None,
)
.await
.unwrap_or_else(|e| println!("ERROR: {:?}", e));
.unwrap_or_else(|e| println!("ERROR: {e:?}"));
}
async fn download_playlist(
@ -185,7 +186,7 @@ async fn download_playlist(
.for_each(|res| match res {
Ok(_) => {}
Err(e) => {
println!("ERROR: {:?}", e);
println!("ERROR: {e:?}");
}
});
}

View file

@ -53,14 +53,14 @@ pub async fn collect_large_numbers(project_root: &Path, concurrency: usize) {
for (n, ch_id) in channels.iter().enumerate() {
let channel = get_channel(ch_id, lang)
.await
.context(format!("{}-{}", lang, n))
.context(format!("{lang}-{n}"))
.unwrap();
channel.view_counts.iter().for_each(|(num, txt)| {
entry.insert(txt.to_owned(), *num);
});
println!("collected {}-{}", lang, n);
println!("collected {lang}-{n}");
}
(lang, entry)
@ -232,7 +232,7 @@ pub fn write_samples_to_dict(project_root: &Path) {
// Check for duplicates
let mut uniq = HashSet::new();
if !dict_entry.number_tokens.values().all(|x| uniq.insert(x)) {
println!("Warning: collected duplicate tokens for {}", lang);
println!("Warning: collected duplicate tokens for {lang}");
}
}

View file

@ -222,9 +222,7 @@ pub fn write_samples_to_dict(project_root: &Path) {
n: 3,
unit: timeago::TimeUnit::Day
}),
"lang: {}, txt: {}",
lang,
datestr
"lang: {lang}, txt: {datestr}"
);
}
@ -246,7 +244,7 @@ pub fn write_samples_to_dict(project_root: &Path) {
} else if n == &date.2 {
"D"
} else {
panic!("invalid number {} in {}", n, datestr);
panic!("invalid number {n} in {datestr}");
}
})
.collect::<String>();
@ -254,7 +252,7 @@ pub fn write_samples_to_dict(project_root: &Path) {
if num_order.is_empty() {
num_order = this_num_order;
} else {
assert_eq!(this_num_order, num_order, "lang: {}", lang);
assert_eq!(this_num_order, num_order, "lang: {lang}");
}
// Insert words into the map

View file

@ -142,7 +142,7 @@ async fn player(testfiles: &Path) {
for client_type in CLIENT_TYPES {
let mut json_path = testfiles.to_path_buf();
json_path.push("player");
json_path.push(format!("{:?}_video.json", client_type).to_lowercase());
json_path.push(format!("{client_type:?}_video.json").to_lowercase());
if json_path.exists() {
continue;
@ -162,7 +162,7 @@ async fn player_model(testfiles: &Path) {
for (name, id) in [("multilanguage", "tVWWp1PqDus"), ("hdr", "LXb3EKWsInQ")] {
let mut json_path = testfiles.to_path_buf();
json_path.push("player_model");
json_path.push(format!("{}.json", name).to_lowercase());
json_path.push(format!("{name}.json").to_lowercase());
if json_path.exists() {
continue;
@ -188,7 +188,7 @@ async fn playlist(testfiles: &Path) {
] {
let mut json_path = testfiles.to_path_buf();
json_path.push("playlist");
json_path.push(format!("playlist_{}.json", name));
json_path.push(format!("playlist_{name}.json"));
if json_path.exists() {
continue;
}
@ -228,7 +228,7 @@ async fn video_details(testfiles: &Path) {
] {
let mut json_path = testfiles.to_path_buf();
json_path.push("video_details");
json_path.push(format!("video_details_{}.json", name));
json_path.push(format!("video_details_{name}.json"));
if json_path.exists() {
continue;
}
@ -304,7 +304,7 @@ async fn channel_videos(testfiles: &Path) {
] {
let mut json_path = testfiles.to_path_buf();
json_path.push("channel");
json_path.push(format!("channel_videos_{}.json", name));
json_path.push(format!("channel_videos_{name}.json"));
if json_path.exists() {
continue;
}
@ -521,7 +521,7 @@ async fn music_playlist(testfiles: &Path) {
] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_playlist");
json_path.push(format!("playlist_{}.json", name));
json_path.push(format!("playlist_{name}.json"));
if json_path.exists() {
continue;
}
@ -584,7 +584,7 @@ async fn music_album(testfiles: &Path) {
] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_playlist");
json_path.push(format!("album_{}.json", name));
json_path.push(format!("album_{name}.json"));
if json_path.exists() {
continue;
}
@ -602,7 +602,7 @@ async fn music_search(testfiles: &Path) {
] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_search");
json_path.push(format!("main_{}.json", name));
json_path.push(format!("main_{name}.json"));
if json_path.exists() {
continue;
}
@ -625,7 +625,7 @@ async fn music_search_tracks(testfiles: &Path) {
] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_search");
json_path.push(format!("tracks_{}.json", name));
json_path.push(format!("tracks_{name}.json"));
if json_path.exists() {
continue;
}
@ -670,7 +670,7 @@ async fn music_search_playlists(testfiles: &Path) {
for (name, community) in [("ytm", false), ("community", true)] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_search");
json_path.push(format!("playlists_{}.json", name));
json_path.push(format!("playlists_{name}.json"));
if json_path.exists() {
continue;
}
@ -702,7 +702,7 @@ async fn music_search_suggestion(testfiles: &Path) {
for (name, query) in [("default", "t"), ("empty", "reujbhevmfndxnjrze")] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_search");
json_path.push(format!("suggestion_{}.json", name));
json_path.push(format!("suggestion_{name}.json"));
if json_path.exists() {
continue;
}
@ -723,7 +723,7 @@ async fn music_artist(testfiles: &Path) {
] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_artist");
json_path.push(format!("artist_{}.json", name));
json_path.push(format!("artist_{name}.json"));
if json_path.exists() {
continue;
}
@ -737,7 +737,7 @@ async fn music_details(testfiles: &Path) {
for (name, id) in [("mv", "ZeerrnuLi5E"), ("track", "7nigXQS1Xb0")] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_details");
json_path.push(format!("details_{}.json", name));
json_path.push(format!("details_{name}.json"));
if json_path.exists() {
continue;
}
@ -787,7 +787,7 @@ async fn music_radio(testfiles: &Path) {
for (name, id) in [("mv", "RDAMVMZeerrnuLi5E"), ("track", "RDAMVM7nigXQS1Xb0")] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_details");
json_path.push(format!("radio_{}.json", name));
json_path.push(format!("radio_{name}.json"));
if json_path.exists() {
continue;
}
@ -840,7 +840,7 @@ async fn music_charts(testfiles: &Path) {
for (name, country) in [("global", Some(Country::Zz)), ("US", Some(Country::Us))] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_charts");
json_path.push(&format!("charts_{}.json", name));
json_path.push(&format!("charts_{name}.json"));
if json_path.exists() {
continue;
}
@ -869,7 +869,7 @@ async fn music_genre(testfiles: &Path) {
] {
let mut json_path = testfiles.to_path_buf();
json_path.push("music_genres");
json_path.push(&format!("genre_{}.json", name));
json_path.push(&format!("genre_{name}.json"));
if json_path.exists() {
continue;
}

View file

@ -23,10 +23,10 @@ fn parse_tu(tu: &str) -> (u8, Option<TimeUnit>) {
"M" => Some(TimeUnit::Month),
"Y" => Some(TimeUnit::Year),
"" => None,
_ => panic!("invalid time unit: {}", tu),
_ => panic!("invalid time unit: {tu}"),
},
),
None => panic!("invalid time unit: {}", tu),
None => panic!("invalid time unit: {tu}"),
}
}
@ -91,9 +91,9 @@ pub(crate) fn entry(lang: Language) -> Entry {
dict.iter().for_each(|(lang, entry)| {
// Match selector
let mut selector = format!("Language::{:?}", lang);
let mut selector = format!("Language::{lang:?}");
entry.equivalent.iter().for_each(|eq| {
let _ = write!(selector, " | Language::{:?}", eq);
let _ = write!(selector, " | Language::{eq:?}");
});
// Timeago tokens
@ -103,9 +103,9 @@ pub(crate) fn entry(lang: Language) -> Entry {
match unit {
Some(unit) => ta_tokens.entry(
txt,
&format!("TaToken {{ n: {}, unit: Some(TimeUnit::{:?}) }}", n, unit),
&format!("TaToken {{ n: {n}, unit: Some(TimeUnit::{unit:?}) }}"),
),
None => ta_tokens.entry(txt, &format!("TaToken {{ n: {}, unit: None }}", n)),
None => ta_tokens.entry(txt, &format!("TaToken {{ n: {n}, unit: None }}")),
};
});
@ -122,16 +122,16 @@ pub(crate) fn entry(lang: Language) -> Entry {
match unit {
Some(unit) => ta_nd_tokens.entry(
txt,
&format!("TaToken {{ n: {}, unit: Some(TimeUnit::{:?}) }}", n, unit),
&format!("TaToken {{ n: {n}, unit: Some(TimeUnit::{unit:?}) }}"),
),
None => ta_nd_tokens.entry(txt, &format!("TaToken {{ n: {}, unit: None }}", n)),
None => ta_nd_tokens.entry(txt, &format!("TaToken {{ n: {n}, unit: None }}")),
};
});
// Date order
let mut date_order = "&[".to_owned();
entry.date_order.chars().for_each(|c| {
let _ = write!(date_order, "DateCmp::{}, ", c);
let _ = write!(date_order, "DateCmp::{c}, ");
});
date_order = date_order.trim_end_matches([' ', ',']).to_owned() + "]";
@ -144,7 +144,7 @@ pub(crate) fn entry(lang: Language) -> Entry {
// Album types
let mut album_types = phf_codegen::Map::<&str>::new();
entry.album_types.iter().for_each(|(txt, album_type)| {
album_types.entry(txt, &format!("AlbumType::{:?}", album_type));
album_types.entry(txt, &format!("AlbumType::{album_type:?}"));
});
let code_ta_tokens = &ta_tokens.build().to_string().replace('\n', "\n ");
@ -159,7 +159,7 @@ pub(crate) fn entry(lang: Language) -> Entry {
code_timeago_tokens = code_timeago_tokens.trim_end().to_owned() + "\n }\n}\n";
let code = format!("{}\n{}", code_head, code_timeago_tokens);
let code = format!("{code_head}\n{code_timeago_tokens}");
let mut target_path = project_root.to_path_buf();
target_path.push(TARGET_PATH);

View file

@ -235,21 +235,20 @@ pub enum Country {
.collect::<String>();
// Language enum
write!(code_langs, " /// {}\n ", n).unwrap();
write!(code_langs, " /// {n}\n ").unwrap();
if c.contains('-') {
write!(code_langs, "#[serde(rename = \"{}\")]\n ", c).unwrap();
write!(code_langs, "#[serde(rename = \"{c}\")]\n ").unwrap();
}
code_langs += &enum_name;
code_langs += ",\n";
// Language array
writeln!(code_lang_array, " Language::{},", enum_name).unwrap();
writeln!(code_lang_array, " Language::{enum_name},").unwrap();
// Language names
writeln!(
code_lang_names,
" Language::{} => \"{}\",",
enum_name, n
" Language::{enum_name} => \"{n}\","
)
.unwrap();
});
@ -259,17 +258,16 @@ pub enum Country {
let enum_name = c[0..1].to_owned().to_uppercase() + &c[1..].to_owned().to_lowercase();
// Country enum
writeln!(code_countries, " /// {}", n).unwrap();
writeln!(code_countries, " {},", enum_name).unwrap();
writeln!(code_countries, " /// {n}").unwrap();
writeln!(code_countries, " {enum_name},").unwrap();
// Country array
writeln!(code_country_array, " Country::{},", enum_name).unwrap();
writeln!(code_country_array, " Country::{enum_name},").unwrap();
// Country names
writeln!(
code_country_names,
" Country::{} => \"{}\",",
enum_name, n
" Country::{enum_name} => \"{n}\","
)
.unwrap();
});
@ -287,15 +285,7 @@ pub enum Country {
code_country_names += " }\n }\n}\n";
let code = format!(
"{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}",
code_head,
code_langs,
code_countries,
code_lang_array,
code_country_array,
code_lang_names,
code_country_names,
code_foot
"{code_head}\n{code_langs}\n{code_countries}\n{code_lang_array}\n{code_country_array}\n{code_lang_names}\n{code_country_names}\n{code_foot}"
);
let mut target_path = project_root.to_path_buf();

View file

@ -81,8 +81,8 @@ async fn main() {
n,
occurrences as f32 / n as f32 * 100.0
);
eprintln!("visitor_data (present): {:?}", vd_present);
eprintln!("visitor_data (absent): {:?}", vd_absent);
eprintln!("visitor_data (present): {vd_present:?}");
eprintln!("visitor_data (absent): {vd_absent:?}");
}
None => {
let res = abtest::run_all_tests(n, cli.concurrency).await;

View file

@ -48,11 +48,7 @@ fn parse_cr_header(cr_header: &str) -> Result<(u64, u64)> {
let captures = PATTERN.captures(cr_header).ok_or_else(|| {
DownloadError::Progressive(
format!(
"Content-Range header '{}' does not match pattern",
cr_header
)
.into(),
format!("Content-Range header '{cr_header}' does not match pattern").into(),
)
})?;
@ -348,7 +344,7 @@ pub async fn download_video(
match (video, audio) {
// Downloading combined video/audio stream (no conversion)
(Some(video), None) => {
pb.set_message(format!("Downloading {}", title));
pb.set_message(format!("Downloading {title}"));
download_single_file(
&video.url,
download_dir.join(output_fname).with_extension(&format),
@ -386,10 +382,10 @@ pub async fn download_video(
})
}
pb.set_message(format!("Downloading {}", title));
pb.set_message(format!("Downloading {title}"));
download_streams(&downloads, http, pb.clone()).await?;
pb.set_message(format!("Converting {}", title));
pb.set_message(format!("Converting {title}"));
pb.set_style(
ProgressStyle::with_template("{msg}\n{spinner:.green} [{elapsed_precise}]")
.unwrap(),

View file

@ -29,7 +29,7 @@ pub enum DownloadError {
/// `example.com/api?k1=v1&k2=v2 => example.com/api; {k1: v1, k2: v2}`
pub fn url_to_params(url: &str) -> Result<(Url, BTreeMap<String, String>), DownloadError> {
let mut parsed_url = Url::parse(url).map_err(|e| {
DownloadError::Other(format!("could not parse url `{}` err: {}", url, e).into())
DownloadError::Other(format!("could not parse url `{url}` err: {e}").into())
})?;
let url_params: BTreeMap<String, String> = parsed_url
.query_pairs()

View file

@ -510,7 +510,7 @@ mod tests {
#[case::shorts("shorts", "UCh8gHdtzO2tXd593_bjErWg")]
#[case::livestreams("livestreams", "UC2DjFE7Xf11URZqWBigcVOQ")]
fn map_channel_videos(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "channel" / format!("channel_{}.json", name));
let json_path = path!("testfiles" / "channel" / format!("channel_{name}.json"));
let json_file = File::open(json_path).unwrap();
let channel: response::Channel =
@ -525,11 +525,11 @@ mod tests {
);
if name == "videos_upcoming" {
insta::assert_ron_snapshot!(format!("map_channel_{}", name), map_res.c, {
insta::assert_ron_snapshot!(format!("map_channel_{name}"), map_res.c, {
".content.items[1:].publish_date" => "[date]",
});
} else {
insta::assert_ron_snapshot!(format!("map_channel_{}", name), map_res.c, {
insta::assert_ron_snapshot!(format!("map_channel_{name}"), map_res.c, {
".content.items[].publish_date" => "[date]",
});
}

View file

@ -55,10 +55,10 @@ impl RustyPipeQuery {
reporter.report(&report);
}
Err(ExtractionError::InvalidData(
format!("could not deserialize xml: {}", e).into(),
Err(
ExtractionError::InvalidData(format!("could not deserialize xml: {e}").into())
.into(),
)
.into())
}
}
}

View file

@ -130,8 +130,6 @@ impl Default for RequestYT {
#[derive(Clone, Debug, Serialize, Default)]
#[serde(rename_all = "camelCase")]
struct User {
// TODO: provide a way to enable restricted mode with:
// "enableSafetyMode": true
locked_safety_mode: bool,
}
@ -926,8 +924,7 @@ impl RustyPipeQuery {
.inner
.http
.post(format!(
"{}{}?key={}{}",
YOUTUBEI_V1_URL, endpoint, DESKTOP_API_KEY, DISABLE_PRETTY_PRINT_PARAMETER
"{YOUTUBEI_V1_URL}{endpoint}?key={DESKTOP_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
))
.header(header::ORIGIN, "https://www.youtube.com")
.header(header::REFERER, "https://www.youtube.com")
@ -942,11 +939,7 @@ impl RustyPipeQuery {
.inner
.http
.post(format!(
"{}{}?key={}{}",
YOUTUBE_MUSIC_V1_URL,
endpoint,
DESKTOP_MUSIC_API_KEY,
DISABLE_PRETTY_PRINT_PARAMETER
"{YOUTUBE_MUSIC_V1_URL}{endpoint}?key={DESKTOP_MUSIC_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
))
.header(header::ORIGIN, "https://music.youtube.com")
.header(header::REFERER, "https://music.youtube.com")
@ -961,8 +954,7 @@ impl RustyPipeQuery {
.inner
.http
.post(format!(
"{}{}?key={}{}",
YOUTUBEI_V1_URL, endpoint, DESKTOP_API_KEY, DISABLE_PRETTY_PRINT_PARAMETER
"{YOUTUBEI_V1_URL}{endpoint}?key={DESKTOP_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
))
.header(header::ORIGIN, "https://www.youtube.com")
.header(header::REFERER, "https://www.youtube.com")
@ -973,11 +965,7 @@ impl RustyPipeQuery {
.inner
.http
.post(format!(
"{}{}?key={}{}",
YOUTUBEI_V1_GAPIS_URL,
endpoint,
ANDROID_API_KEY,
DISABLE_PRETTY_PRINT_PARAMETER
"{YOUTUBEI_V1_GAPIS_URL}{endpoint}?key={ANDROID_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
))
.header(
header::USER_AGENT,
@ -992,8 +980,7 @@ impl RustyPipeQuery {
.inner
.http
.post(format!(
"{}{}?key={}{}",
YOUTUBEI_V1_GAPIS_URL, endpoint, IOS_API_KEY, DISABLE_PRETTY_PRINT_PARAMETER
"{YOUTUBEI_V1_GAPIS_URL}{endpoint}?key={IOS_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
))
.header(
header::USER_AGENT,
@ -1065,7 +1052,7 @@ impl RustyPipeQuery {
let report = Report {
info: Default::default(),
level,
operation: format!("{}({})", operation, id),
operation: format!("{operation}({id})"),
error,
msgs,
deobf_data: deobf.map(Deobfuscator::get_data),
@ -1230,7 +1217,6 @@ mod tests {
fn t_get_ytm_visitor_data() {
let rp = RustyPipe::new();
let visitor_data = tokio_test::block_on(rp.get_ytm_visitor_data()).unwrap();
dbg!(&visitor_data);
assert!(visitor_data.ends_with("%3D"));
assert_eq!(visitor_data.len(), 32)
}

View file

@ -380,13 +380,12 @@ mod tests {
#[case::no_artist("no_artist", "UCh8gHdtzO2tXd593_bjErWg")]
#[case::only_more_singles("only_more_singles", "UC0aXrjVxG5pZr99v77wZdPQ")]
fn map_music_artist(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_artist" / format!("artist_{}.json", name));
let json_path = path!("testfiles" / "music_artist" / format!("artist_{name}.json"));
let json_file = File::open(json_path).unwrap();
let mut album_page_paths = Vec::new();
for i in 1..=2 {
let json_path =
path!("testfiles" / "music_artist" / format!("artist_{}_{}.json", name, i));
let json_path = path!("testfiles" / "music_artist" / format!("artist_{name}_{i}.json"));
if !json_path.exists() {
break;
}
@ -421,7 +420,7 @@ mod tests {
artist.albums.append(&mut map_res.c);
}
insta::assert_ron_snapshot!(format!("map_music_artist_{}", name), artist);
insta::assert_ron_snapshot!(format!("map_music_artist_{name}"), artist);
}
#[test]
@ -458,7 +457,7 @@ mod tests {
ExtractionError::Redirect(id) => {
assert_eq!(id, "UCOR4_bSVIXPsGa4BbCSt60Q")
}
_ => panic!("error: {}", e),
_ => panic!("error: {e}"),
}
}
}

View file

@ -154,7 +154,7 @@ mod tests {
#[case::default("global")]
#[case::us("US")]
fn map_music_charts(#[case] name: &str) {
let filename = format!("testfiles/music_charts/charts_{}.json", name);
let filename = format!("testfiles/music_charts/charts_{name}.json");
let json_path = Path::new(&filename);
let json_file = File::open(json_path).unwrap();
@ -167,6 +167,6 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_charts_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_charts_{name}"), map_res.c);
}
}

View file

@ -401,7 +401,7 @@ mod tests {
#[case::mv("mv", "ZeerrnuLi5E")]
#[case::track("track", "7nigXQS1Xb0")]
fn map_music_details(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_details" / format!("details_{}.json", name));
let json_path = path!("testfiles" / "music_details" / format!("details_{name}.json"));
let json_file = File::open(json_path).unwrap();
let details: response::MusicDetails =
@ -414,14 +414,14 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_details_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_details_{name}"), map_res.c);
}
#[rstest]
#[case::mv("mv", "RDAMVMZeerrnuLi5E")]
#[case::track("track", "RDAMVM7nigXQS1Xb0")]
fn map_music_radio(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_details" / format!("radio_{}.json", name));
let json_path = path!("testfiles" / "music_details" / format!("radio_{name}.json"));
let json_file = File::open(json_path).unwrap();
let radio: response::MusicDetails =
@ -434,7 +434,7 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_radio_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_radio_{name}"), map_res.c);
}
#[test]

View file

@ -236,7 +236,7 @@ mod tests {
#[case::default("default", "ggMPOg1uX1lMbVZmbzl6NlJ3")]
#[case::mood("mood", "ggMPOg1uX1JOQWZFeDByc2Jm")]
fn map_music_genre(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_genres" / format!("genre_{}.json", name));
let json_path = path!("testfiles" / "music_genres" / format!("genre_{name}.json"));
let json_file = File::open(json_path).unwrap();
let playlist: response::MusicGenre =
@ -249,6 +249,6 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_genre_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_genre_{name}"), map_res.c);
}
}

View file

@ -90,7 +90,7 @@ mod tests {
#[rstest]
#[case::default("default")]
fn map_music_new_albums(#[case] name: &str) {
let json_path = path!("testfiles" / "music_new" / format!("albums_{}.json", name));
let json_path = path!("testfiles" / "music_new" / format!("albums_{name}.json"));
let json_file = File::open(json_path).unwrap();
let new_albums: response::MusicNew =
@ -103,13 +103,13 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_new_albums_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_new_albums_{name}"), map_res.c);
}
#[rstest]
#[case::default("default")]
fn map_music_new_videos(#[case] name: &str) {
let json_path = path!("testfiles" / "music_new" / format!("videos_{}.json", name));
let json_path = path!("testfiles" / "music_new" / format!("videos_{name}.json"));
let json_file = File::open(json_path).unwrap();
let new_albums: response::MusicNew =
@ -122,6 +122,6 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_new_videos_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_new_videos_{name}"), map_res.c);
}
}

View file

@ -25,7 +25,7 @@ impl RustyPipeQuery {
let context = self.get_context(ClientType::DesktopMusic, true, None).await;
let request_body = QBrowse {
context,
browse_id: &format!("VL{}", playlist_id),
browse_id: &format!("VL{playlist_id}"),
};
self.execute_request::<response::MusicPlaylist, _, _>(
@ -129,8 +129,7 @@ impl MapResponse<MusicPlaylist> for response::MusicPlaylist {
if let Some(playlist_id) = shelf.playlist_id {
if playlist_id != id {
return Err(ExtractionError::WrongResult(format!(
"got wrong playlist id {}, expected {}",
playlist_id, id
"got wrong playlist id {playlist_id}, expected {id}"
)));
}
}
@ -384,7 +383,7 @@ mod tests {
#[case::long("long", "PL5dDx681T4bR7ZF1IuWzOv1omlRbE7PiJ")]
#[case::nomusic("nomusic", "PL1J-6JOckZtE_P9Xx8D3b2O6w0idhuKBe")]
fn map_music_playlist(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_playlist" / format!("playlist_{}.json", name));
let json_path = path!("testfiles" / "music_playlist" / format!("playlist_{name}.json"));
let json_file = File::open(json_path).unwrap();
let playlist: response::MusicPlaylist =
@ -397,7 +396,7 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_playlist_{}", name), map_res.c, {
insta::assert_ron_snapshot!(format!("map_music_playlist_{name}"), map_res.c, {
".last_update" => "[date]"
});
}
@ -409,7 +408,7 @@ mod tests {
#[case::description("description", "MPREb_PiyfuVl6aYd")]
#[case::unavailable("unavailable", "MPREb_AzuWg8qAVVl")]
fn map_music_album(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_playlist" / format!("album_{}.json", name));
let json_path = path!("testfiles" / "music_playlist" / format!("album_{name}.json"));
let json_file = File::open(json_path).unwrap();
let playlist: response::MusicPlaylist =
@ -422,6 +421,6 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_album_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_album_{name}"), map_res.c);
}
}

View file

@ -391,7 +391,7 @@ mod tests {
#[case::typo("typo")]
#[case::radio("radio")]
fn map_music_search_main(#[case] name: &str) {
let json_path = path!("testfiles" / "music_search" / format!("main_{}.json", name));
let json_path = path!("testfiles" / "music_search" / format!("main_{name}.json"));
let json_file = File::open(json_path).unwrap();
let search: response::MusicSearch =
@ -405,7 +405,7 @@ mod tests {
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_search_main_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_search_main_{name}"), map_res.c);
}
#[rstest]
@ -414,7 +414,7 @@ mod tests {
#[case::videos("videos")]
#[case::no_artist_link("no_artist_link")]
fn map_music_search_tracks(#[case] name: &str) {
let json_path = path!("testfiles" / "music_search" / format!("tracks_{}.json", name));
let json_path = path!("testfiles" / "music_search" / format!("tracks_{name}.json"));
let json_file = File::open(json_path).unwrap();
let search: response::MusicSearch =
@ -428,7 +428,7 @@ mod tests {
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_search_tracks_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_search_tracks_{name}"), map_res.c);
}
#[test]
@ -473,7 +473,7 @@ mod tests {
#[case::ytm("ytm")]
#[case::community("community")]
fn map_music_search_playlists(#[case] name: &str) {
let json_path = path!("testfiles" / "music_search" / format!("playlists_{}.json", name));
let json_path = path!("testfiles" / "music_search" / format!("playlists_{name}.json"));
let json_file = File::open(json_path).unwrap();
let search: response::MusicSearch =
@ -487,14 +487,14 @@ mod tests {
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_search_playlists_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_search_playlists_{name}"), map_res.c);
}
#[rstest]
#[case::default("default")]
#[case::empty("empty")]
fn map_music_search_suggestion(#[case] name: &str) {
let json_path = path!("testfiles" / "music_search" / format!("suggestion_{}.json", name));
let json_path = path!("testfiles" / "music_search" / format!("suggestion_{name}.json"));
let json_file = File::open(json_path).unwrap();
let suggestion: response::MusicSearchSuggestion =
@ -508,6 +508,6 @@ mod tests {
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_music_search_suggestion_{}", name), map_res.c);
insta::assert_ron_snapshot!(format!("map_music_search_suggestion_{name}"), map_res.c);
}
}

View file

@ -362,7 +362,7 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_{}", name), map_res.c, {
insta::assert_ron_snapshot!(format!("map_{name}"), map_res.c, {
".items.*.publish_date" => "[date]",
});
}
@ -385,7 +385,7 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_{}", name), paginator);
insta::assert_ron_snapshot!(format!("map_{name}"), paginator);
}
#[rstest]
@ -408,7 +408,7 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_{}", name), paginator);
insta::assert_ron_snapshot!(format!("map_{name}"), paginator);
}
#[rstest]
@ -429,6 +429,6 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_{}", name), paginator);
insta::assert_ron_snapshot!(format!("map_{name}"), paginator);
}
}

View file

@ -105,7 +105,7 @@ impl RustyPipeQuery {
playback_context: Some(QPlaybackContext {
content_playback_context: QContentPlaybackContext {
signature_timestamp: deobf.get_sts(),
referer: format!("https://www.youtube.com/watch?v={}", video_id),
referer: format!("https://www.youtube.com/watch?v={video_id}"),
},
}),
cpn: None,
@ -374,7 +374,7 @@ fn map_url(
util::url_to_params(url),
MapResult {
c: None,
warnings: vec![format!("Could not parse url `{}`", url)]
warnings: vec![format!("Could not parse url `{url}`")]
}
),
None => match signature_cipher {
@ -384,8 +384,7 @@ fn map_url(
return MapResult {
c: None,
warnings: vec![format!(
"Could not deobfuscate signatureCipher `{}`: {}",
signature_cipher, e
"Could not deobfuscate signatureCipher `{signature_cipher}`: {e}"
)],
};
}
@ -403,8 +402,7 @@ fn map_url(
let mut throttled = false;
deobf_nsig(&mut url_params, deobf, last_nsig).unwrap_or_else(|e| {
warnings.push(format!(
"Could not deobfuscate nsig (params: {:?}): {}",
url_params, e
"Could not deobfuscate nsig (params: {url_params:?}): {e}"
));
throttled = true;
});
@ -416,8 +414,7 @@ fn map_url(
MapResult {
c: None,
warnings: vec![format!(
"url could not be joined. url: `{}` params: {:?}",
url_base, url_params
"url could not be joined. url: `{url_base}` params: {url_params:?}"
)],
}
)
@ -636,7 +633,7 @@ mod tests {
#[case::android("android")]
#[case::ios("ios")]
fn map_player_data(#[case] name: &str) {
let json_path = path!("testfiles" / "player" / format!("{}_video.json", name));
let json_path = path!("testfiles" / "player" / format!("{name}_video.json"));
let json_file = File::open(json_path).unwrap();
let resp: response::Player = serde_json::from_reader(BufReader::new(json_file)).unwrap();
@ -650,7 +647,7 @@ mod tests {
map_res.warnings
);
let is_desktop = name == "desktop" || name == "desktopmusic";
insta::assert_ron_snapshot!(format!("map_player_data_{}", name), map_res.c, {
insta::assert_ron_snapshot!(format!("map_player_data_{name}"), map_res.c, {
".details.publish_date" => insta::dynamic_redaction(move |value, _path| {
if is_desktop {
assert!(value.as_str().unwrap().starts_with("2019-05-30T00:00:00"));

View file

@ -20,7 +20,7 @@ impl RustyPipeQuery {
let context = self.get_context(ClientType::Desktop, true, None).await;
let request_body = QBrowse {
context,
browse_id: &format!("VL{}", playlist_id),
browse_id: &format!("VL{playlist_id}"),
};
self.execute_request::<response::Playlist, _, _>(
@ -145,8 +145,7 @@ impl MapResponse<Playlist> for response::Playlist {
let playlist_id = header.playlist_header_renderer.playlist_id;
if playlist_id != id {
return Err(ExtractionError::WrongResult(format!(
"got wrong playlist id {}, expected {}",
playlist_id, id
"got wrong playlist id {playlist_id}, expected {id}"
)));
}
@ -243,7 +242,7 @@ mod tests {
#[case::long("long", "PL5dDx681T4bR7ZF1IuWzOv1omlRbE7PiJ")]
#[case::nomusic("nomusic", "PL1J-6JOckZtE_P9Xx8D3b2O6w0idhuKBe")]
fn map_playlist_data(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "playlist" / format!("playlist_{}.json", name));
let json_path = path!("testfiles" / "playlist" / format!("playlist_{name}.json"));
let json_file = File::open(json_path).unwrap();
let playlist: response::Playlist =
@ -255,7 +254,7 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_playlist_data_{}", name), map_res.c, {
insta::assert_ron_snapshot!(format!("map_playlist_data_{name}"), map_res.c, {
".last_update" => "[date]"
});
}

View file

@ -533,7 +533,7 @@ impl MusicListMapper {
// Track
Some((MusicPageType::Track { is_video }, id)) => {
let title =
title.ok_or_else(|| format!("track {}: could not get title", id))?;
title.ok_or_else(|| format!("track {id}: could not get title"))?;
let (artists_p, album_p, duration_p) = match item.flex_column_display_style
{
@ -549,7 +549,7 @@ impl MusicListMapper {
} else {
let mut subtitle_parts = c2
.ok_or_else(|| {
format!("track {}: could not get subtitle", id)
format!("track {id}: could not get subtitle")
})?
.renderer
.text
@ -649,7 +649,7 @@ impl MusicListMapper {
.into_iter();
let title =
title.ok_or_else(|| format!("track {}: could not get title", id))?;
title.ok_or_else(|| format!("track {id}: could not get title"))?;
let subtitle_p1 = subtitle_parts.next();
let subtitle_p2 = subtitle_parts.next();
@ -812,8 +812,7 @@ impl MusicListMapper {
}
_ => {
return Err(format!(
"could not parse subtitle of album {}",
id
"could not parse subtitle of album {id}"
));
}
};
@ -1057,7 +1056,7 @@ mod tests {
atype_samples.iter().for_each(|(lang, entry)| {
entry.iter().for_each(|(album_type, txt)| {
let res = map_album_type(txt, *lang);
assert_eq!(res, *album_type, "lang: {}, txt: {}", lang, txt);
assert_eq!(res, *album_type, "lang: {lang}, txt: {txt}");
});
});
}

View file

@ -147,7 +147,7 @@ mod tests {
#[case::empty("empty")]
#[case::ab3_channel_handles("20221121_AB3_channel_handles")]
fn t_map_search(#[case] name: &str) {
let json_path = path!("testfiles" / "search" / format!("{}.json", name));
let json_path = path!("testfiles" / "search" / format!("{name}.json"));
let json_file = File::open(json_path).unwrap();
let search: response::Search = serde_json::from_reader(BufReader::new(json_file)).unwrap();
@ -159,7 +159,7 @@ mod tests {
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_search_{}", name), map_res.c, {
insta::assert_ron_snapshot!(format!("map_search_{name}"), map_res.c, {
".items.items.*.publish_date" => "[date]",
});
}

View file

@ -101,7 +101,7 @@ impl RustyPipeQuery {
// YouTube Music album has to be resolved by the YTM API
if resolve_albums && id.starts_with(util::PLAYLIST_ID_ALBUM_PREFIX) {
self._navigation_resolve_url(
&format!("/playlist?list={}", id),
&format!("/playlist?list={id}"),
ClientType::DesktopMusic,
)
.await
@ -225,7 +225,7 @@ impl RustyPipeQuery {
}
// URL without protocol
else if string.contains('/') && string.contains('.') {
self.resolve_url(&format!("https://{}", string), resolve_albums)
self.resolve_url(&format!("https://{string}"), resolve_albums)
.await
}
// ID only
@ -241,7 +241,7 @@ impl RustyPipeQuery {
} else if util::PLAYLIST_ID_REGEX.is_match(string) {
if resolve_albums && string.starts_with(util::PLAYLIST_ID_ALBUM_PREFIX) {
self._navigation_resolve_url(
&format!("/playlist?list={}", string),
&format!("/playlist?list={string}"),
ClientType::DesktopMusic,
)
.await

View file

@ -100,8 +100,7 @@ impl MapResponse<VideoDetails> for response::VideoDetails {
let video_id = current_video_endpoint.watch_endpoint.video_id;
if id != video_id {
return Err(ExtractionError::WrongResult(format!(
"got wrong playlist id {}, expected {}",
video_id, id
"got wrong playlist id {video_id}, expected {id}"
)));
}
@ -555,8 +554,7 @@ mod tests {
#[case::new_cont("20221011_new_continuation", "ZeerrnuLi5E")]
#[case::no_recommends("20221011_rec_isr", "nFDBxBUfE74")]
fn map_video_details(#[case] name: &str, #[case] id: &str) {
let json_path =
path!("testfiles" / "video_details" / format!("video_details_{}.json", name));
let json_path = path!("testfiles" / "video_details" / format!("video_details_{name}.json"));
let json_file = File::open(json_path).unwrap();
let details: response::VideoDetails =
@ -568,7 +566,7 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_video_details_{}", name), map_res.c, {
insta::assert_ron_snapshot!(format!("map_video_details_{name}"), map_res.c, {
".publish_date" => "[date]",
".recommended.items[].publish_date" => "[date]",
});
@ -592,7 +590,7 @@ mod tests {
#[case::top("top")]
#[case::latest("latest")]
fn map_comments(#[case] name: &str) {
let json_path = path!("testfiles" / "video_details" / format!("comments_{}.json", name));
let json_path = path!("testfiles" / "video_details" / format!("comments_{name}.json"));
let json_file = File::open(json_path).unwrap();
let comments: response::VideoComments =
@ -604,7 +602,7 @@ mod tests {
"deserialization/mapping warnings: {:?}",
map_res.warnings
);
insta::assert_ron_snapshot!(format!("map_comments_{}", name), map_res.c, {
insta::assert_ron_snapshot!(format!("map_comments_{name}"), map_res.c, {
".items[].publish_date" => "[date]",
});
}

View file

@ -84,7 +84,7 @@ fn get_sig_fn_name(player_js: &str) -> Result<String> {
}
fn caller_function(fn_name: &str) -> String {
format!("var {}={};", DEOBFUSCATION_FUNC_NAME, fn_name)
format!("var {DEOBFUSCATION_FUNC_NAME}={fn_name};")
}
fn get_sig_fn(player_js: &str) -> Result<String> {
@ -274,8 +274,7 @@ async fn get_player_js_url(http: &Client) -> Result<String> {
.as_str();
Ok(format!(
"https://www.youtube.com/s/player/{}/player_ias.vflset/en_US/base.js",
player_hash
"https://www.youtube.com/s/player/{player_hash}/player_ias.vflset/en_US/base.js"
))
}
@ -402,8 +401,8 @@ c[36](c[8],c[32]),c[20](c[25],c[10]),c[2](c[22],c[8]),c[32](c[20],c[16]),c[32](c
let deobf = tokio_test::block_on(Deobfuscator::new(client)).unwrap();
let deobf_sig = deobf.deobfuscate_sig("GOqGOqGOq0QJ8wRAIgaryQHfplJ9xJSKFywyaSMHuuwZYsoMTAvRvfm51qIGECIA5061zWeyfMPX9hEl_U6f9J0tr7GTJMKyPf5XNrJb5fb5i").unwrap();
println!("{}", deobf_sig);
println!("{deobf_sig}");
let deobf_nsig = deobf.deobfuscate_nsig("WHbZ-Nj2TSJxder").unwrap();
println!("{}", deobf_nsig);
println!("{deobf_nsig}");
}
}

View file

@ -93,17 +93,17 @@ impl UrlTarget {
pub fn to_url_yt_host(&self, yt_host: &str) -> String {
match self {
UrlTarget::Video { id, start_time, .. } => match start_time {
0 => format!("{}/watch?v={}", yt_host, id),
n => format!("{}/watch?v={}&t={}s", yt_host, id, n),
0 => format!("{yt_host}/watch?v={id}"),
n => format!("{yt_host}/watch?v={id}&t={n}s"),
},
UrlTarget::Channel { id } => {
format!("{}/channel/{}", yt_host, id)
format!("{yt_host}/channel/{id}")
}
UrlTarget::Playlist { id } => {
format!("{}/playlist?list={}", yt_host, id)
format!("{yt_host}/playlist?list={id}")
}
UrlTarget::Album { id } => {
format!("https://music.youtube.com/browse/{}", id)
format!("https://music.youtube.com/browse/{id}")
}
}
}

View file

@ -848,13 +848,13 @@ impl Display for Country {
impl FromStr for Language {
type Err = serde_json::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
serde_json::from_str(&format!("\"{}\"", s))
serde_json::from_str(&format!("\"{s}\""))
}
}
impl FromStr for Country {
type Err = serde_json::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
serde_json::from_str(&format!("\"{}\"", s))
serde_json::from_str(&format!("\"{s}\""))
}
}

View file

@ -130,7 +130,7 @@ impl FileReporter {
fn _report(&self, report: &Report) -> Result<(), Error> {
let report_path = get_report_path(&self.path, report, "json")?;
serde_json::to_writer_pretty(&File::create(report_path)?, &report)
.map_err(|e| Error::Other(format!("could not serialize report. err: {}", e).into()))?;
.map_err(|e| Error::Other(format!("could not serialize report. err: {e}").into()))?;
Ok(())
}
}
@ -162,13 +162,13 @@ fn get_report_path(root: &Path, report: &Report, ext: &str) -> Result<PathBuf, E
);
let mut report_path = root.to_path_buf();
report_path.push(format!("{}.{}", filename_prefix, ext));
report_path.push(format!("{filename_prefix}.{ext}"));
// ensure unique filename
for i in 1..u32::MAX {
if report_path.exists() {
report_path = root.to_path_buf();
report_path.push(format!("{}_{}.{}", filename_prefix, i, ext));
report_path.push(format!("{filename_prefix}_{i}.{ext}"));
} else {
break;
}

View file

@ -209,7 +209,7 @@ pub(crate) fn parse_timeago_or_warn(
) -> Option<TimeAgo> {
let res = parse_timeago(lang, textual_date);
if res.is_none() {
warnings.push(format!("could not parse timeago `{}`", textual_date));
warnings.push(format!("could not parse timeago `{textual_date}`"));
}
res
}
@ -221,7 +221,7 @@ pub(crate) fn parse_timeago_dt_or_warn(
) -> Option<OffsetDateTime> {
let res = parse_timeago_to_dt(lang, textual_date);
if res.is_none() {
warnings.push(format!("could not parse timeago `{}`", textual_date));
warnings.push(format!("could not parse timeago `{textual_date}`"));
}
res
}
@ -288,7 +288,7 @@ pub(crate) fn parse_textual_date_or_warn(
) -> Option<OffsetDateTime> {
let res = parse_textual_date_to_dt(lang, textual_date);
if res.is_none() {
warnings.push(format!("could not parse textual date `{}`", textual_date));
warnings.push(format!("could not parse textual date `{textual_date}`"));
}
res
}
@ -482,9 +482,7 @@ mod tests {
assert_eq!(
parse_timeago(*lang, s),
Some(expect[n]),
"Language: {}, n: {}",
lang,
n
"Language: {lang}, n: {n}"
);
});
})
@ -515,9 +513,7 @@ mod tests {
assert_eq!(
timeago,
Some(TimeAgo { n: *n, unit: *t }),
"lang: {}, txt: {}",
lang,
txt
"lang: {lang}, txt: {txt}"
);
n_cases += 1;
@ -561,8 +557,7 @@ mod tests {
n: 0,
unit: TimeUnit::Day
})),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Yesterday").unwrap()),
@ -574,8 +569,7 @@ mod tests {
},
unit: TimeUnit::Day
})),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Ago").unwrap()),
@ -583,80 +577,67 @@ mod tests {
n: 3,
unit: TimeUnit::Day
})),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Jan").unwrap()),
Some(ParsedDate::Absolute(date!(2020 - 1 - 3))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Feb").unwrap()),
Some(ParsedDate::Absolute(date!(2016 - 2 - 7))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Mar").unwrap()),
Some(ParsedDate::Absolute(date!(2015 - 3 - 9))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Apr").unwrap()),
Some(ParsedDate::Absolute(date!(2017 - 4 - 2))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("May").unwrap()),
Some(ParsedDate::Absolute(date!(2014 - 5 - 22))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Jun").unwrap()),
Some(ParsedDate::Absolute(date!(2014 - 6 - 28))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Jul").unwrap()),
Some(ParsedDate::Absolute(date!(2014 - 7 - 2))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Aug").unwrap()),
Some(ParsedDate::Absolute(date!(2015 - 8 - 23))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Sep").unwrap()),
Some(ParsedDate::Absolute(date!(2018 - 9 - 16))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Oct").unwrap()),
Some(ParsedDate::Absolute(date!(2014 - 10 - 31))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Nov").unwrap()),
Some(ParsedDate::Absolute(date!(2016 - 11 - 3))),
"lang: {}",
lang
"lang: {lang}"
);
assert_eq!(
parse_textual_date(*lang, samples.get("Dec").unwrap()),
Some(ParsedDate::Absolute(date!(2021 - 12 - 24))),
"lang: {}",
lang
"lang: {lang}"
);
})
}

View file

@ -91,7 +91,7 @@ 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<(Url, BTreeMap<String, String>), Error> {
let mut parsed_url = Url::parse(url)
.map_err(|e| Error::Other(format!("could not parse url `{}` err: {}", url, e).into()))?;
.map_err(|e| Error::Other(format!("could not parse url `{url}` err: {e}").into()))?;
let url_params: BTreeMap<String, String> = parsed_url
.query_pairs()
.map(|(k, v)| (k.to_string(), v.to_string()))
@ -168,7 +168,7 @@ where
{
let res = parse_numeric::<F>(string);
if res.is_err() {
warnings.push(format!("could not parse number `{}`", string));
warnings.push(format!("could not parse number `{string}`"));
}
res.ok()
}
@ -409,10 +409,7 @@ mod tests {
let res = retry_delay(n, 1000, 60000, 3);
assert!(
res >= expect_min && res <= expect_max,
"res: {} not within {} and {}",
res,
expect_min,
expect_max
"res: {res} not within {expect_min} and {expect_max}"
);
}
@ -490,10 +487,6 @@ mod tests {
};
let res = parse_large_numstr::<u64>(string, lang).expect(string);
assert_eq!(
res, rounded,
"{} (lang: {}, exact: {})",
string, lang, expect
);
assert_eq!(res, rounded, "{string} (lang: {lang}, exact: {expect})");
}
}

View file

@ -226,7 +226,7 @@ fn get_player(
assert_eq!(details.id, id);
assert_eq!(details.name, name);
let desc = details.description.unwrap();
assert!(desc.contains(description), "description: {}", desc);
assert!(desc.contains(description), "description: {desc}");
assert_eq!(details.length, length);
assert_eq!(details.channel.id, channel_id);
assert_eq!(details.channel.name, channel_name);
@ -267,7 +267,7 @@ fn get_player(
.collect::<HashSet<_>>();
for l in ["en", "es", "fr", "pt", "ru"] {
assert!(langs.contains(l), "missing lang: {}", l);
assert!(langs.contains(l), "missing lang: {l}");
}
}
_ => {}
@ -311,9 +311,7 @@ fn get_player_error(#[case] id: &str, #[case] msg: &str) {
assert!(
err.starts_with(msg),
"got error msg: `{}`, expected: `{}`",
err,
msg
"got error msg: `{err}`, expected: `{msg}`"
);
}
@ -400,8 +398,7 @@ fn playlist_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -419,8 +416,7 @@ fn get_video_details() {
let desc = details.description.to_plaintext();
assert!(
desc.contains("Listen and download aespa's debut single \"Black Mamba\""),
"bad description: {}",
desc
"bad description: {desc}"
);
assert_eq!(details.channel.id, "UCEf_Bc-KVd7onSeifS3py9g");
@ -459,7 +455,7 @@ fn get_video_details_music() {
assert_eq!(details.id, "XuM2onMGvTI");
assert_eq!(details.name, "Gäa");
let desc = details.description.to_plaintext();
assert!(desc.contains("Gäa · Oonagh"), "bad description: {}", desc);
assert!(desc.contains("Gäa · Oonagh"), "bad description: {desc}");
assert_eq!(details.channel.id, "UCVGvnqB-5znqPSbMGlhF4Pw");
assert_eq!(details.channel.name, "Sentamusic");
@ -506,8 +502,7 @@ fn get_video_details_ccommons() {
let desc = details.description.to_plaintext();
assert!(
desc.contains("Seit Anfang 2019 hat David jeden einzelnen Halt jeder einzelnen Zugfahrt auf jedem einzelnen Fernbahnhof in ganz Deutschland"),
"bad description: {}",
desc
"bad description: {desc}"
);
assert_eq!(details.channel.id, "UC2TXq_t06Hjdr2g_KdKpHQg");
@ -548,8 +543,7 @@ fn get_video_details_chapters() {
let desc = details.description.to_plaintext();
assert!(
desc.contains("These days, you can game almost anywhere on the planet, anytime. But what if that planet was in the middle of an apocalypse"),
"bad description: {}",
desc
"bad description: {desc}"
);
assert_eq!(details.channel.id, "UCXuqSBlHAE6Xw-yeJA0Tunw");
@ -676,8 +670,7 @@ fn get_video_details_live() {
let desc = details.description.to_plaintext();
assert!(
desc.contains("The station is crewed by NASA astronauts as well as Russian Cosmonauts"),
"bad description: {}",
desc
"bad description: {desc}"
);
assert_eq!(details.channel.id, "UCakgsb0w7QB0VHdnCc-OVEA");
@ -758,8 +751,7 @@ fn get_video_details_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
)
}
@ -1001,8 +993,7 @@ fn channel_not_found(#[case] id: &str) {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -1307,8 +1298,7 @@ fn music_playlist_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -1329,7 +1319,7 @@ fn music_album(#[case] name: &str, #[case] id: &str) {
assert!(!album.cover.is_empty(), "got no cover");
insta::assert_ron_snapshot!(format!("music_album_{}", name), album,
insta::assert_ron_snapshot!(format!("music_album_{name}"), album,
{".cover" => "[cover]"}
);
}
@ -1344,8 +1334,7 @@ fn music_album_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -1401,7 +1390,7 @@ fn music_artist(
// Sort albums to ensure consistent order
artist.albums.sort_by_key(|a| a.id.to_owned());
insta::assert_ron_snapshot!(format!("music_artist_{}", name), artist, {
insta::assert_ron_snapshot!(format!("music_artist_{name}"), artist, {
".header_image" => "[header_image]",
".subscriber_count" => "[subscriber_count]",
".albums[].cover" => "[cover]",
@ -1422,8 +1411,7 @@ fn music_artist_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -1721,14 +1709,11 @@ fn music_search_suggestion(#[case] query: &str, #[case] expect: Option<&str>) {
match expect {
Some(expect) => assert!(
suggestion.iter().any(|s| s == expect),
"suggestion: {:?}, expected: {}",
suggestion,
expect
"suggestion: {suggestion:?}, expected: {expect}"
),
None => assert!(
suggestion.is_empty(),
"suggestion: {:?}, expected to be empty",
suggestion
"suggestion: {suggestion:?}, expected to be empty"
),
}
}
@ -1747,7 +1732,7 @@ fn music_details(#[case] name: &str, #[case] id: &str) {
assert!(track.track.view_count.is_none());
}
insta::assert_ron_snapshot!(format!("music_details_{}", name), track,
insta::assert_ron_snapshot!(format!("music_details_{name}"), track,
{
".track.cover" => "[cover]",
".track.view_count" => "[view_count]"
@ -1774,8 +1759,7 @@ fn music_lyrics_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -1890,8 +1874,7 @@ fn music_details_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -1912,8 +1895,7 @@ fn music_radio_track_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -1942,8 +1924,7 @@ fn music_radio_playlist_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
}
@ -1967,8 +1948,7 @@ fn music_radio_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -2117,8 +2097,7 @@ fn music_genre_not_found() {
err,
Error::Extraction(ExtractionError::ContentUnavailable(_))
),
"got: {}",
err
"got: {err}"
);
}
@ -2157,9 +2136,9 @@ fn invalid_ctoken(#[case] ep: ContinuationEndpoint) {
ExtractionError::BadRequest(msg) => {
assert_eq!(msg, "Request contains an invalid argument.")
}
_ => panic!("invalid error: {}", e),
_ => panic!("invalid error: {e}"),
},
_ => panic!("invalid error: {}", e),
_ => panic!("invalid error: {e}"),
}
}
@ -2171,15 +2150,13 @@ fn assert_approx(left: f64, right: f64) {
let f = left / right;
assert!(
0.9 < f && f < 1.1,
"{} not within 10% margin of {}",
left,
right
"{left} not within 10% margin of {right}"
);
}
}
fn assert_gte<T: PartialOrd + Display>(a: T, b: T, msg: &str) {
assert!(a >= b, "expected {} {}, got {}", b, msg, a);
assert!(a >= b, "expected {b} {msg}, got {a}");
}
/// Assert that the paginator produces at least n pages
@ -2218,17 +2195,17 @@ fn assert_next_items<T: FromYtItem, Q: AsRef<RustyPipeQuery>>(
}
fn assert_video_id(id: &str) {
assert!(validate::video_id(id), "invalid video id: `{}`", id)
assert!(validate::video_id(id), "invalid video id: `{id}`")
}
fn assert_channel_id(id: &str) {
assert!(validate::channel_id(id), "invalid channel id: `{}`", id);
assert!(validate::channel_id(id), "invalid channel id: `{id}`");
}
fn assert_album_id(id: &str) {
assert!(validate::album_id(id), "invalid album id: `{}`", id);
assert!(validate::album_id(id), "invalid album id: `{id}`");
}
fn assert_playlist_id(id: &str) {
assert!(validate::playlist_id(id), "invalid playlist id: `{}`", id);
assert!(validate::playlist_id(id), "invalid playlist id: `{id}`");
}