Compare commits
3 Commits
v0.4.3-dev
...
v0.5.0-dev
Author | SHA1 | Date | |
---|---|---|---|
7958b89abc | |||
c0d23e0640 | |||
1a64b512f4 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -60,7 +60,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.4.3"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.4.3"
|
version = "0.5.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.88"
|
rust-version = "1.88"
|
||||||
description = "models used for the icarus project"
|
description = "models used for the icarus project"
|
||||||
|
@@ -0,0 +1,2 @@
|
|||||||
|
A library containing commonly used models and functions that is used throughout
|
||||||
|
icarus projects. This reduces the amount of duplicated code without a benefit.
|
||||||
|
149
src/song.rs
149
src/song.rs
@@ -46,6 +46,7 @@ pub struct Song {
|
|||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub directory: String,
|
pub directory: String,
|
||||||
|
// TODO: Think about what to do with this
|
||||||
// #[serde(skip)]
|
// #[serde(skip)]
|
||||||
// pub album_id: i32,
|
// pub album_id: i32,
|
||||||
// #[serde(skip)]
|
// #[serde(skip)]
|
||||||
@@ -150,151 +151,3 @@ impl Song {
|
|||||||
filename
|
filename
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
mod embedded {
|
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
impl Song {
|
|
||||||
pub fn to_metadata_json(&self, pretty: bool) -> Result<String, serde_json::Error> {
|
|
||||||
if pretty {
|
|
||||||
serde_json::to_string_pretty(&self)
|
|
||||||
} else {
|
|
||||||
serde_json::to_string(&self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn song_path(&self) -> Result<String, std::io::Error> {
|
|
||||||
if self.directory.is_empty() {
|
|
||||||
return Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"Directory does not exist",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let directory = &self.directory;
|
|
||||||
let mut buffer: String = directory.clone();
|
|
||||||
let last_index = directory.len() - 1;
|
|
||||||
|
|
||||||
if let Some(character) = directory.chars().nth(last_index) {
|
|
||||||
if character != '/' {
|
|
||||||
buffer += "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += &self.filename.clone();
|
|
||||||
|
|
||||||
Ok(buffer)
|
|
||||||
} else {
|
|
||||||
Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"Could not access last character of directory",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
|
|
||||||
let path_result = self.song_path();
|
|
||||||
|
|
||||||
match path_result {
|
|
||||||
Ok(path) => {
|
|
||||||
let mut file = std::fs::File::open(path)?;
|
|
||||||
let mut buffer: Vec<u8> = Vec::new();
|
|
||||||
file.read_to_end(&mut buffer)?;
|
|
||||||
|
|
||||||
if buffer.is_empty() {
|
|
||||||
Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"File is empty",
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
Ok(buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(er) => Err(er),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The song's duration is a floating point in seconds
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Song {
|
|
||||||
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
|
||||||
#[serde(alias = "id")]
|
|
||||||
pub id: uuid::Uuid,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub title: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub artist: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub album: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub album_artist: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub genre: String,
|
|
||||||
#[serde(skip_serializing_if = "init::is_embed_zero")]
|
|
||||||
pub year: i32,
|
|
||||||
#[serde(skip_serializing_if = "init::is_embed_dur_not_set")]
|
|
||||||
pub duration: f64,
|
|
||||||
#[serde(skip_serializing_if = "init::is_embed_zero")]
|
|
||||||
pub track: i32,
|
|
||||||
#[serde(skip_serializing_if = "init::is_embed_zero")]
|
|
||||||
pub disc: i32,
|
|
||||||
#[serde(skip_serializing_if = "init::is_embed_zero")]
|
|
||||||
pub disc_count: i32,
|
|
||||||
#[serde(skip_serializing_if = "init::is_embed_zero")]
|
|
||||||
pub track_count: i32,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub audio_type: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub date_created: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub filename: String,
|
|
||||||
#[serde(skip_serializing_if = "init::is_embed_zero")]
|
|
||||||
pub user_id: i32,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub data: Vec<u8>,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub directory: String,
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub album_id: i32,
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub artist_id: i32,
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub genre_id: i32,
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub coverart_id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Default for Song {
|
|
||||||
fn default() -> Self {
|
|
||||||
Song {
|
|
||||||
id: uuid::Uuid::nil(),
|
|
||||||
title: String::new(),
|
|
||||||
artist: String::new(),
|
|
||||||
album: String::new(),
|
|
||||||
album_artist: String::new(),
|
|
||||||
genre: String::new(),
|
|
||||||
year: 0,
|
|
||||||
duration: 0.0,
|
|
||||||
track: 0,
|
|
||||||
disc: 0,
|
|
||||||
disc_count: 0,
|
|
||||||
track_count: 0,
|
|
||||||
audio_type: String::new(),
|
|
||||||
date_created: String::new(),
|
|
||||||
filename: String::new(),
|
|
||||||
user_id: 0,
|
|
||||||
data: Vec::new(),
|
|
||||||
directory: String::new(),
|
|
||||||
// album_id: 0,
|
|
||||||
// artist_id: 0,
|
|
||||||
// genre_id: 0,
|
|
||||||
// coverart_id: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
Reference in New Issue
Block a user