GUI plugins #9
3 changed files with 30 additions and 20 deletions
pinakes-core: unify book metadata extraction; remove ExtractedBookMetadata
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ifd6e66515b9ff78a4bb13eba47b9b2cf6a6a6964
commit
8f2b44b50c
|
|
@ -32,7 +32,7 @@ fn extract_pdf(path: &Path) -> Result<ExtractedMetadata> {
|
||||||
.map_err(|e| PinakesError::MetadataExtraction(format!("PDF load: {e}")))?;
|
.map_err(|e| PinakesError::MetadataExtraction(format!("PDF load: {e}")))?;
|
||||||
|
|
||||||
let mut meta = ExtractedMetadata::default();
|
let mut meta = ExtractedMetadata::default();
|
||||||
let mut book_meta = crate::model::ExtractedBookMetadata::default();
|
let mut book_meta = crate::model::BookMetadata::default();
|
||||||
|
|
||||||
// Find the Info dictionary via the trailer
|
// Find the Info dictionary via the trailer
|
||||||
if let Ok(info_ref) = doc.trailer.get(b"Info") {
|
if let Ok(info_ref) = doc.trailer.get(b"Info") {
|
||||||
|
|
@ -145,7 +145,7 @@ fn extract_epub(path: &Path) -> Result<ExtractedMetadata> {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut book_meta = crate::model::ExtractedBookMetadata::default();
|
let mut book_meta = crate::model::BookMetadata::default();
|
||||||
|
|
||||||
// Extract basic metadata
|
// Extract basic metadata
|
||||||
if let Some(lang) = doc.mdata("language") {
|
if let Some(lang) = doc.mdata("language") {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use std::{collections::HashMap, path::Path};
|
||||||
use crate::{
|
use crate::{
|
||||||
error::Result,
|
error::Result,
|
||||||
media_type::MediaType,
|
media_type::MediaType,
|
||||||
model::ExtractedBookMetadata,
|
model::BookMetadata,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
|
@ -22,7 +22,7 @@ pub struct ExtractedMetadata {
|
||||||
pub duration_secs: Option<f64>,
|
pub duration_secs: Option<f64>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub extra: HashMap<String, String>,
|
pub extra: HashMap<String, String>,
|
||||||
pub book_metadata: Option<ExtractedBookMetadata>,
|
pub book_metadata: Option<BookMetadata>,
|
||||||
|
|
||||||
// Photo-specific metadata
|
// Photo-specific metadata
|
||||||
pub date_taken: Option<chrono::DateTime<chrono::Utc>>,
|
pub date_taken: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
|
|
|
||||||
|
|
@ -417,6 +417,10 @@ pub struct SavedSearch {
|
||||||
// Book Management Types
|
// Book Management Types
|
||||||
|
|
||||||
/// Metadata for book-type media.
|
/// Metadata for book-type media.
|
||||||
|
///
|
||||||
|
/// Used both as a DB record (with populated `media_id`, `created_at`,
|
||||||
|
/// `updated_at`) and as an extraction result (with placeholder values for
|
||||||
|
/// those fields when the record has not yet been persisted).
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct BookMetadata {
|
pub struct BookMetadata {
|
||||||
pub media_id: MediaId,
|
pub media_id: MediaId,
|
||||||
|
|
@ -435,6 +439,28 @@ pub struct BookMetadata {
|
||||||
pub updated_at: DateTime<Utc>,
|
pub updated_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for BookMetadata {
|
||||||
|
fn default() -> Self {
|
||||||
|
let now = Utc::now();
|
||||||
|
Self {
|
||||||
|
media_id: MediaId(uuid::Uuid::nil()),
|
||||||
|
isbn: None,
|
||||||
|
isbn13: None,
|
||||||
|
publisher: None,
|
||||||
|
language: None,
|
||||||
|
page_count: None,
|
||||||
|
publication_date: None,
|
||||||
|
series_name: None,
|
||||||
|
series_index: None,
|
||||||
|
format: None,
|
||||||
|
authors: Vec::new(),
|
||||||
|
identifiers: HashMap::new(),
|
||||||
|
created_at: now,
|
||||||
|
updated_at: now,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Information about a book author.
|
/// Information about a book author.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
pub struct AuthorInfo {
|
pub struct AuthorInfo {
|
||||||
|
|
@ -476,22 +502,6 @@ impl AuthorInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Book metadata extracted from files (without database-specific fields)
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
|
||||||
pub struct ExtractedBookMetadata {
|
|
||||||
pub isbn: Option<String>,
|
|
||||||
pub isbn13: Option<String>,
|
|
||||||
pub publisher: Option<String>,
|
|
||||||
pub language: Option<String>,
|
|
||||||
pub page_count: Option<i32>,
|
|
||||||
pub publication_date: Option<chrono::NaiveDate>,
|
|
||||||
pub series_name: Option<String>,
|
|
||||||
pub series_index: Option<f64>,
|
|
||||||
pub format: Option<String>,
|
|
||||||
pub authors: Vec<AuthorInfo>,
|
|
||||||
pub identifiers: HashMap<String, Vec<String>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reading progress for a book.
|
/// Reading progress for a book.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ReadingProgress {
|
pub struct ReadingProgress {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue