Song changes
This commit is contained in:
101
src/song.rs
101
src/song.rs
@@ -1,6 +1,10 @@
|
||||
use std::default::Default;
|
||||
use std::io::Read;
|
||||
|
||||
use crate::constants;
|
||||
use crate::types;
|
||||
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
@@ -42,14 +46,14 @@ pub struct Song {
|
||||
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,
|
||||
// #[serde(skip)]
|
||||
// pub album_id: i32,
|
||||
// #[serde(skip)]
|
||||
// pub artist_id: i32,
|
||||
// #[serde(skip)]
|
||||
// pub genre_id: i32,
|
||||
// #[serde(skip)]
|
||||
// pub coverart_id: i32,
|
||||
}
|
||||
|
||||
fn is_zero(num: &i32) -> bool {
|
||||
@@ -81,10 +85,10 @@ impl Default for Song {
|
||||
user_id: 0,
|
||||
data: Vec::new(),
|
||||
directory: String::new(),
|
||||
album_id: 0,
|
||||
artist_id: 0,
|
||||
genre_id: 0,
|
||||
coverart_id: 0,
|
||||
// album_id: 0,
|
||||
// artist_id: 0,
|
||||
// genre_id: 0,
|
||||
// coverart_id: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,6 +153,55 @@ impl Song {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_filename(&self, typ: types::types::Types, randomize: bool) -> String {
|
||||
let mut filename: String = String::new();
|
||||
let filename_len = 10;
|
||||
|
||||
let file_extension = match typ {
|
||||
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)
|
||||
}
|
||||
};
|
||||
|
||||
if randomize {
|
||||
let some_chars: String = String::from("abcdefghij0123456789");
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for _i in 0..filename_len {
|
||||
let random_number: i32 = rng.gen_range(0..=19);
|
||||
let index = random_number as usize;
|
||||
let rando_char = some_chars.chars().nth(index);
|
||||
|
||||
match rando_char {
|
||||
Some(c) => {
|
||||
filename.push(c);
|
||||
}
|
||||
None => {}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
filename += "track-output";
|
||||
}
|
||||
|
||||
filename += &file_extension;
|
||||
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
|
||||
mod embedded {
|
||||
@@ -258,14 +311,14 @@ mod embedded {
|
||||
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,
|
||||
// #[serde(skip)]
|
||||
// pub album_id: i32,
|
||||
// #[serde(skip)]
|
||||
// pub artist_id: i32,
|
||||
// #[serde(skip)]
|
||||
// pub genre_id: i32,
|
||||
// #[serde(skip)]
|
||||
// pub coverart_id: i32,
|
||||
}
|
||||
|
||||
fn is_embed_zero(num: &i32) -> bool {
|
||||
@@ -297,10 +350,10 @@ mod embedded {
|
||||
user_id: 0,
|
||||
data: Vec::new(),
|
||||
directory: String::new(),
|
||||
album_id: 0,
|
||||
artist_id: 0,
|
||||
genre_id: 0,
|
||||
coverart_id: 0,
|
||||
// album_id: 0,
|
||||
// artist_id: 0,
|
||||
// genre_id: 0,
|
||||
// coverart_id: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
|
||||
mod types {
|
||||
pub mod types {
|
||||
pub enum Types {
|
||||
DefaultMusicExtension,
|
||||
WavExtension,
|
||||
FlacExtension,
|
||||
MPThreeExtension,
|
||||
|
Reference in New Issue
Block a user