feat(cli): add ID3 image extraction
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
parent
7a59f81fb4
commit
8917221b42
|
@ -1,3 +1,4 @@
|
||||||
|
use std::io::Write;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use super::Extractor;
|
use super::Extractor;
|
||||||
|
@ -8,10 +9,11 @@ use upend_base::{
|
||||||
constants::{ATTR_IN, ATTR_KEY, ATTR_LABEL, ATTR_OF},
|
constants::{ATTR_IN, ATTR_KEY, ATTR_LABEL, ATTR_OF},
|
||||||
entry::{Entry, EntryValue, InvariantEntry},
|
entry::{Entry, EntryValue, InvariantEntry},
|
||||||
};
|
};
|
||||||
|
use upend_db::stores::Blob;
|
||||||
use upend_db::{
|
use upend_db::{
|
||||||
jobs::{JobContainer, JobState},
|
jobs::{JobContainer, JobState},
|
||||||
stores::{fs::FILE_MIME_KEY, UpStore},
|
stores::{fs::FILE_MIME_KEY, UpStore},
|
||||||
UpEndConnection,
|
BlobMode, UpEndConnection,
|
||||||
};
|
};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -33,7 +35,7 @@ impl Extractor for ID3Extractor {
|
||||||
fn get(
|
fn get(
|
||||||
&self,
|
&self,
|
||||||
address: &Address,
|
address: &Address,
|
||||||
_connection: &UpEndConnection,
|
connection: &UpEndConnection,
|
||||||
store: Arc<Box<dyn UpStore + Send + Sync>>,
|
store: Arc<Box<dyn UpStore + Send + Sync>>,
|
||||||
mut job_container: JobContainer,
|
mut job_container: JobContainer,
|
||||||
) -> Result<Vec<Entry>> {
|
) -> Result<Vec<Entry>> {
|
||||||
|
@ -83,6 +85,26 @@ impl Extractor for ID3Extractor {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
for (idx, picture) in tags.pictures().enumerate() {
|
||||||
|
let tmp_dir = tempfile::tempdir()?;
|
||||||
|
let tmp_path = tmp_dir.path().join(format!("img-{}", idx));
|
||||||
|
let mut file = std::fs::File::create(&tmp_path)?;
|
||||||
|
file.write_all(&*picture.data)?;
|
||||||
|
let hash = store.store(
|
||||||
|
connection,
|
||||||
|
Blob::from_filepath(&tmp_path),
|
||||||
|
None,
|
||||||
|
Some(BlobMode::StoreOnly),
|
||||||
|
)?;
|
||||||
|
result.push(Entry {
|
||||||
|
entity: address.clone(),
|
||||||
|
attribute: "ID3_PICTURE".to_string(),
|
||||||
|
value: EntryValue::Address(Address::Hash(hash)),
|
||||||
|
provenance: "SYSTEM EXTRACTOR".to_string(),
|
||||||
|
timestamp: chrono::Utc::now().naive_utc(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if !result.is_empty() {
|
if !result.is_empty() {
|
||||||
result.extend(
|
result.extend(
|
||||||
result
|
result
|
||||||
|
|
|
@ -559,7 +559,7 @@ pub async fn put_blob(
|
||||||
let options = connection.get_vault_options()?;
|
let options = connection.get_vault_options()?;
|
||||||
_store
|
_store
|
||||||
.store(
|
.store(
|
||||||
connection,
|
&connection,
|
||||||
Blob::from_filepath(file.path()),
|
Blob::from_filepath(file.path()),
|
||||||
_filename,
|
_filename,
|
||||||
options.blob_mode,
|
options.blob_mode,
|
||||||
|
|
|
@ -645,7 +645,7 @@ impl UpStore for FsStore {
|
||||||
|
|
||||||
fn store(
|
fn store(
|
||||||
&self,
|
&self,
|
||||||
connection: UpEndConnection,
|
connection: &UpEndConnection,
|
||||||
blob: Blob,
|
blob: Blob,
|
||||||
name_hint: Option<String>,
|
name_hint: Option<String>,
|
||||||
blob_mode: Option<BlobMode>,
|
blob_mode: Option<BlobMode>,
|
||||||
|
@ -694,7 +694,7 @@ impl UpStore for FsStore {
|
||||||
.flatten();
|
.flatten();
|
||||||
|
|
||||||
self.insert_file_with_metadata(
|
self.insert_file_with_metadata(
|
||||||
&connection,
|
connection,
|
||||||
&final_path,
|
&final_path,
|
||||||
upath,
|
upath,
|
||||||
hash.clone(),
|
hash.clone(),
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub trait UpStore {
|
||||||
fn retrieve_all(&self) -> Result<Vec<Blob>>;
|
fn retrieve_all(&self) -> Result<Vec<Blob>>;
|
||||||
fn store(
|
fn store(
|
||||||
&self,
|
&self,
|
||||||
connection: UpEndConnection,
|
connection: &UpEndConnection,
|
||||||
blob: Blob,
|
blob: Blob,
|
||||||
name_hint: Option<String>,
|
name_hint: Option<String>,
|
||||||
blob_mode: Option<BlobMode>,
|
blob_mode: Option<BlobMode>,
|
||||||
|
|
Loading…
Reference in New Issue