mirror of
https://github.com/markuryy/shark.git
synced 2025-12-12 11:41: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:
11
src-tauri/Cargo.lock
generated
11
src-tauri/Cargo.lock
generated
@@ -16,6 +16,7 @@ dependencies = [
|
||||
"tauri-plugin-fs",
|
||||
"tauri-plugin-http",
|
||||
"tauri-plugin-opener",
|
||||
"tauri-plugin-process",
|
||||
"tauri-plugin-sql",
|
||||
"tauri-plugin-store",
|
||||
]
|
||||
@@ -4750,6 +4751,16 @@ dependencies = [
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-process"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7461c622a5ea00eb9cd9f7a08dbd3bf79484499fd5c21aa2964677f64ca651ab"
|
||||
dependencies = [
|
||||
"tauri",
|
||||
"tauri-plugin",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-sql"
|
||||
version = "2.3.0"
|
||||
|
||||
@@ -29,4 +29,5 @@ tauri-plugin-http = { version = "2", features = ["unsafe-headers"] }
|
||||
tauri-plugin-sql = { version = "2", features = ["sqlite"] }
|
||||
id3 = "1.16.3"
|
||||
metaflac = "0.2.8"
|
||||
tauri-plugin-process = "2"
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
]
|
||||
},
|
||||
"sql:default",
|
||||
"sql:allow-execute"
|
||||
"sql:allow-execute",
|
||||
"process:default"
|
||||
]
|
||||
}
|
||||
@@ -16,21 +16,15 @@ fn tag_audio_file(
|
||||
cover_data: Option<Vec<u8>>,
|
||||
embed_lyrics: bool,
|
||||
) -> Result<(), String> {
|
||||
tagger::tag_audio_file(
|
||||
&path,
|
||||
&metadata,
|
||||
cover_data.as_deref(),
|
||||
embed_lyrics,
|
||||
)
|
||||
tagger::tag_audio_file(&path, &metadata, cover_data.as_deref(), embed_lyrics)
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let library_migrations = vec![
|
||||
Migration {
|
||||
version: 1,
|
||||
description: "create_library_tables",
|
||||
sql: "
|
||||
let library_migrations = vec![Migration {
|
||||
version: 1,
|
||||
description: "create_library_tables",
|
||||
sql: "
|
||||
CREATE TABLE IF NOT EXISTS artists (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
@@ -61,15 +55,13 @@ pub fn run() {
|
||||
CREATE INDEX IF NOT EXISTS idx_albums_year ON albums(year);
|
||||
CREATE INDEX IF NOT EXISTS idx_albums_artist_title ON albums(artist_name, title);
|
||||
",
|
||||
kind: MigrationKind::Up,
|
||||
}
|
||||
];
|
||||
kind: MigrationKind::Up,
|
||||
}];
|
||||
|
||||
let deezer_migrations = vec![
|
||||
Migration {
|
||||
version: 1,
|
||||
description: "create_deezer_cache_tables",
|
||||
sql: "
|
||||
let deezer_migrations = vec![Migration {
|
||||
version: 1,
|
||||
description: "create_deezer_cache_tables",
|
||||
sql: "
|
||||
CREATE TABLE IF NOT EXISTS deezer_playlists (
|
||||
id TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
@@ -94,7 +86,6 @@ pub fn run() {
|
||||
CREATE TABLE IF NOT EXISTS deezer_artists (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
nb_album INTEGER DEFAULT 0,
|
||||
picture_small TEXT,
|
||||
picture_medium TEXT,
|
||||
cached_at INTEGER NOT NULL
|
||||
@@ -114,16 +105,16 @@ pub fn run() {
|
||||
CREATE INDEX IF NOT EXISTS idx_deezer_artists_name ON deezer_artists(name);
|
||||
CREATE INDEX IF NOT EXISTS idx_deezer_tracks_title ON deezer_tracks(title);
|
||||
",
|
||||
kind: MigrationKind::Up,
|
||||
}
|
||||
];
|
||||
kind: MigrationKind::Up,
|
||||
}];
|
||||
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(
|
||||
tauri_plugin_sql::Builder::new()
|
||||
.add_migrations("sqlite:library.db", library_migrations)
|
||||
.add_migrations("sqlite:deezer.db", deezer_migrations)
|
||||
.build()
|
||||
.build(),
|
||||
)
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
|
||||
@@ -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