fix: update lofty 0.18 API calls to lofty 0.23
- Imports reorganized: use lofty::prelude::*, lofty::tag::*, lofty::picture::*
- Picture::new_unchecked -> Picture::unchecked().pic_type().mime_type().build()
- set_year/remove_year -> set_date/remove_date with Timestamp
- ItemKey::Unknown("ISRC") -> ItemKey::Isrc
- save_to_path(path) -> save_to_path(path, WriteOptions::default())
- get_string/remove_key now take ItemKey by value
- Bump qbz-library crate lofty dep to 0.23
cc
This commit is contained in:
7 files changed
+40
-29
No files matched your search
@@ -24,7 +24,7 @@ walkdir = "2"
|
||||
dirs = "5"
|
||||
|
||||
# Audio metadata
|
||||
lofty = "0.18"
|
||||
lofty = "0.23"
|
||||
|
||||
# Image processing (thumbnails)
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp"] }
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//! Metadata extraction for audio files
|
||||
|
||||
use lofty::{Accessor, AudioFile, ItemKey, Probe, TaggedFileExt};
|
||||
use lofty::prelude::*;
|
||||
use lofty::probe::Probe;
|
||||
use lofty::tag::ItemKey;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
@@ -452,7 +454,7 @@ impl MetadataExtractor {
|
||||
.or_else(|| fallback_artist.clone())
|
||||
.unwrap_or_else(|| "Unknown Artist".to_string()),
|
||||
album: album_title,
|
||||
album_artist: tag.get_string(&ItemKey::AlbumArtist).map(|s| s.to_string()),
|
||||
album_artist: tag.get_string(ItemKey::AlbumArtist).map(|s| s.to_string()),
|
||||
album_group_key,
|
||||
album_group_title,
|
||||
track_number: tag
|
||||
@@ -463,10 +465,10 @@ impl MetadataExtractor {
|
||||
.disk()
|
||||
.and_then(|d| if d > 0 { Some(d as u32) } else { None })
|
||||
.or(inferred_disc),
|
||||
year: tag.year().map(|y| y as u32),
|
||||
year: tag.date().map(|ts| ts.year as u32),
|
||||
genre: tag.genre().map(|s| s.to_string()),
|
||||
catalog_number: tag
|
||||
.get_string(&ItemKey::CatalogNumber)
|
||||
.get_string(ItemKey::CatalogNumber)
|
||||
.map(|s| s.to_string()),
|
||||
duration_secs,
|
||||
format,
|
||||
|
||||
@@ -11902,7 +11902,7 @@ fn spawn_track_cache_download(
|
||||
let (bit_depth_detected, sample_rate_detected) =
|
||||
match lofty::read_from_path(&new_path) {
|
||||
Ok(tagged_file) => {
|
||||
use lofty::AudioFile;
|
||||
use lofty::prelude::*;
|
||||
let properties = tagged_file.properties();
|
||||
(
|
||||
properties.bit_depth().map(|bd| bd as u32),
|
||||
|
||||
@@ -2247,7 +2247,9 @@ pub async fn library_write_album_metadata_to_files_impl(
|
||||
let write_result = tokio::task::spawn_blocking({
|
||||
let request = request.clone();
|
||||
move || -> Result<(), String> {
|
||||
use lofty::{Accessor, AudioFile, ItemKey, Tag, TaggedFileExt};
|
||||
use lofty::prelude::*;
|
||||
use lofty::tag::{ItemKey, Tag};
|
||||
use lofty::config::WriteOptions;
|
||||
|
||||
// Ensure we only write each file once.
|
||||
let mut by_file: HashMap<String, &LibraryAlbumTrackMetadataUpdate> = HashMap::new();
|
||||
@@ -2300,16 +2302,19 @@ pub async fn library_write_album_metadata_to_files_impl(
|
||||
|
||||
// Album artist (not part of Accessor).
|
||||
if request.album_artist.trim().is_empty() {
|
||||
tag.remove_key(&ItemKey::AlbumArtist);
|
||||
tag.remove_key(ItemKey::AlbumArtist);
|
||||
} else {
|
||||
tag.insert_text(ItemKey::AlbumArtist, request.album_artist.trim().to_string());
|
||||
}
|
||||
|
||||
// Year / Genre
|
||||
if let Some(year) = request.year {
|
||||
tag.set_year(year);
|
||||
tag.set_date(lofty::tag::items::Timestamp {
|
||||
year: year as u16,
|
||||
..Default::default()
|
||||
});
|
||||
} else {
|
||||
tag.remove_year();
|
||||
tag.remove_date();
|
||||
}
|
||||
|
||||
if let Some(ref genre) = request.genre {
|
||||
@@ -2326,17 +2331,17 @@ pub async fn library_write_album_metadata_to_files_impl(
|
||||
if let Some(ref cat) = request.catalog_number {
|
||||
let c = cat.trim();
|
||||
if c.is_empty() {
|
||||
tag.remove_key(&ItemKey::CatalogNumber);
|
||||
tag.remove_key(ItemKey::CatalogNumber);
|
||||
} else {
|
||||
tag.insert_text(ItemKey::CatalogNumber, c.to_string());
|
||||
}
|
||||
} else {
|
||||
tag.remove_key(&ItemKey::CatalogNumber);
|
||||
tag.remove_key(ItemKey::CatalogNumber);
|
||||
}
|
||||
}
|
||||
|
||||
tagged_file
|
||||
.save_to_path(path)
|
||||
.save_to_path(path, WriteOptions::default())
|
||||
.map_err(|_| "Failed to write tags to audio files. Check that the album folder is mounted read-write and you have permissions.".to_string())?;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ async fn post_process_cached_track(
|
||||
};
|
||||
|
||||
// 6. Extract audio properties from FLAC file
|
||||
use lofty::AudioFile;
|
||||
use lofty::prelude::*;
|
||||
let (bit_depth, sample_rate) = match lofty::read_from_path(&new_path) {
|
||||
Ok(tagged_file) => {
|
||||
let properties = tagged_file.properties();
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
//!
|
||||
//! Handles complete metadata retrieval from Qobuz API and writing to FLAC tags.
|
||||
|
||||
use lofty::{Accessor, AudioFile, ItemKey, Picture, PictureType, Tag, TagExt, TaggedFileExt};
|
||||
use lofty::config::WriteOptions;
|
||||
use lofty::picture::{MimeType, Picture, PictureType};
|
||||
use lofty::prelude::*;
|
||||
use lofty::tag::{ItemKey, Tag};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::Path;
|
||||
|
||||
@@ -139,7 +142,10 @@ pub fn write_flac_tags(file_path: &str, metadata: &CompleteTrackMetadata) -> Res
|
||||
}
|
||||
|
||||
if let Some(year) = metadata.year {
|
||||
tag.set_year(year);
|
||||
tag.set_date(lofty::tag::items::Timestamp {
|
||||
year: year as u16,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(genre) = &metadata.genre {
|
||||
@@ -147,7 +153,7 @@ pub fn write_flac_tags(file_path: &str, metadata: &CompleteTrackMetadata) -> Res
|
||||
}
|
||||
|
||||
if let Some(isrc) = &metadata.isrc {
|
||||
tag.insert_text(ItemKey::Unknown("ISRC".to_string()), isrc.clone());
|
||||
tag.insert_text(ItemKey::Isrc, isrc.clone());
|
||||
}
|
||||
|
||||
if let Some(label) = &metadata.label {
|
||||
@@ -164,7 +170,7 @@ pub fn write_flac_tags(file_path: &str, metadata: &CompleteTrackMetadata) -> Res
|
||||
|
||||
// Save tags
|
||||
tagged_file
|
||||
.save_to_path(path)
|
||||
.save_to_path(path, WriteOptions::default())
|
||||
.map_err(|e| format!("Failed to save tags: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
@@ -186,20 +192,18 @@ pub async fn embed_artwork(file_path: &str, artwork_url: &str) -> Result<(), Str
|
||||
|
||||
// Determine MIME type from URL
|
||||
let mime_type = if artwork_url.contains(".jpg") || artwork_url.contains(".jpeg") {
|
||||
lofty::MimeType::Jpeg
|
||||
MimeType::Jpeg
|
||||
} else if artwork_url.contains(".png") {
|
||||
lofty::MimeType::Png
|
||||
MimeType::Png
|
||||
} else {
|
||||
lofty::MimeType::Jpeg // Default to JPEG
|
||||
MimeType::Jpeg // Default to JPEG
|
||||
};
|
||||
|
||||
// Create picture
|
||||
let picture = Picture::new_unchecked(
|
||||
PictureType::CoverFront,
|
||||
Some(mime_type),
|
||||
None,
|
||||
artwork_bytes.to_vec(),
|
||||
);
|
||||
let picture = Picture::unchecked(artwork_bytes.to_vec())
|
||||
.pic_type(PictureType::CoverFront)
|
||||
.mime_type(mime_type)
|
||||
.build();
|
||||
|
||||
// Read file
|
||||
let path = Path::new(file_path);
|
||||
@@ -218,7 +222,7 @@ pub async fn embed_artwork(file_path: &str, artwork_url: &str) -> Result<(), Str
|
||||
|
||||
// Save
|
||||
tagged_file
|
||||
.save_to_path(path)
|
||||
.save_to_path(path, WriteOptions::default())
|
||||
.map_err(|e| format!("Failed to save artwork: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -119,7 +119,7 @@ async fn migrate_single_track(
|
||||
};
|
||||
|
||||
// 6. Extract audio properties from FLAC file
|
||||
use lofty::AudioFile;
|
||||
use lofty::prelude::*;
|
||||
let (bit_depth, sample_rate) = match lofty::read_from_path(&new_path) {
|
||||
Ok(tagged_file) => {
|
||||
let properties = tagged_file.properties();
|
||||
|
||||
Reference in new issue
Block a user