From 842fe6302e9dbd5e6d727e71b00296ea9d36b538 Mon Sep 17 00:00:00 2001 From: KD Date: Sat, 15 Mar 2025 02:30:08 +0000 Subject: [PATCH] Added functions to song --- src/song.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/song.rs b/src/song.rs index ef21964..522bcb0 100644 --- a/src/song.rs +++ b/src/song.rs @@ -90,9 +90,34 @@ impl Default for Song { } impl Song { + pub fn to_metadata_json(&self, pretty: bool) -> Result { + if pretty { + return serde_json::to_string_pretty(&self); + } else { + return serde_json::to_string(&self); + } + } + // TODO: Implement - pub fn to_metadata_json(&self) -> Result { - return serde_json::to_string_pretty(&self); + pub fn song_path(&self) -> String { + return String::new(); + } + + pub fn to_data(&self) -> Result, std::io::Error> { + let path = self.song_path(); + + let mut file = std::fs::File::open(path)?; + let mut buffer: Vec = Vec::new(); + file.read_to_end(&mut buffer)?; + + if buffer.len() == 0 { + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "File is empty", + )) + } else { + Ok(buffer) + } } }