From 3a77aff9f1c15ae80c3b83fa5be673aa233c8efb Mon Sep 17 00:00:00 2001 From: "alterwain@protonmail.com" Date: Fri, 14 Feb 2025 03:51:12 +0300 Subject: [PATCH] upddd --- Cargo.lock | 205 ++------------------------------------------- Cargo.toml | 4 - src/db.rs | 24 +++++- src/main_screen.rs | 2 +- src/sync.rs | 28 ++++++- 5 files changed, 52 insertions(+), 211 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a72805d..5527701 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,12 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "adler2" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" - [[package]] name = "aho-corasick" version = "1.1.3" @@ -86,7 +80,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide 0.7.4", + "miniz_oxide", "object", "rustc-demangle", ] @@ -133,12 +127,6 @@ version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" -[[package]] -name = "bytemuck" -version = "1.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3" - [[package]] name = "byteorder" version = "1.5.0" @@ -222,15 +210,6 @@ dependencies = [ "tracing-error", ] -[[package]] -name = "color-thief" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6460d760cf38ce67c9e0318f896538820acc54f2d0a3bfc5b2c557211066c98" -dependencies = [ - "rgb", -] - [[package]] name = "compact_str" version = "0.8.1" @@ -261,15 +240,6 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "crc32fast" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" -dependencies = [ - "cfg-if", -] - [[package]] name = "crossterm" version = "0.28.1" @@ -452,16 +422,6 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" -[[package]] -name = "flate2" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" -dependencies = [ - "crc32fast", - "miniz_oxide 0.8.3", -] - [[package]] name = "fnv" version = "1.0.7" @@ -498,12 +458,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "futures" version = "0.3.31" @@ -1027,7 +981,7 @@ dependencies = [ "bincode", "env_logger", "log", - "rand 0.8.5", + "rand", "serde", "serde_json", ] @@ -1054,15 +1008,6 @@ version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" -[[package]] -name = "libmath" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfd3416934a853ae80d5c3b006f632dfcbaf320300c5167e88a469e9ac214502" -dependencies = [ - "rand 0.3.23", -] - [[package]] name = "libredox" version = "0.1.3" @@ -1129,12 +1074,10 @@ dependencies = [ "bincode", "chrono", "color-eyre", - "color-thief", "crossterm", "dirs", "futures", "itunesdb", - "libmath", "md-5", "puremp3", "ratatui", @@ -1144,11 +1087,9 @@ dependencies = [ "serde", "serde_json", "soundcloud", - "strum 0.27.0", "tokio", "tokio-util", "toml", - "ureq", ] [[package]] @@ -1182,15 +1123,6 @@ dependencies = [ "adler", ] -[[package]] -name = "miniz_oxide" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8402cab7aefae129c6977bb0ff1b8fd9a04eb5b51efc50a70bea51cda0c7924" -dependencies = [ - "adler2", -] - [[package]] name = "mio" version = "1.0.3" @@ -1411,29 +1343,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.3.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" -dependencies = [ - "libc", - "rand 0.4.6", -] - -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - [[package]] name = "rand" version = "0.8.5" @@ -1442,7 +1351,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -1452,24 +1361,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.6.4" @@ -1494,22 +1388,13 @@ dependencies = [ "itertools", "lru", "paste", - "strum 0.26.3", + "strum", "time", "unicode-segmentation", "unicode-truncate", "unicode-width 0.2.0", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redb" version = "2.4.0" @@ -1612,15 +1497,6 @@ dependencies = [ "windows-registry", ] -[[package]] -name = "rgb" -version = "0.8.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" -dependencies = [ - "bytemuck", -] - [[package]] name = "ring" version = "0.17.8" @@ -1671,9 +1547,7 @@ version = "0.23.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fb9263ab4eb695e42321db096e3b8fbd715a59b154d5c88d82db2175b681ba7" dependencies = [ - "log", "once_cell", - "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1922,16 +1796,7 @@ version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ - "strum_macros 0.26.4", -] - -[[package]] -name = "strum" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce1475c515a4f03a8a7129bb5228b81a781a86cb0b3fbbc19e1c556d491a401f" -dependencies = [ - "strum_macros 0.27.0", + "strum_macros", ] [[package]] @@ -1947,19 +1812,6 @@ dependencies = [ "syn", ] -[[package]] -name = "strum_macros" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9688894b43459159c82bfa5a5fa0435c19cbe3c9b427fa1dd7b1ce0c279b18a7" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn", -] - [[package]] name = "subtle" version = "2.6.1" @@ -2319,36 +2171,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" -[[package]] -name = "ureq" -version = "3.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2916852be768844b6e9cbe107358b5bc40a696bd6dc8e036c9f80c731242c9c" -dependencies = [ - "base64", - "flate2", - "log", - "percent-encoding", - "rustls", - "rustls-pemfile", - "rustls-pki-types", - "ureq-proto", - "utf-8", - "webpki-roots", -] - -[[package]] -name = "ureq-proto" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c51fe73e1d8c4e06bb2698286f7e7453c6fc90528d6d2e7fc36bb4e87fe09b1" -dependencies = [ - "base64", - "http", - "httparse", - "log", -] - [[package]] name = "url" version = "2.5.4" @@ -2360,12 +2182,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - [[package]] name = "utf16_iter" version = "1.0.5" @@ -2501,15 +2317,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki-roots" -version = "0.26.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2210b291f7ea53617fbafcc4939f10914214ec15aace5ba62293a668f322c5c9" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 07a1ef6..204c44f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,18 +14,14 @@ 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"] } color-eyre = "0.6.3" crossterm = { version = "0.28.1", features = ["event-stream"] } futures = "0.3" tokio = { version = "1", features = ["full"] } tokio-util = { version = "0.7.12", features = ["codec"] } -strum = { version = "0.27", features = ["derive"] } soundcloud = { version = "0.1.8", git = "https://gitea.awain.net/alterwain/soundcloud_api.git" } itunesdb = { version = "0.1.6", git = "https://gitea.awain.net/alterwain/ITunesDB.git" } -ureq = "3.0.5" -color-thief = "0.2" redb = "2.4.0" md-5 = "0.10.6" puremp3 = "0.1.0" diff --git a/src/db.rs b/src/db.rs index 0baed04..de8bc72 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,5 +1,5 @@ use std::fs::File; - +use std::ops::Deref; use itunesdb::xobjects::{XArgument, XPlaylist, XTrackItem}; use md5::{Digest, Md5}; use redb::{Database, Error, ReadableTable, TableDefinition}; @@ -29,7 +29,7 @@ pub struct Track { has_artwork: u8, media_type: u32, pub title: String, - location: String, + pub location: String, album: String, pub artist: String, pub genre: String, @@ -44,7 +44,7 @@ pub struct DBPlaylist { pub tracks: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone)] pub struct Playlist { pub persistent_playlist_id: u64, pub title: String, @@ -177,6 +177,24 @@ pub fn insert_track(db: &Database, track: Track) -> Result<(), Error> { let uid = track.unique_id; let data = bincode::serialize(&track).unwrap(); table.insert(uid, data)?; + + let read_txn = db.begin_read()?; + let table = read_txn.open_table(PLAYLISTS)?; + + let pls = table + .iter() + .unwrap() + .flatten() + .map(|d| bincode::deserialize(&d.1.value()).unwrap()) + .collect::>(); + + for pl in pls { + if !pl.is_master { continue } + let mut master = pl.clone(); + master.tracks.push(uid); + insert_playlist(db, master); + break; + } } write_txn.commit()?; Ok(()) diff --git a/src/main_screen.rs b/src/main_screen.rs index 3050ab0..06b56a9 100644 --- a/src/main_screen.rs +++ b/src/main_screen.rs @@ -333,7 +333,7 @@ impl MainScreen { let mut row = Row::new(vec![ track.unique_id.to_string(), track.title.clone(), - track.artist.clone(), + track.location.clone(), track.bitrate.to_string(), track.genre.clone(), ]); diff --git a/src/sync.rs b/src/sync.rs index 2146ee4..8c12d5f 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -48,14 +48,14 @@ pub fn initialize_async_service( match request { AppEvent::SearchIPod => { if let Some(p) = util::search_ipod() { - let _ = sender.send(AppEvent::SwitchScreen(AppState::MainScreen)).await; ipod_db = Some(p.clone()); parse_itunes(&database, &sender, p).await; + let _ = sender.send(AppEvent::SwitchScreen(AppState::MainScreen)).await; } else { let _ = sender.send(AppEvent::IPodNotFound).await; } }, - AppEvent::DownloadPlaylist(playlist) => download_playlist(playlist, &database, &sender).await, + AppEvent::DownloadPlaylist(playlist) => download_playlist(playlist, &database, &sender, ipod_db.as_ref().unwrap().clone()).await, _ => {} } } @@ -69,18 +69,37 @@ async fn download_playlist( playlist: CloudPlaylist, database: &Database, sender: &Sender, + ipod_path: String ) { if let Ok(()) = dlp::download_from_soundcloud(&playlist.permalink_url, &get_temp_dl_dir(), sender.clone()) .await { let tracks = playlist.tracks; + + let mut p: PathBuf = Path::new(&ipod_path).into(); for track in tracks { if track.title.is_none() { continue; } - let mut t: Track = track.into(); + let mut t: Track = track.clone().into(); t.unique_id = db::get_last_track_id(database).unwrap_or(80) + 1; + let mut tp = PathBuf::new(); + tp.push("iPod_Control"); + tp.push("Music"); + tp.push(["F", &format!("{:02}", &(t.unique_id % 100))].concat()); + tp.push(format!("{:X}", t.unique_id)); + tp.set_extension("mp3"); + t.location = tp.to_str().unwrap().to_string().replace(r"/", ":").to_string(); + let mut dest = p.clone(); + dest.push(tp); + + let mut track_path = get_temp_dl_dir(); + track_path.push(track.id.to_string()); + track_path.set_extension("mp3"); + + let _ = std::fs::copy(track_path, dest); + let _ = db::insert_track(database, t); } } @@ -94,7 +113,8 @@ async fn parse_itunes(database: &Database, sender: &Sender, path: Stri let mut p: PathBuf = Path::new(&path).into(); p.push("iPod_Control"); p.push("iTunes"); - p.set_file_name("iTunesDB"); + p.push("iTunesDB"); + println!("{}", p.to_str().unwrap()); let _ = std::fs::copy(p, &cd); let mut file = File::open(cd).await.unwrap(); let mut contents = vec![];