Skip to content

Commit

Permalink
Fallback to path and modified date if there is no unique id
Browse files Browse the repository at this point in the history
  • Loading branch information
zoriya committed Sep 10, 2023
1 parent 1dd3e37 commit 34e4036
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions transcoder/src/identify.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use json::JsonValue;
use serde::Serialize;
use std::{
collections::HashMap,
fs, io,
collections::{hash_map::DefaultHasher, HashMap},
hash::{Hash, Hasher},
path::PathBuf,
process::Stdio,
str::{self, FromStr},
Expand Down Expand Up @@ -146,7 +146,15 @@ pub async fn identify(path: String) -> Result<MediaInfo, std::io::Error> {
.find(|x| x["@type"] == "General")
.unwrap();

let sha = general["UniqueID"].to_string();
let sha = general["UniqueID"]
.as_str()
.map(|x| x.to_string())
.unwrap_or_else(|| {
let mut hasher = DefaultHasher::new();
path.hash(&mut hasher);
general["File_Modified_Date"].to_string().hash(&mut hasher);
format!("{hash:x}", hash = hasher.finish())
});

let subs: Vec<Subtitle> = output["media"]["track"]
.members()
Expand Down

0 comments on commit 34e4036

Please sign in to comment.