diff --git a/src/error.rs b/src/error.rs index 05cf80b..20d51aa 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,7 +17,7 @@ pub enum IaGetError { FileSystem(String), /// URL format or parsing errors - #[error("Invalid URL: {0}")] + #[error("Invalid archive.org URL: {0}. Expected format: https://archive.org/details/[/]")] UrlFormat(String), /// MD5 hash verification failures diff --git a/src/main.rs b/src/main.rs index 6dafad1..bad691e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,9 +119,7 @@ async fn main() -> std::result::Result<(), Box> { // Validate URL format using consolidated function if let Err(e) = validate_archive_url(&cli.url) { - spinner.finish_with_message(format!("❌ Invalid archive.org URL format: {}", cli.url)); - println!("├╼ Archive.org URL is not in the expected format"); - println!("╰╼ Expected format: https://archive.org/details/[/]"); + spinner.finish_with_message(format!("❌ {}", e)); return Err(e.into()); } diff --git a/src/utils.rs b/src/utils.rs index 6d82f1c..13aadfc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -33,13 +33,15 @@ static URL_REGEX: LazyLock = LazyLock::new(|| { /// ``` pub fn validate_archive_url(url: &str) -> Result<()> { if URL_REGEX.is_match(url) { - Ok(()) - } else { - Err(IaGetError::UrlFormat(format!( - "URL '{}' does not match expected format. Expected: https://archive.org/details/[/]", - url - ))) + // Further check: ensure there's an identifier after "details/" + // and that the identifier is not empty. + if let Some(path_segment) = url.split("/details/").nth(1) { + if !path_segment.trim_end_matches('/').is_empty() { + return Ok(()); + } + } } + Err(IaGetError::UrlFormat(url.to_string())) } /// Create a progress bar with consistent styling