mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
* feat(logging): introduce clash-verge-logging crate for management - Added a new crate `clash-verge-logging` with dependencies on `log`, `tokio`, `compact_str`, and `flexi_logger`. - Implemented logging types and macros for structured logging across the application. - Replaced existing logging imports with the new `clash_verge_logging` crate in various modules. - Updated logging functionality to support different logging types and error handling. - Refactored code to improve logging consistency and maintainability. * fix(logging): update import paths for clash_verge_logging in linux.rs and dns.rs * fix(logging): update import statement for clash_verge_logging in windows.rs
67 lines
2.4 KiB
Rust
67 lines
2.4 KiB
Rust
use regex::Regex;
|
|
use reqwest::Client;
|
|
|
|
use clash_verge_logging::{Type, logging};
|
|
|
|
use super::UnlockItem;
|
|
use super::utils::{country_code_to_emoji, get_local_date_string};
|
|
|
|
pub(super) async fn check_youtube_premium(client: &Client) -> UnlockItem {
|
|
let url = "https://www.youtube.com/premium";
|
|
|
|
match client.get(url).send().await {
|
|
Ok(response) => {
|
|
if let Ok(body) = response.text().await {
|
|
let body_lower = body.to_lowercase();
|
|
let mut status = "Failed";
|
|
let mut region = None;
|
|
|
|
if body_lower.contains("youtube premium is not available in your country") {
|
|
status = "No";
|
|
} else if body_lower.contains("ad-free") {
|
|
match Regex::new(r#"id="country-code"[^>]*>([^<]+)<"#) {
|
|
Ok(re) => {
|
|
if let Some(caps) = re.captures(&body)
|
|
&& let Some(m) = caps.get(1)
|
|
{
|
|
let country_code = m.as_str().trim();
|
|
let emoji = country_code_to_emoji(country_code);
|
|
region = Some(format!("{emoji}{country_code}"));
|
|
status = "Yes";
|
|
}
|
|
}
|
|
Err(e) => {
|
|
logging!(
|
|
error,
|
|
Type::Network,
|
|
"Failed to compile YouTube Premium regex: {}",
|
|
e
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
UnlockItem {
|
|
name: "Youtube Premium".to_string(),
|
|
status: status.to_string(),
|
|
region,
|
|
check_time: Some(get_local_date_string()),
|
|
}
|
|
} else {
|
|
UnlockItem {
|
|
name: "Youtube Premium".to_string(),
|
|
status: "Failed".to_string(),
|
|
region: None,
|
|
check_time: Some(get_local_date_string()),
|
|
}
|
|
}
|
|
}
|
|
Err(_) => UnlockItem {
|
|
name: "Youtube Premium".to_string(),
|
|
status: "Failed".to_string(),
|
|
region: None,
|
|
check_time: Some(get_local_date_string()),
|
|
},
|
|
}
|
|
}
|