fix: log probe error

This commit is contained in:
kieran 2025-01-27 22:11:58 +00:00
parent 9f78c1a54f
commit f3989ba244
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
2 changed files with 41 additions and 38 deletions

View File

@ -1,7 +1,7 @@
use crate::analytics::Analytics;
use crate::settings::Settings;
use anyhow::Error;
use log::{info, warn};
use log::{debug, warn};
use nostr::serde_json;
use reqwest::ClientBuilder;
use rocket::Request;
@ -61,7 +61,7 @@ impl PlausibleAnalytics {
.send()
.await
{
Ok(_v) => info!("Sent {:?}", msg),
Ok(_v) => debug!("Sent {:?}", msg),
Err(e) => warn!("Failed to track: {}", e),
}
}

View File

@ -22,41 +22,44 @@ impl MediaMetadata {
for file in to_migrate {
// probe file and update metadata
let path = self.fs.get(&file.id);
if let Ok(data) = probe_file(&path) {
let bv = data.best_video();
let duration = if data.duration < 0.0 {
None
} else {
Some(data.duration)
};
let bitrate = if data.bitrate == 0 {
None
} else {
Some(data.bitrate as u32)
};
info!(
"Updating metadata: id={}, dim={}x{}, dur={}, br={}",
hex::encode(&file.id),
bv.map(|v| v.width).unwrap_or(0),
bv.map(|v| v.height).unwrap_or(0),
duration.unwrap_or(0.0),
bitrate.unwrap_or(0)
);
if let Err(e) = self
.db
.update_metadata(
&file.id,
bv.map(|v| v.width as u32),
bv.map(|v| v.height as u32),
duration,
bitrate,
)
.await
{
error!("Failed to update metadata: {}", e);
match probe_file(&path) {
Ok(data) => {
let bv = data.best_video();
let duration = if data.duration < 0.0 {
None
} else {
Some(data.duration)
};
let bitrate = if data.bitrate == 0 {
None
} else {
Some(data.bitrate as u32)
};
info!(
"Updating metadata: id={}, dim={}x{}, dur={}, br={}",
hex::encode(&file.id),
bv.map(|v| v.width).unwrap_or(0),
bv.map(|v| v.height).unwrap_or(0),
duration.unwrap_or(0.0),
bitrate.unwrap_or(0)
);
if let Err(e) = self
.db
.update_metadata(
&file.id,
bv.map(|v| v.width as u32),
bv.map(|v| v.height as u32),
duration,
bitrate,
)
.await
{
error!("Failed to update metadata: {}", e);
}
}
Err(e) => {
warn!("Skipping missing file: {}, {}", hex::encode(&file.id), e);
}
} else {
warn!("Skipping missing file: {}", hex::encode(&file.id));
}
}
Ok(())
@ -66,8 +69,8 @@ impl MediaMetadata {
impl Database {
pub async fn get_missing_media_metadata(&mut self) -> Result<Vec<FileUpload>> {
let results: Vec<FileUpload> = sqlx::query_as("select * from uploads where (width is null or height is null or bitrate is null or duration is null) and (mime_type like 'image/%' or mime_type like 'video/%')")
.fetch_all(&self.pool)
.await?;
.fetch_all(&self.pool)
.await?;
Ok(results)
}