diff --git a/src/coverart.rs b/src/coverart.rs new file mode 100644 index 0000000..4703823 --- /dev/null +++ b/src/coverart.rs @@ -0,0 +1,27 @@ +use std::io::Read; + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct CoverArt { + pub id: i32, + pub title: String, + pub path: String, + pub data: Vec, +} + +impl CoverArt { + pub fn to_data(&self) -> Result, std::io::Error> { + let path: &String = &self.path; + let mut file = std::fs::File::open(path)?; + let mut buffer = Vec::new(); + match file.read_to_end(&mut buffer) { + Ok(_) => { + return Ok(buffer); + } + Err(err) => { + return Err(err); + } + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 723b0fc..da15f76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ pub mod access_level; pub mod album; pub mod constants; +pub mod coverart; pub mod login_result; pub mod song; pub mod token; diff --git a/src/song.rs b/src/song.rs index 1ff20f7..b024a62 100644 --- a/src/song.rs +++ b/src/song.rs @@ -159,23 +159,13 @@ impl Song { let filename_len = 10; let file_extension = match typ { - types::types::Types::DefaultMusicExtension => - { + types::types::Types::DefaultMusicExtension => { String::from(constants::DEFAULTMUSICEXTENSION) } - types::types::Types::WavExtension => - { - String::from(constants::WAVEXTENSION) - } - types::types::Types::FlacExtension => - { - String::from(constants::FLACEXTENSION) - } - types::types::Types::MPThreeExtension => - { - String::from(constants::MPTHREEEXTENSION) - } + types::types::Types::WavExtension => String::from(constants::WAVEXTENSION), + types::types::Types::FlacExtension => String::from(constants::FLACEXTENSION), + types::types::Types::MPThreeExtension => String::from(constants::MPTHREEEXTENSION), }; if randomize {