diff --git a/.gitignore b/.gitignore index 5f32e70..9f97022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -target/ -.env \ No newline at end of file +target/ \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 4cc5eb2..0b341ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -325,39 +325,6 @@ dependencies = [ "powerfmt", ] -[[package]] -name = "diesel" -version = "2.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04001f23ba8843dc315804fa324000376084dfb1c30794ff68dd279e6e5696d5" -dependencies = [ - "diesel_derives", - "libsqlite3-sys", - "time", -] - -[[package]] -name = "diesel_derives" -version = "2.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f2c3de51e2ba6bf2a648285696137aaf0f5f487bcbea93972fe8a364e131a4" -dependencies = [ - "diesel_table_macro_syntax", - "dsl_auto_type", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "diesel_table_macro_syntax" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" -dependencies = [ - "syn", -] - [[package]] name = "dirs" version = "6.0.0" @@ -390,26 +357,6 @@ dependencies = [ "syn", ] -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - -[[package]] -name = "dsl_auto_type" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "139ae9aca7527f85f26dd76483eb38533fd84bd571065da1739656ef71c5ff5b" -dependencies = [ - "darling", - "either", - "heck", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "either" version = "1.13.0" @@ -1081,16 +1028,6 @@ dependencies = [ "libc", ] -[[package]] -name = "libsqlite3-sys" -version = "0.31.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad8935b44e7c13394a179a438e0cebba0fe08fe01b54f152e29a93b5cf993fd4" -dependencies = [ - "pkg-config", - "vcpkg", -] - [[package]] name = "libusb1-sys" version = "0.7.0" @@ -1144,17 +1081,17 @@ dependencies = [ name = "lyrica" version = "0.1.0" dependencies = [ + "bincode", "chrono", "color-eyre", "color-thief", "crossterm", - "diesel", "dirs", - "dotenvy", "futures", "itunesdb", "libmath", "ratatui", + "redb", "regex", "rusb", "serde", @@ -1506,6 +1443,15 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "redb" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea0a72cd7140de9fc3e318823b883abf819c20d478ec89ce880466dc2ef263c6" +dependencies = [ + "libc", +] + [[package]] name = "redox_syscall" version = "0.5.8" @@ -2065,14 +2011,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" dependencies = [ "deranged", - "itoa", "libc", "num-conv", "num_threads", "powerfmt", "serde", "time-core", - "time-macros", ] [[package]] @@ -2081,16 +2025,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" -[[package]] -name = "time-macros" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" -dependencies = [ - "num-conv", - "time-core", -] - [[package]] name = "tinystr" version = "0.7.6" diff --git a/Cargo.toml b/Cargo.toml index 847c62d..d5eecf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ dirs = "6.0.0" toml = "0.8.20" serde = "1.0.217" serde_json = "1.0" +bincode = "1.3.3" regex = "1.11.1" libmath = "0.2.1" ratatui = { version = "0.29.0", features = ["all-widgets"] } @@ -25,5 +26,4 @@ soundcloud = { version = "0.1.4", git = "https://gitea.awain.net/alterwain/sound itunesdb = { version = "0.1.1", git = "https://gitea.awain.net/alterwain/ITunesDB.git" } ureq = "3.0.5" color-thief = "0.2" -diesel = { version = "2.2.7", features = ["sqlite", "returning_clauses_for_sqlite_3_35"] } -dotenvy = "0.15" \ No newline at end of file +redb = "2.4.0" diff --git a/src/config.rs b/src/config.rs index 8021ce0..30f6cd6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,25 +27,34 @@ pub fn get_temp_itunesdb() -> PathBuf { p } +pub fn get_db() -> PathBuf { + let mut p = get_configs_dir(); + p.push("data.redb"); + p +} + #[derive(Debug, Deserialize, Serialize)] pub struct YouTubeConfiguration { - pub user_id: u64 + pub user_id: u64, } #[derive(Debug, Deserialize, Serialize)] pub struct SoundCloudConfiguration { - pub user_id: u64 + pub user_id: u64, } #[derive(Debug, Deserialize, Serialize)] pub struct LyricaConfiguration { soundcloud: SoundCloudConfiguration, - youtube: YouTubeConfiguration + youtube: YouTubeConfiguration, } impl Default for LyricaConfiguration { fn default() -> Self { - Self { soundcloud: SoundCloudConfiguration { user_id: 0 }, youtube: YouTubeConfiguration { user_id: 0 } } + Self { + soundcloud: SoundCloudConfiguration { user_id: 0 }, + youtube: YouTubeConfiguration { user_id: 0 }, + } } } @@ -57,4 +66,4 @@ impl LyricaConfiguration { pub fn get_youtube(&self) -> &YouTubeConfiguration { &self.youtube } -} \ No newline at end of file +} diff --git a/src/db.rs b/src/db.rs new file mode 100644 index 0000000..5b8c046 --- /dev/null +++ b/src/db.rs @@ -0,0 +1,54 @@ +use redb::{Database, Error, ReadableTable, TableDefinition}; +use serde::{Deserialize, Serialize}; + +use crate::config::get_db; + +const TRACKS: TableDefinition> = TableDefinition::new("tracks"); + +#[derive(Serialize, Deserialize)] +struct Track { + unique_id: u32, + filetype: u32, + stars: u8, + last_modified_time: u32, + size: u32, + length: u32, + year: u32, + bitrate: u32, + sample_rate: u32, + play_count: u32, + dbid: u64, + bpm: u16, + skip_count: u32, + has_artwork: u8, + media_type: u32, + title: String, + location: String, + album: String, + artist: String, + genre: String, +} + +fn init_db() -> Database { + Database::create(get_db()).unwrap() +} + +fn insert_track(db: &Database, track: Track) -> Result<(), Error> { + let write_txn = db.begin_write()?; + { + let mut table = write_txn.open_table(TRACKS)?; + let uid = track.unique_id; + let data = bincode::serialize(&track).unwrap(); + table.insert(uid, data)?; + } + write_txn.commit()?; + Ok(()) +} + +fn get_track(db: &Database, id: u32) -> Result { + let read_txn = db.begin_read()?; + let table = read_txn.open_table(TRACKS)?; + let b = table.get(id)?.unwrap().value(); + let track: Track = bincode::deserialize(&b).unwrap(); + Ok(track) +} diff --git a/src/main.rs b/src/main.rs index d219353..83b42c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,7 @@ use tokio_util::sync::CancellationToken; use wait_screen::WaitScreen; mod config; +mod db; mod dlp; mod main_screen; mod screen; diff --git a/src/sync.rs b/src/sync.rs index 51ddf6b..29e43d5 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -11,7 +11,8 @@ use tokio_util::sync::CancellationToken; use crate::{ config::{ - get_config_path, get_configs_dir, get_temp_dl_dir, get_temp_itunesdb, LyricaConfiguration, + get_config_path, get_configs_dir, get_temp_dl_dir, get_temp_itunesdb, + LyricaConfiguration, }, dlp::{self, DownloadProgress}, }; @@ -34,7 +35,10 @@ pub fn initialize_async_service( token: CancellationToken, ) { tokio::spawn(async move { + let _ = std::fs::create_dir_all(get_configs_dir()); + let mut receiver = receiver; + loop { tokio::select! { _ = token.cancelled() => { return; } @@ -51,7 +55,6 @@ pub fn initialize_async_service( }, AppEvent::ParseItunes(path) => { // todo: parse itunes - let _ = std::fs::create_dir_all(get_configs_dir()); let cd = get_temp_itunesdb(); let p: PathBuf = Path::new(&path).into(); // p.push("iPod_Control");