mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor: enhance YouTube Premium check logic and streamline response handling
This commit is contained in:
@@ -241,4 +241,8 @@ needless_collect = "deny"
|
|||||||
missing_const_for_fn = "deny"
|
missing_const_for_fn = "deny"
|
||||||
iter_with_drain = "deny"
|
iter_with_drain = "deny"
|
||||||
iter_on_single_items = "deny"
|
iter_on_single_items = "deny"
|
||||||
iter_on_empty_collections = "deny"
|
iter_on_empty_collections = "deny"
|
||||||
|
# fallible_impl_from = "deny" // 过于激进,暂时不开启
|
||||||
|
equatable_if_let = "deny"
|
||||||
|
collection_is_never_read = "deny"
|
||||||
|
branches_sharing_code = "deny"
|
||||||
@@ -189,7 +189,6 @@ pub async fn apply_dns_config(apply: bool) -> CmdResult {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
logging!(info, Type::Config, "DNS config successfully applied");
|
logging!(info, Type::Config, "DNS config successfully applied");
|
||||||
handle::Handle::refresh_clash();
|
|
||||||
} else {
|
} else {
|
||||||
// 当关闭DNS设置时,重新生成配置(不加载DNS配置文件)
|
// 当关闭DNS设置时,重新生成配置(不加载DNS配置文件)
|
||||||
logging!(
|
logging!(
|
||||||
@@ -212,9 +211,9 @@ pub async fn apply_dns_config(apply: bool) -> CmdResult {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
logging!(info, Type::Config, "Config regenerated successfully");
|
logging!(info, Type::Config, "Config regenerated successfully");
|
||||||
handle::Handle::refresh_clash();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle::Handle::refresh_clash();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,19 +13,23 @@ pub(super) async fn check_youtube_premium(client: &Client) -> UnlockItem {
|
|||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if let Ok(body) = response.text().await {
|
if let Ok(body) = response.text().await {
|
||||||
let body_lower = body.to_lowercase();
|
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") {
|
if body_lower.contains("youtube premium is not available in your country") {
|
||||||
return UnlockItem {
|
status = "No";
|
||||||
name: "Youtube Premium".to_string(),
|
} else if body_lower.contains("ad-free") {
|
||||||
status: "No".to_string(),
|
match Regex::new(r#"id="country-code"[^>]*>([^<]+)<"#) {
|
||||||
region: None,
|
Ok(re) => {
|
||||||
check_time: Some(get_local_date_string()),
|
if let Some(caps) = re.captures(&body)
|
||||||
};
|
&& let Some(m) = caps.get(1)
|
||||||
}
|
{
|
||||||
|
let country_code = m.as_str().trim();
|
||||||
if body_lower.contains("ad-free") {
|
let emoji = country_code_to_emoji(country_code);
|
||||||
let re = match Regex::new(r#"id="country-code"[^>]*>([^<]+)<"#) {
|
region = Some(format!("{emoji}{country_code}"));
|
||||||
Ok(re) => re,
|
status = "Yes";
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
logging!(
|
logging!(
|
||||||
error,
|
error,
|
||||||
@@ -33,34 +37,14 @@ pub(super) async fn check_youtube_premium(client: &Client) -> UnlockItem {
|
|||||||
"Failed to compile YouTube Premium regex: {}",
|
"Failed to compile YouTube Premium regex: {}",
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
return UnlockItem {
|
|
||||||
name: "Youtube Premium".to_string(),
|
|
||||||
status: "Failed".to_string(),
|
|
||||||
region: None,
|
|
||||||
check_time: Some(get_local_date_string()),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
let region = re.captures(&body).and_then(|caps| {
|
|
||||||
caps.get(1).map(|m| {
|
|
||||||
let country_code = m.as_str().trim();
|
|
||||||
let emoji = country_code_to_emoji(country_code);
|
|
||||||
format!("{emoji}{country_code}")
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
return UnlockItem {
|
|
||||||
name: "Youtube Premium".to_string(),
|
|
||||||
status: "Yes".to_string(),
|
|
||||||
region,
|
|
||||||
check_time: Some(get_local_date_string()),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UnlockItem {
|
UnlockItem {
|
||||||
name: "Youtube Premium".to_string(),
|
name: "Youtube Premium".to_string(),
|
||||||
status: "Failed".to_string(),
|
status: status.to_string(),
|
||||||
region: None,
|
region,
|
||||||
check_time: Some(get_local_date_string()),
|
check_time: Some(get_local_date_string()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user