use crate::{ addressing::Address, database::{entry::Entry, UpEndConnection}, util::jobs::JobContainer, }; use anyhow::Result; use std::sync::{Arc, RwLock}; #[cfg(feature = "extractors-web")] pub mod web; #[cfg(feature = "extractors-audio")] pub mod audio; pub trait Extractor { fn get( &self, address: &Address, connection: &UpEndConnection, job_container: Arc>, ) -> Result>; fn is_needed(&self, _address: &Address, _connection: &UpEndConnection) -> Result { Ok(true) } fn insert_info( &self, address: &Address, connection: &UpEndConnection, job_container: Arc>, ) -> Result { if self.is_needed(address, connection)? { let entries = self.get(address, connection, job_container)?; connection.transaction(|| { let len = entries.len(); for entry in entries { connection.insert_entry(entry)?; } Ok(len) }) } else { Ok(0) } } } pub fn extract_all( address: &Address, connection: &UpEndConnection, job_container: Arc>, ) -> Result { let mut entry_count = 0; #[cfg(feature = "extractors-web")] { entry_count += web::WebExtractor.insert_info(address, connection, job_container.clone())?; } #[cfg(feature = "extractors-audio")] { entry_count += audio::ID3Extractor.insert_info(address, connection, job_container)?; } Ok(entry_count) }