diff --git a/transcoder/src/error.rs b/transcoder/src/error.rs index 1c487d99..4bea0ca7 100644 --- a/transcoder/src/error.rs +++ b/transcoder/src/error.rs @@ -20,7 +20,7 @@ impl error::ResponseError for ApiError { HttpResponse::build(self.status_code()) .insert_header(ContentType::json()) .body(format!( - "{{ \"status\": \"{status}\", \"error\": \"{err}\" }}", + "{{ \"status\": \"{status}\", \"errors\": [\"{err}\"] }}", status = self.status_code(), err = self.to_string() )) diff --git a/transcoder/src/identify.rs b/transcoder/src/identify.rs index 9cbc3779..b03621a1 100644 --- a/transcoder/src/identify.rs +++ b/transcoder/src/identify.rs @@ -127,7 +127,7 @@ async fn extract(path: String, sha: &String, subs: &Vec) { .expect("Error running ffmpeg extract"); } -pub async fn identify(path: String) -> Result { +pub async fn identify(path: String) -> Option { let extension_table: HashMap<&str, &str> = HashMap::from([("subrip", "srt"), ("ass", "ass"), ("vtt", "vtt")]); @@ -138,7 +138,9 @@ pub async fn identify(path: String) -> Result { .output() .await .expect("Error running the mediainfo command"); - assert!(mediainfo.status.success()); + if !mediainfo.status.success() { + return None; + } let output = json::parse(str::from_utf8(mediainfo.stdout.as_slice()).unwrap()).unwrap(); let general = output["media"]["track"] @@ -182,8 +184,8 @@ pub async fn identify(path: String) -> Result { .collect(); if !PathBuf::from(format!("/metadata/{sha}")).exists() { - std::fs::create_dir_all(format!("/metadata/{sha}/att"))?; - std::fs::create_dir_all(format!("/metadata/{sha}/sub"))?; + std::fs::create_dir_all(format!("/metadata/{sha}/att")).unwrap(); + std::fs::create_dir_all(format!("/metadata/{sha}/sub")).unwrap(); extract(path.clone(), &sha, &subs).await; } @@ -191,8 +193,8 @@ pub async fn identify(path: String) -> Result { v.as_str().and_then(|x| x.parse::().ok()) } - Ok(MediaInfo { - length: parse::(&general["Duration"]).unwrap(), + Some(MediaInfo { + length: parse::(&general["Duration"])?, container: general["Format"].as_str().unwrap().to_string(), video: { let v = output["media"]["track"] diff --git a/transcoder/src/main.rs b/transcoder/src/main.rs index 9001d0ab..6840981b 100644 --- a/transcoder/src/main.rs +++ b/transcoder/src/main.rs @@ -105,13 +105,12 @@ async fn identify_resource( .await .map_err(|_| ApiError::NotFound)?; - identify(path).await.map(|info| Json(info)).map_err(|e| { - eprintln!( - "Unhandled error occured while identifing the resource: {}", - e - ); - ApiError::InternalError - }) + identify(path) + .await + .map(|info| Json(info)) + .ok_or_else(|| ApiError::BadRequest { + error: "Invalid video file. Could not parse informations.".to_string(), + }) } /// Get attachments diff --git a/transcoder/src/state.rs b/transcoder/src/state.rs index 775fa672..2311aca5 100644 --- a/transcoder/src/state.rs +++ b/transcoder/src/state.rs @@ -54,7 +54,7 @@ impl Transcoder { pub async fn build_master(&self, resource: String, slug: String) -> Option { let mut master = String::from("#EXTM3U\n"); let path = get_path(resource, slug).await.ok()?; - let info = identify(path).await.ok()?; + let info = identify(path).await?; // TODO: Only add this if transmuxing is possible. if true {