Cleaned up code, updated crates

This commit is contained in:
G2-Games 2024-01-24 02:47:57 -06:00
parent e706d232d6
commit 04c7ddb876
3 changed files with 21 additions and 13 deletions

View file

@ -13,12 +13,11 @@ categories = []
[dependencies]
file-format = { version = "0.23.0", features = ["reader-asf", "reader-ebml", "reader-mp4", "reader-rm", "reader-txt", "reader-xml", "serde"] }
lofty = "0.18.0"
lofty = "0.18.2"
serde = { version = "1.0.195", features = ["derive"] }
walkdir = "2.4.0"
chrono = { version = "0.4.31", features = ["serde"] }
bincode = { version = "2.0.0-rc.3", features = ["serde"] }
unidecode = "0.3.0"
rayon = "1.8.0"
log = "0.4"
base64 = "0.21.5"
@ -35,4 +34,5 @@ m3u8-rs = "5.0.5"
thiserror = "1.0.56"
font = "0.27.0"
uuid = { version = "1.6.1", features = ["v4", "serde"]}
serde_json = "1.0.111"
serde_json = "1.0.111"
deunicode = "1.4.2"

View file

@ -83,7 +83,8 @@ enum PlaybackStats {
Playing{
start: Duration,
end: Duration,
}
},
Finished // When this is sent, the thread will die!
}
/// An instance of a music player with a GStreamer backend
@ -142,10 +143,10 @@ impl Player {
let mut stats = PlaybackStats::Idle;
let mut pos_temp;
loop {
match stat_rx.recv_timeout(std::time::Duration::from_millis(100)) {
Ok(res) => stats = res,
Err(_) => {}
};
// Check for new messages or updates about how to proceed
if let Ok(res) = stat_rx.recv_timeout(std::time::Duration::from_millis(100)) {
stats = res
}
pos_temp = playbin_arc
.read()
@ -171,8 +172,13 @@ impl Player {
// This has to be done AFTER the current time in the file
// is calculated, or everything else is wrong
pos_temp = Some(pos_temp.unwrap() - start)
}
_ => println!("waiting!")
},
PlaybackStats::Finished => {
*position_update.write().unwrap() = None;
break
},
PlaybackStats::Idle | PlaybackStats::Switching => println!("waiting!"),
_ => ()
}
*position_update.write().unwrap() = pos_temp;
@ -483,11 +489,13 @@ impl Player {
}
impl Drop for Player {
/// Cleans up `GStreamer` pipeline when `Backend` is dropped.
/// Cleans up the `GStreamer` pipeline and the monitoring
/// thread when [Player] is dropped.
fn drop(&mut self) {
self.playbin_mut()
.unwrap()
.set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
let _ = self.playback_tx.send(PlaybackStats::Finished);
}
}

View file

@ -6,13 +6,13 @@ use std::error::Error;
use walkdir::WalkDir;
use file_format::{FileFormat, Kind};
use snap;
use unidecode::unidecode;
use deunicode::deunicode_with_tofu;
use super::library::{AlbumArt, URI};
pub(super) fn normalize(input_string: &str) -> String {
// Normalize the string to latin characters... this needs a lot of work
let mut normalized = unidecode(input_string);
let mut normalized = deunicode_with_tofu(input_string, " ");
// Remove non alphanumeric characters
normalized.retain(|c| c.is_alphanumeric());