-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
Some epubs may use custom string when assigning their cover images. My current workaround is below, some context is missing but i'm sure you can figure it out
//Look for keys in the hashmap containing the word cover
let pattern = r"(?i)cover";
let regex = Regex::new(pattern).unwrap();
let epub_resources = doc.resources.clone();
println!("Resources {:?}", epub_resources);
let cover_id = epub_resources.keys().find(|key| regex.is_match(key));
if cover_id.is_some() {
let cover = doc.get_resource(cover_id.unwrap());
let cover_data = cover.unwrap().0;
let mut f = fs::File
::create(&cover_path)
.map_err(|err| format!("Error creating cover file: {}", err))?;
f.write_all(&cover_data).map_err(|err| format!("Error writing cover data: {}", err))?;
} else {
//Return our error thumbnail placeholder
return Ok(format!("{}/{}", get_home_dir(), "error.jpg"));
}
Metadata
Metadata
Assignees
Labels
No labels