diff --git a/Cargo.lock b/Cargo.lock index 4ff420d..e8e517f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -433,7 +433,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1662,7 +1662,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1881,8 +1881,8 @@ dependencies = [ [[package]] name = "soundcloud" -version = "0.1.4" -source = "git+https://gitea.awain.net/alterwain/soundcloud_api.git#22f02cfa43bb91370211b64c9c6240496bd44515" +version = "0.1.8" +source = "git+https://gitea.awain.net/alterwain/soundcloud_api.git#656aef28f356411ff25cee14214ea0e677563537" dependencies = [ "hyper-util", "regex", @@ -2029,7 +2029,7 @@ dependencies = [ "getrandom 0.3.1", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2532,7 +2532,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 13802b4..2b6fa8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ 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.4", git = "https://gitea.awain.net/alterwain/soundcloud_api.git" } +soundcloud = { version = "0.1.8", git = "https://gitea.awain.net/alterwain/soundcloud_api.git" } itunesdb = { version = "0.1.2", git = "https://gitea.awain.net/alterwain/ITunesDB.git" } ureq = "3.0.5" color-thief = "0.2" diff --git a/src/db.rs b/src/db.rs index 13cb0bb..cc1f914 100644 --- a/src/db.rs +++ b/src/db.rs @@ -50,7 +50,7 @@ impl From for Track { size: f.metadata().unwrap().len() as u32, length: 0, year: 0, - bitrate: header.bitrate.bps(), + bitrate: header.bitrate.bps() / 1000, sample_rate: header.sample_rate.hz(), play_count: 0, dbid: hash(data), @@ -61,7 +61,9 @@ impl From for Track { title: value.title.unwrap(), location: String::new(), album: String::new(), - artist: "Soundcloud".to_string(), + artist: value + .user + .map_or(String::new(), |a| a.username.unwrap_or(a.permalink)), genre: value.genre.unwrap_or_default(), } } diff --git a/src/loading_screen.rs b/src/loading_screen.rs index f49b227..eee32d0 100644 --- a/src/loading_screen.rs +++ b/src/loading_screen.rs @@ -57,26 +57,16 @@ impl LoadingScreen { frame.render_widget(main_content, chunks[0]); - let gauge = Gauge::default() - .block( - Block::default() - .borders(Borders::ALL) - .title(" Downloading Playlist "), - ) - .gauge_style(Style::default().fg(Color::Green)) - .ratio(self.progress.unwrap().0 as f64 / self.progress.unwrap().1 as f64) - .label(format!( - "{:}/{:}", - self.progress.unwrap().0, - self.progress.unwrap().1 - )); - - frame.render_widget(gauge, chunks[1]); - - if self.s_progress.is_none() { - return; + if self.progress.is_some() { + self.render_overall(frame, chunks[1]); } + if self.s_progress.is_some() { + self.render_current(frame, chunks[2]); + } + } + + fn render_current(&self, frame: &mut Frame, area: Rect) { let s: String = self .s_progress .as_ref() @@ -96,6 +86,24 @@ impl LoadingScreen { .ratio(ratio / 100.0) .label(self.s_progress.as_ref().unwrap().progress_total.to_string()); - frame.render_widget(gauge, chunks[2]); + frame.render_widget(gauge, area); + } + + fn render_overall(&self, frame: &mut Frame, area: Rect) { + let gauge = Gauge::default() + .block( + Block::default() + .borders(Borders::ALL) + .title(" Downloading Playlist "), + ) + .gauge_style(Style::default().fg(Color::Green)) + .ratio(self.progress.unwrap().0 as f64 / self.progress.unwrap().1 as f64) + .label(format!( + "{:}/{:}", + self.progress.unwrap().0, + self.progress.unwrap().1 + )); + + frame.render_widget(gauge, area); } } diff --git a/src/sync.rs b/src/sync.rs index 07200a8..acf6ea2 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -86,6 +86,9 @@ async fn download_playlist( let _ = db::insert_track(database, t); } } + let _ = sender + .send(AppEvent::SwitchScreen(AppState::MainScreen)) + .await; } async fn parse_itunes(database: &Database, sender: &Sender, path: String) { @@ -119,7 +122,7 @@ async fn parse_itunes(database: &Database, sender: &Sender, path: Stri let config = LyricaConfiguration::default(); let cfg_str = toml::to_string_pretty(&config).unwrap(); let mut file = File::create(&p).await.unwrap(); - file.write(cfg_str.as_bytes()).await; + let _ = file.write(cfg_str.as_bytes()).await; } let mut file = File::open(p).await.unwrap(); let mut content = String::new(); @@ -128,10 +131,31 @@ async fn parse_itunes(database: &Database, sender: &Sender, path: Stri let app_version = soundcloud::get_app().await.unwrap().unwrap(); let client_id = soundcloud::get_client_id().await.unwrap().unwrap(); - let playlists = - soundcloud::get_playlists(config.get_soundcloud().user_id, client_id, app_version) - .await - .unwrap(); + let playlists = soundcloud::get_playlists( + config.get_soundcloud().user_id, + client_id.clone(), + app_version.clone(), + ) + .await + .unwrap(); - let _ = sender.send(AppEvent::SoundcloudGot(playlists)).await; + let mut playlists = playlists.collection; + + for playlist in playlists.iter_mut() { + if let Ok(tracks) = soundcloud::get_tracks( + playlist.tracks.clone(), + client_id.clone(), + app_version.clone(), + ) + .await + { + playlist.tracks = tracks; + } + } + + let _ = sender + .send(AppEvent::SoundcloudGot(CloudPlaylists { + collection: playlists, + })) + .await; }