Check for existing annotations

This commit is contained in:
Josh Hansen 2023-06-28 15:13:31 -07:00
parent c4c509c1e1
commit b6db840208

View file

@ -200,6 +200,7 @@ fn main() {
let sample_rate: Arc<FairMutex<usize>> = Arc::new(FairMutex::new(44100));
// The audio output stream / thread
let stream = {
let idx = Arc::clone(&idx);
let buf = Arc::clone(&buf);
@ -305,27 +306,35 @@ fn main() {
let file = File::open(path.as_ref().unwrap()).unwrap();
let mut mp3dec = Decoder::new(file);
// If there are no annotations for the file, load it and begin the process of annotating;
if xattr::get(path.as_ref().unwrap(), "user.ad-annotation")
.unwrap()
.is_none()
{
buf.lock().clear();
let mut mp3dec = Decoder::new(file);
let mut is_first = true;
{
buf.lock().clear();
while let Ok(frame) = mp3dec.next_frame() {
buf.lock().extend_from_slice(&frame.data);
let mut is_first = true;
// Get settings only from the first frame
if is_first {
is_first = false;
while let Ok(frame) = mp3dec.next_frame() {
buf.lock().extend_from_slice(&frame.data);
let mut mp3_channels = mp3_channels.lock();
*mp3_channels = Some(frame.channels);
// Get settings only from the first frame
if is_first {
is_first = false;
let mut sample_rate = sample_rate.lock();
*sample_rate = frame.sample_rate as usize;
let mut mp3_channels = mp3_channels.lock();
*mp3_channels = Some(frame.channels);
let mut sample_rate = sample_rate.lock();
*sample_rate = frame.sample_rate as usize;
}
}
}
} else {
execute!(stdout, MoveToNextLine(1), MoveToColumn(0), Print("\t🗃 Annotations Found")).unwrap();
}
} // while buf empty