mirror of
https://github.com/markuryy/shark.git
synced 2025-12-12 19:51:01 +00:00
137 lines
5.0 KiB
Rust
137 lines
5.0 KiB
Rust
use tauri_plugin_sql::{Migration, MigrationKind};
|
|
|
|
mod tagger;
|
|
|
|
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
|
#[tauri::command]
|
|
fn greet(name: &str) -> String {
|
|
format!("Hello, {}! You've been greeted from Rust!", name)
|
|
}
|
|
|
|
/// Tag an audio file with metadata, cover art, and lyrics
|
|
#[tauri::command]
|
|
fn tag_audio_file(
|
|
path: String,
|
|
metadata: tagger::TaggingMetadata,
|
|
cover_data: Option<Vec<u8>>,
|
|
embed_lyrics: bool,
|
|
) -> Result<(), String> {
|
|
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: "
|
|
CREATE TABLE IF NOT EXISTS artists (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL,
|
|
path TEXT NOT NULL UNIQUE,
|
|
album_count INTEGER DEFAULT 0,
|
|
track_count INTEGER DEFAULT 0,
|
|
primary_cover_path TEXT,
|
|
last_scanned INTEGER,
|
|
created_at INTEGER DEFAULT (strftime('%s', 'now'))
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS albums (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
artist_id INTEGER NOT NULL,
|
|
artist_name TEXT NOT NULL,
|
|
title TEXT NOT NULL,
|
|
path TEXT NOT NULL UNIQUE,
|
|
cover_path TEXT,
|
|
track_count INTEGER DEFAULT 0,
|
|
year INTEGER,
|
|
last_scanned INTEGER,
|
|
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
FOREIGN KEY (artist_id) REFERENCES artists(id) ON DELETE CASCADE
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_artists_name ON artists(name);
|
|
CREATE INDEX IF NOT EXISTS idx_albums_artist_id ON albums(artist_id);
|
|
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,
|
|
}
|
|
];
|
|
|
|
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,
|
|
nb_tracks INTEGER DEFAULT 0,
|
|
creator_name TEXT,
|
|
picture_small TEXT,
|
|
picture_medium TEXT,
|
|
cached_at INTEGER NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS deezer_albums (
|
|
id TEXT PRIMARY KEY,
|
|
title TEXT NOT NULL,
|
|
artist_name TEXT NOT NULL,
|
|
nb_tracks INTEGER DEFAULT 0,
|
|
release_date TEXT,
|
|
picture_small TEXT,
|
|
picture_medium TEXT,
|
|
cached_at INTEGER NOT NULL
|
|
);
|
|
|
|
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
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS deezer_tracks (
|
|
id TEXT PRIMARY KEY,
|
|
title TEXT NOT NULL,
|
|
artist_name TEXT NOT NULL,
|
|
album_title TEXT,
|
|
duration INTEGER DEFAULT 0,
|
|
cached_at INTEGER NOT NULL
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_deezer_playlists_title ON deezer_playlists(title);
|
|
CREATE INDEX IF NOT EXISTS idx_deezer_albums_artist ON deezer_albums(artist_name);
|
|
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,
|
|
}
|
|
];
|
|
|
|
tauri::Builder::default()
|
|
.plugin(
|
|
tauri_plugin_sql::Builder::new()
|
|
.add_migrations("sqlite:library.db", library_migrations)
|
|
.add_migrations("sqlite:deezer.db", deezer_migrations)
|
|
.build()
|
|
)
|
|
.plugin(tauri_plugin_http::init())
|
|
.plugin(tauri_plugin_opener::init())
|
|
.plugin(tauri_plugin_store::Builder::new().build())
|
|
.plugin(tauri_plugin_dialog::init())
|
|
.plugin(tauri_plugin_fs::init())
|
|
.invoke_handler(tauri::generate_handler![greet, tag_audio_file])
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|