Compare commits
4 Commits
dev-v0.1.1
...
dev-v0.1.1
Author | SHA1 | Date | |
---|---|---|---|
950a70ccad | |||
7f8649ee38 | |||
ab3e519f53 | |||
98c518e149 |
31
src/album.rs
Normal file
31
src/album.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
pub mod collection {
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
fn is_set(num: &i32) -> bool {
|
||||||
|
*num >= 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Album {
|
||||||
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
|
#[serde(alias = "album")]
|
||||||
|
pub title: String,
|
||||||
|
pub genre: String,
|
||||||
|
pub year: i32,
|
||||||
|
pub track_count: i32,
|
||||||
|
#[serde(skip_serializing_if = "is_set")]
|
||||||
|
pub disc_count: i32,
|
||||||
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
|
pub tracks: Vec<Track>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Track {
|
||||||
|
pub title: String,
|
||||||
|
pub artist: String,
|
||||||
|
pub disc: i32,
|
||||||
|
pub track: i32,
|
||||||
|
// In seconds
|
||||||
|
pub duration: f64,
|
||||||
|
}
|
||||||
|
}
|
27
src/coverart.rs
Normal file
27
src/coverart.rs
Normal file
@@ -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<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CoverArt {
|
||||||
|
pub fn to_data(&self) -> Result<Vec<u8>, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,7 @@
|
|||||||
pub mod access_level;
|
pub mod access_level;
|
||||||
|
pub mod album;
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
|
pub mod coverart;
|
||||||
pub mod login_result;
|
pub mod login_result;
|
||||||
pub mod song;
|
pub mod song;
|
||||||
pub mod token;
|
pub mod token;
|
||||||
|
18
src/song.rs
18
src/song.rs
@@ -159,23 +159,13 @@ impl Song {
|
|||||||
let filename_len = 10;
|
let filename_len = 10;
|
||||||
|
|
||||||
let file_extension = match typ {
|
let file_extension = match typ {
|
||||||
types::types::Types::DefaultMusicExtension =>
|
types::types::Types::DefaultMusicExtension => {
|
||||||
{
|
|
||||||
String::from(constants::DEFAULTMUSICEXTENSION)
|
String::from(constants::DEFAULTMUSICEXTENSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
types::types::Types::WavExtension =>
|
types::types::Types::WavExtension => String::from(constants::WAVEXTENSION),
|
||||||
{
|
types::types::Types::FlacExtension => String::from(constants::FLACEXTENSION),
|
||||||
String::from(constants::WAVEXTENSION)
|
types::types::Types::MPThreeExtension => String::from(constants::MPTHREEEXTENSION),
|
||||||
}
|
|
||||||
types::types::Types::FlacExtension =>
|
|
||||||
{
|
|
||||||
String::from(constants::FLACEXTENSION)
|
|
||||||
}
|
|
||||||
types::types::Types::MPThreeExtension =>
|
|
||||||
{
|
|
||||||
String::from(constants::MPTHREEEXTENSION)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if randomize {
|
if randomize {
|
||||||
|
Reference in New Issue
Block a user