modified: .gitignore
modified: Cargo.lock modified: Cargo.toml modified: src/config.rs new file: src/db.rs modified: src/main.rs modified: src/sync.rs
This commit is contained in:
parent
8f8a79411b
commit
f6b8faa221
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
target/
|
target/
|
||||||
.env
|
|
88
Cargo.lock
generated
88
Cargo.lock
generated
@ -325,39 +325,6 @@ dependencies = [
|
|||||||
"powerfmt",
|
"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]]
|
[[package]]
|
||||||
name = "dirs"
|
name = "dirs"
|
||||||
version = "6.0.0"
|
version = "6.0.0"
|
||||||
@ -390,26 +357,6 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.13.0"
|
version = "1.13.0"
|
||||||
@ -1081,16 +1028,6 @@ dependencies = [
|
|||||||
"libc",
|
"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]]
|
[[package]]
|
||||||
name = "libusb1-sys"
|
name = "libusb1-sys"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@ -1144,17 +1081,17 @@ dependencies = [
|
|||||||
name = "lyrica"
|
name = "lyrica"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bincode",
|
||||||
"chrono",
|
"chrono",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"color-thief",
|
"color-thief",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"diesel",
|
|
||||||
"dirs",
|
"dirs",
|
||||||
"dotenvy",
|
|
||||||
"futures",
|
"futures",
|
||||||
"itunesdb",
|
"itunesdb",
|
||||||
"libmath",
|
"libmath",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
|
"redb",
|
||||||
"regex",
|
"regex",
|
||||||
"rusb",
|
"rusb",
|
||||||
"serde",
|
"serde",
|
||||||
@ -1506,6 +1443,15 @@ dependencies = [
|
|||||||
"rand_core 0.3.1",
|
"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]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.5.8"
|
version = "0.5.8"
|
||||||
@ -2065,14 +2011,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21"
|
checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"deranged",
|
"deranged",
|
||||||
"itoa",
|
|
||||||
"libc",
|
"libc",
|
||||||
"num-conv",
|
"num-conv",
|
||||||
"num_threads",
|
"num_threads",
|
||||||
"powerfmt",
|
"powerfmt",
|
||||||
"serde",
|
"serde",
|
||||||
"time-core",
|
"time-core",
|
||||||
"time-macros",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2081,16 +2025,6 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
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]]
|
[[package]]
|
||||||
name = "tinystr"
|
name = "tinystr"
|
||||||
version = "0.7.6"
|
version = "0.7.6"
|
||||||
|
@ -12,6 +12,7 @@ dirs = "6.0.0"
|
|||||||
toml = "0.8.20"
|
toml = "0.8.20"
|
||||||
serde = "1.0.217"
|
serde = "1.0.217"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
bincode = "1.3.3"
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
libmath = "0.2.1"
|
libmath = "0.2.1"
|
||||||
ratatui = { version = "0.29.0", features = ["all-widgets"] }
|
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" }
|
itunesdb = { version = "0.1.1", git = "https://gitea.awain.net/alterwain/ITunesDB.git" }
|
||||||
ureq = "3.0.5"
|
ureq = "3.0.5"
|
||||||
color-thief = "0.2"
|
color-thief = "0.2"
|
||||||
diesel = { version = "2.2.7", features = ["sqlite", "returning_clauses_for_sqlite_3_35"] }
|
redb = "2.4.0"
|
||||||
dotenvy = "0.15"
|
|
||||||
|
@ -27,25 +27,34 @@ pub fn get_temp_itunesdb() -> PathBuf {
|
|||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_db() -> PathBuf {
|
||||||
|
let mut p = get_configs_dir();
|
||||||
|
p.push("data.redb");
|
||||||
|
p
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct YouTubeConfiguration {
|
pub struct YouTubeConfiguration {
|
||||||
pub user_id: u64
|
pub user_id: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct SoundCloudConfiguration {
|
pub struct SoundCloudConfiguration {
|
||||||
pub user_id: u64
|
pub user_id: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct LyricaConfiguration {
|
pub struct LyricaConfiguration {
|
||||||
soundcloud: SoundCloudConfiguration,
|
soundcloud: SoundCloudConfiguration,
|
||||||
youtube: YouTubeConfiguration
|
youtube: YouTubeConfiguration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LyricaConfiguration {
|
impl Default for LyricaConfiguration {
|
||||||
fn default() -> Self {
|
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 {
|
pub fn get_youtube(&self) -> &YouTubeConfiguration {
|
||||||
&self.youtube
|
&self.youtube
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
54
src/db.rs
Normal file
54
src/db.rs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
use redb::{Database, Error, ReadableTable, TableDefinition};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::config::get_db;
|
||||||
|
|
||||||
|
const TRACKS: TableDefinition<u32, Vec<u8>> = 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<Track, Error> {
|
||||||
|
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)
|
||||||
|
}
|
@ -23,6 +23,7 @@ use tokio_util::sync::CancellationToken;
|
|||||||
use wait_screen::WaitScreen;
|
use wait_screen::WaitScreen;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
mod db;
|
||||||
mod dlp;
|
mod dlp;
|
||||||
mod main_screen;
|
mod main_screen;
|
||||||
mod screen;
|
mod screen;
|
||||||
|
@ -11,7 +11,8 @@ use tokio_util::sync::CancellationToken;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{
|
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},
|
dlp::{self, DownloadProgress},
|
||||||
};
|
};
|
||||||
@ -34,7 +35,10 @@ pub fn initialize_async_service(
|
|||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
) {
|
) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
let _ = std::fs::create_dir_all(get_configs_dir());
|
||||||
|
|
||||||
let mut receiver = receiver;
|
let mut receiver = receiver;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = token.cancelled() => { return; }
|
_ = token.cancelled() => { return; }
|
||||||
@ -51,7 +55,6 @@ pub fn initialize_async_service(
|
|||||||
},
|
},
|
||||||
AppEvent::ParseItunes(path) => {
|
AppEvent::ParseItunes(path) => {
|
||||||
// todo: parse itunes
|
// todo: parse itunes
|
||||||
let _ = std::fs::create_dir_all(get_configs_dir());
|
|
||||||
let cd = get_temp_itunesdb();
|
let cd = get_temp_itunesdb();
|
||||||
let p: PathBuf = Path::new(&path).into();
|
let p: PathBuf = Path::new(&path).into();
|
||||||
// p.push("iPod_Control");
|
// p.push("iPod_Control");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user