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

View File

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