Fix slow transcoder (use mediainfo id instead of sha1)

This commit is contained in:
Zoe Roux 2023-09-11 00:17:29 +02:00
parent 1641ba2898
commit e79e568a4c
3 changed files with 3 additions and 19 deletions

12
transcoder/Cargo.lock generated
View File

@ -1112,17 +1112,6 @@ dependencies = [
"serde",
]
[[package]]
name = "sha-1"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "sha1"
version = "0.10.5"
@ -1317,7 +1306,6 @@ dependencies = [
"rand",
"reqwest",
"serde",
"sha-1",
"tokio",
"utoipa",
]

View File

@ -13,4 +13,3 @@ derive_more = "0.99.17"
reqwest = { version = "0.11.16", default_features = false, features = ["json", "rustls-tls"] }
utoipa = { version = "3", features = ["actix_extras"] }
json = "0.12.4"
sha-1 = "0.10.1"

View File

@ -1,6 +1,5 @@
use json::JsonValue;
use serde::Serialize;
use sha1::{Digest, Sha1};
use std::{
collections::HashMap,
fs, io,
@ -103,6 +102,7 @@ pub struct Chapter {
}
async fn extract(path: String, sha: &String, subs: &Vec<Subtitle>) {
println!("Extract subs and fonts for {}", path);
let mut cmd = Command::new("ffmpeg");
cmd.current_dir(format!("/metadata/{sha}/att/"))
.args(&["-dump_attachment:t", ""])
@ -141,16 +141,13 @@ pub async fn identify(path: String) -> Result<MediaInfo, std::io::Error> {
assert!(mediainfo.status.success());
let output = json::parse(str::from_utf8(mediainfo.stdout.as_slice()).unwrap()).unwrap();
let mut file = fs::File::open(&path)?;
let mut hasher = Sha1::new();
io::copy(&mut file, &mut hasher)?;
let sha = format!("{:x}", hasher.finalize());
let general = output["media"]["track"]
.members()
.find(|x| x["@type"] == "General")
.unwrap();
let sha = general["UniqueID"].to_string();
let subs: Vec<Subtitle> = output["media"]["track"]
.members()
.filter(|x| x["@type"] == "Text")