mirror of
https://github.com/markuryy/shark.git
synced 2025-12-14 20:31:02 +00:00
feat(dz): add cache clearing and database reset functionality
Add ability to fully clear cached online library by deleting and recreating the database file. Integrate new Clear Cache option in settings UI, which restarts the app after clearing. Remove unused artist/album fields from cache and UI. Add process plugin for relaunch.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use id3::{Tag as ID3Tag, TagLike, Version, frame::{Picture, PictureType}};
|
||||
use id3::{
|
||||
frame::{Picture, PictureType},
|
||||
Tag as ID3Tag, TagLike, Version,
|
||||
};
|
||||
use metaflac::Tag as FlacTag;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::Path;
|
||||
@@ -60,8 +63,7 @@ fn tag_mp3(
|
||||
embed_lyrics: bool,
|
||||
) -> Result<(), String> {
|
||||
// Read or create tag
|
||||
let mut tag = ID3Tag::read_from_path(path)
|
||||
.unwrap_or_else(|_| ID3Tag::new());
|
||||
let mut tag = ID3Tag::read_from_path(path).unwrap_or_else(|_| ID3Tag::new());
|
||||
|
||||
// Basic metadata
|
||||
if let Some(ref title) = metadata.title {
|
||||
@@ -129,57 +131,75 @@ fn tag_mp3(
|
||||
|
||||
// Custom text frames (TXXX)
|
||||
if let Some(ref barcode) = metadata.barcode {
|
||||
use id3::frame::{ExtendedText, Content};
|
||||
use id3::frame::{Content, ExtendedText};
|
||||
let ext_text = ExtendedText {
|
||||
description: "BARCODE".to_string(),
|
||||
value: barcode.clone(),
|
||||
};
|
||||
tag.add_frame(id3::frame::Frame::with_content("TXXX", Content::ExtendedText(ext_text)));
|
||||
tag.add_frame(id3::frame::Frame::with_content(
|
||||
"TXXX",
|
||||
Content::ExtendedText(ext_text),
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(explicit) = metadata.explicit {
|
||||
use id3::frame::{ExtendedText, Content};
|
||||
use id3::frame::{Content, ExtendedText};
|
||||
let ext_text = ExtendedText {
|
||||
description: "ITUNESADVISORY".to_string(),
|
||||
value: if explicit { "1" } else { "0" }.to_string(),
|
||||
};
|
||||
tag.add_frame(id3::frame::Frame::with_content("TXXX", Content::ExtendedText(ext_text)));
|
||||
tag.add_frame(id3::frame::Frame::with_content(
|
||||
"TXXX",
|
||||
Content::ExtendedText(ext_text),
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(ref replay_gain) = metadata.replay_gain {
|
||||
use id3::frame::{ExtendedText, Content};
|
||||
use id3::frame::{Content, ExtendedText};
|
||||
let ext_text = ExtendedText {
|
||||
description: "REPLAYGAIN_TRACK_GAIN".to_string(),
|
||||
value: replay_gain.clone(),
|
||||
};
|
||||
tag.add_frame(id3::frame::Frame::with_content("TXXX", Content::ExtendedText(ext_text)));
|
||||
tag.add_frame(id3::frame::Frame::with_content(
|
||||
"TXXX",
|
||||
Content::ExtendedText(ext_text),
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(ref source_id) = metadata.source_id {
|
||||
use id3::frame::{ExtendedText, Content};
|
||||
use id3::frame::{Content, ExtendedText};
|
||||
let source_text = ExtendedText {
|
||||
description: "SOURCE".to_string(),
|
||||
value: "Deezer".to_string(),
|
||||
};
|
||||
tag.add_frame(id3::frame::Frame::with_content("TXXX", Content::ExtendedText(source_text)));
|
||||
tag.add_frame(id3::frame::Frame::with_content(
|
||||
"TXXX",
|
||||
Content::ExtendedText(source_text),
|
||||
));
|
||||
|
||||
let sourceid_text = ExtendedText {
|
||||
description: "SOURCEID".to_string(),
|
||||
value: source_id.clone(),
|
||||
};
|
||||
tag.add_frame(id3::frame::Frame::with_content("TXXX", Content::ExtendedText(sourceid_text)));
|
||||
tag.add_frame(id3::frame::Frame::with_content(
|
||||
"TXXX",
|
||||
Content::ExtendedText(sourceid_text),
|
||||
));
|
||||
}
|
||||
|
||||
// Lyrics (USLT frame)
|
||||
if embed_lyrics {
|
||||
if let Some(ref lyrics) = metadata.lyrics_unsync {
|
||||
use id3::frame::{Lyrics, Content};
|
||||
use id3::frame::{Content, Lyrics};
|
||||
let lyrics_frame = Lyrics {
|
||||
lang: "eng".to_string(),
|
||||
description: String::new(),
|
||||
text: lyrics.clone(),
|
||||
};
|
||||
tag.add_frame(id3::frame::Frame::with_content("USLT", Content::Lyrics(lyrics_frame)));
|
||||
tag.add_frame(id3::frame::Frame::with_content(
|
||||
"USLT",
|
||||
Content::Lyrics(lyrics_frame),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +213,10 @@ fn tag_mp3(
|
||||
description: "Cover".to_string(),
|
||||
data: cover_bytes.to_vec(),
|
||||
};
|
||||
tag.add_frame(id3::frame::Frame::with_content("APIC", id3::frame::Content::Picture(picture)));
|
||||
tag.add_frame(id3::frame::Frame::with_content(
|
||||
"APIC",
|
||||
id3::frame::Content::Picture(picture),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,8 +232,8 @@ fn tag_flac(
|
||||
cover_data: Option<&[u8]>,
|
||||
embed_lyrics: bool,
|
||||
) -> Result<(), String> {
|
||||
let mut tag = FlacTag::read_from_path(path)
|
||||
.map_err(|e| format!("Failed to read FLAC file: {}", e))?;
|
||||
let mut tag =
|
||||
FlacTag::read_from_path(path).map_err(|e| format!("Failed to read FLAC file: {}", e))?;
|
||||
|
||||
// Remove all existing vorbis comments to start fresh
|
||||
let vorbis = tag.vorbis_comments_mut();
|
||||
@@ -279,7 +302,10 @@ fn tag_flac(
|
||||
}
|
||||
|
||||
if let Some(explicit) = metadata.explicit {
|
||||
tag.set_vorbis("ITUNESADVISORY", vec![if explicit { "1" } else { "0" }.to_string()]);
|
||||
tag.set_vorbis(
|
||||
"ITUNESADVISORY",
|
||||
vec![if explicit { "1" } else { "0" }.to_string()],
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(ref replay_gain) = metadata.replay_gain {
|
||||
@@ -303,7 +329,11 @@ fn tag_flac(
|
||||
if !cover_bytes.is_empty() {
|
||||
let mime_type = detect_mime_type_str(cover_bytes);
|
||||
tag.remove_picture_type(metaflac::block::PictureType::CoverFront);
|
||||
tag.add_picture(mime_type, metaflac::block::PictureType::CoverFront, cover_bytes.to_vec());
|
||||
tag.add_picture(
|
||||
mime_type,
|
||||
metaflac::block::PictureType::CoverFront,
|
||||
cover_bytes.to_vec(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user