diff --git a/Cargo.toml b/Cargo.toml index 6f249e1..a488655 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ rustls-tls-native-roots = ["reqwest/rustls-tls-native-roots"] # quick-js = "0.4.1" quick-js = { path = "../quickjs-rs", default-features = false } once_cell = "1.12.0" -fancy-regex = "0.10.0" +fancy-regex = "0.11.0" thiserror = "1.0.36" url = "2.2.2" log = "0.4.17" @@ -48,7 +48,7 @@ time = { version = "0.3.15", features = [ futures = "0.3.21" ress = "0.11.4" phf = "0.11.1" -base64 = "0.20.0" +base64 = "0.21.0" urlencoding = "2.1.2" quick-xml = { version = "0.26.0", features = ["serialize"], optional = true } diff --git a/src/client/music_artist.rs b/src/client/music_artist.rs index 1abb4f7..91d734a 100644 --- a/src/client/music_artist.rs +++ b/src/client/music_artist.rs @@ -175,7 +175,7 @@ fn map_artist_page( let share_channel_id = urlencoding::decode(&pb) .ok() - .and_then(|pb| base64::decode(pb.as_bytes()).ok()) + .and_then(|pb| util::b64_decode(pb.as_bytes()).ok()) .and_then(|pb| util::string_from_pb(pb, 3)); if let Some(share_channel_id) = share_channel_id { diff --git a/src/param/search_filter.rs b/src/param/search_filter.rs index 104e14a..71e6390 100644 --- a/src/param/search_filter.rs +++ b/src/param/search_filter.rs @@ -2,7 +2,7 @@ use std::collections::BTreeSet; -use crate::util::ProtoBuilder; +use crate::util::{self, ProtoBuilder}; /// YouTube search filter /// @@ -200,7 +200,7 @@ impl SearchFilter { pb.embedded(8, extras) } - let b64 = base64::encode(pb.bytes); + let b64 = util::b64_encode(pb.bytes); urlencoding::encode(&b64).to_string() } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 9791f47..f8d546a 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -12,6 +12,7 @@ use std::{ str::FromStr, }; +use base64::Engine; use fancy_regex::Regex; use once_cell::sync::Lazy; use rand::Rng; @@ -343,6 +344,14 @@ pub fn video_id_from_thumbnail_url(url: &str) -> Option { .and_then(|cap| cap.get(1).map(|x| x.as_str().to_owned())) } +pub fn b64_encode>(input: T) -> String { + base64::engine::general_purpose::STANDARD.encode(input) +} + +pub fn b64_decode>(input: T) -> Result, base64::DecodeError> { + base64::engine::general_purpose::STANDARD.decode(input) +} + #[cfg(test)] mod tests { use std::{fs::File, io::BufReader}; diff --git a/src/util/protobuf.rs b/src/util/protobuf.rs index 60731a7..5858a56 100644 --- a/src/util/protobuf.rs +++ b/src/util/protobuf.rs @@ -120,6 +120,8 @@ pub fn string_from_pb>(pb: P, field: u32) -> Option