From 1fe8746dda317f117b878a6c18c583b416737993 Mon Sep 17 00:00:00 2001 From: bytedream Date: Wed, 5 Jul 2023 16:01:55 +0200 Subject: [PATCH] Add support for old url scheme (#224) --- crunchy-cli-core/src/utils/parse.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crunchy-cli-core/src/utils/parse.rs b/crunchy-cli-core/src/utils/parse.rs index 1bf9364..f85d8c2 100644 --- a/crunchy-cli-core/src/utils/parse.rs +++ b/crunchy-cli-core/src/utils/parse.rs @@ -130,6 +130,20 @@ pub async fn parse_url( UrlFilter::default() }; + // check if the url is the old series/episode scheme which still occurs in some places (like the + // rss) + let old_url_regex = Regex::new(r"https?://(www\.)?crunchyroll\.com/.+").unwrap(); + if old_url_regex.is_match(&url) { + debug!("Detected maybe old url"); + // replace the 'http' prefix with 'https' as https is not supported by the reqwest client + if url.starts_with("http://") { + url.replace_range(0..4, "https") + } + // the old url redirects to the new url. request the old url, follow the redirects and + // extract the final url + url = crunchy.client().get(&url).send().await?.url().to_string() + } + let parsed_url = crunchyroll_rs::parse_url(url).map_or(Err(anyhow!("Invalid url")), Ok)?; debug!("Url type: {:?}", parsed_url); let media_collection = match parsed_url {