Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 24e066d8d9 | |||
| ab08792ff4 | |||
| 9799edef33 | |||
| 92eb31a687 | |||
| aa946a0a05 | |||
| 19d6f2dc33 | |||
| 4824e6f33a | |||
| 64935ea772 | |||
| de90b0d0a1 | |||
| 19b943eed8 | |||
| 8c781398b4 | |||
| c575d2e523 | |||
| 03ed3deae6 | |||
| b69c111b66 | |||
| 8d97d4eb70 | |||
| 2f00ce6abf | |||
| e3cd1f4018 | |||
| a9f9ba8350 | |||
| df60bef381 | |||
| 038142eb8a | |||
| 69b81bc15c | |||
| b2e246d175 | |||
| c76e7b71b5 | |||
| b8dccca158 | |||
| b52607b4e3 | |||
| ac970a4302 | |||
| a372bfcc05 | |||
| d22850b280 | |||
| 4d170f6a85 | |||
| 7391b1db68 | |||
| 772641a8c4 | |||
| 4c99f88baf | |||
| c3718c5add | |||
| a4d026e41f | |||
| 6aa6f548a9 | |||
| 53b83a809c |
@@ -2,9 +2,9 @@ name: Rust
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "rust-lg" ]
|
branches: [ "master" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "rust-lg" ]
|
branches: [ "master" ]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
@@ -12,12 +12,11 @@ env:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: macos-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --verbose
|
run: cargo build --verbose
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test --verbose
|
run: cargo test --verbose
|
||||||
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
name: Rust
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "master" ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Install Rust version
|
||||||
|
run: rustup install 1.85.0 && rustup default 1.85.0
|
||||||
|
|
||||||
|
- name: Debug secret
|
||||||
|
run: echo "${{ secrets.MYREPO_TOKEN }}" | head -c 10 ; echo "..."
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$EXTREPO_KEY" > ~/.ssh/gitlab_deploy_key
|
||||||
|
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||||
|
ssh-keyscan git.kundeng.us ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLl/OZiKVDxwnyvMxa+rjKvDpKqTxH1GWuGuDPLmENGQMbTVulajZWr9x8Q1cotoJiHZkt7DA5vczcjB/4lwgWA= >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||||
|
cargo build --release
|
||||||
|
env:
|
||||||
|
EXTREPO_KEY: ${{ secrets.MYREPO_TOKEN }}
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: cargo test --verbose
|
||||||
+10
-9
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus-dm"
|
name = "icarus-dm"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -9,10 +9,11 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = { version = "0.3.30" }
|
futures = { version = "0.3.31" }
|
||||||
http = { version = "1.1.0" }
|
http = { version = "1.3.1" }
|
||||||
reqwest = { version = "0.12.4", features = ["json", "blocking", "multipart", "stream"] }
|
reqwest = { version = "0.12.15", features = ["json", "blocking", "multipart", "stream"] }
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.115"
|
serde_json = "1.0.140"
|
||||||
tokio = { version = "1.37", features = ["full"] }
|
tokio = { version = "1.44.1", features = ["full"] }
|
||||||
tokio-util = { version = "0.7.11", features = ["codec"] }
|
tokio-util = { version = "0.7.14", features = ["codec"] }
|
||||||
|
icarus-models = { git = "ssh://git@git.kundeng.us/phoenix/icarus-models.git", tag = "v0.1.14" }
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ icarus-dm download -u spacecadet -p stellar40 -h https://icarus.com -b 15
|
|||||||
### Uploading Song with metadata
|
### Uploading Song with metadata
|
||||||
|
|
||||||
```BASH
|
```BASH
|
||||||
icarus-dm upload-meta -u spacecadet -p stellar40 -h https://icarus.com -s /path/of/song.mp3 -t 1 -m /path/to/metadata/config/collection.json -ca /path/to/cover/art/image.png
|
icarus-dm upload-meta -u spacecadet -p stellar40 -h https://icarus.com -s /path/of/song.flac -t 1 -m /path/to/metadata/config/collection.json -ca /path/to/cover/art/image.png
|
||||||
```
|
```
|
||||||
|
|
||||||
### Uploading Song with metadata from directory
|
### Uploading Song with metadata from directory
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
pub const WAV_FILE_EXTENSION: &str = ".wav";
|
|
||||||
pub const _MP3_FILE_EXTENSION: &str = ".mp3";
|
|
||||||
pub const JPG_FILE_EXTENSION: &str = ".jpg";
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub mod file_extensions;
|
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
pub fn print_help() {
|
||||||
|
let msg: String = String::from(
|
||||||
|
r#"icd [Action] [flag]
|
||||||
|
|
||||||
|
Actions
|
||||||
|
download
|
||||||
|
upload-meta
|
||||||
|
retrieve
|
||||||
|
delete
|
||||||
|
|
||||||
|
Flags
|
||||||
|
Required for all actions
|
||||||
|
-u username
|
||||||
|
-p password
|
||||||
|
-h host
|
||||||
|
|
||||||
|
Required for upload with metadata
|
||||||
|
-s path of song
|
||||||
|
-t track number
|
||||||
|
-m metadata filepath
|
||||||
|
-ca coverart filepath
|
||||||
|
-scma directory where songs, metadata, and cover art exists and will be uploaded (Optional)
|
||||||
|
|
||||||
|
Required for download
|
||||||
|
-b song id
|
||||||
|
-d path to download song (Optional)
|
||||||
|
|
||||||
|
Required for retrieving records
|
||||||
|
-rt retrieve type (songs is only accepted)
|
||||||
|
|
||||||
|
Required for deleting a song
|
||||||
|
-D song id"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
println!("{}", msg);
|
||||||
|
}
|
||||||
+121
-56
@@ -1,4 +1,4 @@
|
|||||||
mod constants;
|
mod help;
|
||||||
mod managers;
|
mod managers;
|
||||||
mod models;
|
mod models;
|
||||||
mod parsers;
|
mod parsers;
|
||||||
@@ -6,71 +6,23 @@ mod syncers;
|
|||||||
mod utilities;
|
mod utilities;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::process;
|
|
||||||
|
|
||||||
fn exit_program(code: i32) {
|
|
||||||
process::exit(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_help() {
|
|
||||||
let msg: String = String::from(
|
|
||||||
r#"icd [Action] [flag]
|
|
||||||
|
|
||||||
Actions
|
|
||||||
download
|
|
||||||
upload-meta
|
|
||||||
retrieve
|
|
||||||
delete
|
|
||||||
|
|
||||||
Flags
|
|
||||||
Required for all actions
|
|
||||||
-u username
|
|
||||||
-p password
|
|
||||||
-h host
|
|
||||||
|
|
||||||
Required for upload with metadata
|
|
||||||
-s path of song
|
|
||||||
-t track number
|
|
||||||
-m metadata filepath
|
|
||||||
-ca coverart filepath
|
|
||||||
-scma directory where songs, metadata, and cover art exists and will be uploaded (Optional)
|
|
||||||
|
|
||||||
Required for download
|
|
||||||
-b song id
|
|
||||||
-d path to download song (Optional)
|
|
||||||
|
|
||||||
Required for retrieving records
|
|
||||||
-rt retrieve type (songs is only accepted)
|
|
||||||
|
|
||||||
Required for deleting a song
|
|
||||||
-D song id"#,
|
|
||||||
);
|
|
||||||
|
|
||||||
println!("{}", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
if args.len() == 1 {
|
|
||||||
print_help();
|
|
||||||
exit_program(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
let args_len = args.len() as i32;
|
let args_len = args.len() as i32;
|
||||||
|
|
||||||
|
if args_len == 1 {
|
||||||
|
help::print_help();
|
||||||
|
utilities::checks::exit_program(-1);
|
||||||
|
}
|
||||||
|
|
||||||
println!("Argument count: {}", args_len);
|
println!("Argument count: {}", args_len);
|
||||||
|
|
||||||
let mut act_mgr = managers::action_managers::ActionManager {
|
let mut act_mgr = managers::action_managers::ActionManager::default();
|
||||||
action: String::new(),
|
act_mgr.set_params(&args);
|
||||||
flags: Vec::new(),
|
|
||||||
params: args,
|
|
||||||
param_count: args_len,
|
|
||||||
};
|
|
||||||
act_mgr.initialize();
|
act_mgr.initialize();
|
||||||
|
|
||||||
let chosen_act = act_mgr.retrieve_icarus_action();
|
let chosen_act = act_mgr.retrieve_icarus_action();
|
||||||
|
|
||||||
chosen_act.print_action_and_flags();
|
chosen_act.print_action_and_flags();
|
||||||
|
|
||||||
let mut cmt_mgr = managers::commit_manager::CommitManager {
|
let mut cmt_mgr = managers::commit_manager::CommitManager {
|
||||||
@@ -79,3 +31,116 @@ fn main() {
|
|||||||
|
|
||||||
cmt_mgr.commit_action();
|
cmt_mgr.commit_action();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::managers;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_song_prep_upload() {
|
||||||
|
let meta_path = String::from("tests/sample2_tracks/album.json");
|
||||||
|
|
||||||
|
if !std::path::Path::new(&meta_path).exists() {
|
||||||
|
assert!(false, "File does not exists: {:?}", meta_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
match icarus_models::album::collection::parse_album(&meta_path) {
|
||||||
|
Ok(album) => {
|
||||||
|
for track in 1..3 {
|
||||||
|
let directory_path = std::path::Path::new(&meta_path);
|
||||||
|
let directory: String = directory_path.parent().unwrap().display().to_string();
|
||||||
|
let filename: String = if track < 10 {
|
||||||
|
String::from("track0")
|
||||||
|
+ &track.to_string()
|
||||||
|
+ icarus_models::constants::DEFAULTMUSICEXTENSION
|
||||||
|
} else {
|
||||||
|
String::from("track")
|
||||||
|
+ &track.to_string()
|
||||||
|
+ icarus_models::constants::DEFAULTMUSICEXTENSION
|
||||||
|
};
|
||||||
|
let disc = 1;
|
||||||
|
match managers::commit_manager::retrieve_song(
|
||||||
|
&album, track, disc, &directory, &filename,
|
||||||
|
) {
|
||||||
|
Ok(song) => match song.to_data() {
|
||||||
|
Ok(_) => {
|
||||||
|
print!("Success");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_minimum_action_and_args() {
|
||||||
|
let args: Vec<String> = vec![
|
||||||
|
"icarus-dm".to_string(),
|
||||||
|
"download".to_string(),
|
||||||
|
"-u".to_string(),
|
||||||
|
"jamborie".to_string(),
|
||||||
|
"-p".to_string(),
|
||||||
|
"somethingsecr3t!".to_string(),
|
||||||
|
"-h".to_string(),
|
||||||
|
"https://music-server.com".to_string(),
|
||||||
|
];
|
||||||
|
let arg_count = args.len() as i32;
|
||||||
|
let minimum_arg_count = 8;
|
||||||
|
assert!(arg_count >= minimum_arg_count);
|
||||||
|
|
||||||
|
let mut act_mgr = managers::action_managers::ActionManager {
|
||||||
|
action: String::new(),
|
||||||
|
flags: Vec::new(),
|
||||||
|
params: args,
|
||||||
|
param_count: arg_count,
|
||||||
|
};
|
||||||
|
act_mgr.initialize();
|
||||||
|
let ica = act_mgr.retrieve_icarus_action();
|
||||||
|
let action = &ica.action;
|
||||||
|
let flags = &ica.flags;
|
||||||
|
|
||||||
|
assert!(action != "");
|
||||||
|
assert!(flags.len() > 2);
|
||||||
|
assert!(
|
||||||
|
!(action != "download"
|
||||||
|
&& action != "upload"
|
||||||
|
&& action != "retrieve"
|
||||||
|
&& action != "upload-meta")
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut found_count = 0;
|
||||||
|
let mut flags_already_read = Vec::new();
|
||||||
|
|
||||||
|
for flag in flags {
|
||||||
|
if flags_already_read.contains(&flag.flag) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if flag.flag == "-u" {
|
||||||
|
found_count += 1;
|
||||||
|
flags_already_read.push(flag.flag.clone());
|
||||||
|
} else if flag.flag == "-p" {
|
||||||
|
found_count += 1;
|
||||||
|
flags_already_read.push(flag.flag.clone());
|
||||||
|
} else if flag.flag == "-h" {
|
||||||
|
found_count += 1;
|
||||||
|
flags_already_read.push(flag.flag.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let all_flags_found = found_count == 3;
|
||||||
|
|
||||||
|
assert_eq!(found_count, 3, "Three flags are required: -u, -p, -h");
|
||||||
|
assert!(all_flags_found, "All flags have not been found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::models;
|
use crate::{models, utilities};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct ActionManager {
|
pub struct ActionManager {
|
||||||
@@ -10,6 +10,17 @@ pub struct ActionManager {
|
|||||||
pub param_count: i32,
|
pub param_count: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ActionManager {
|
||||||
|
fn default() -> Self {
|
||||||
|
ActionManager {
|
||||||
|
action: String::new(),
|
||||||
|
flags: Vec::new(),
|
||||||
|
params: Vec::new(),
|
||||||
|
param_count: -1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActionManager {
|
impl ActionManager {
|
||||||
pub fn retrieve_icarus_action(&self) -> models::icarus_action::IcarusAction {
|
pub fn retrieve_icarus_action(&self) -> models::icarus_action::IcarusAction {
|
||||||
return models::icarus_action::IcarusAction {
|
return models::icarus_action::IcarusAction {
|
||||||
@@ -45,6 +56,11 @@ impl ActionManager {
|
|||||||
self.action = self.action.to_lowercase();
|
self.action = self.action.to_lowercase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_params(&mut self, args: &Vec<String>) {
|
||||||
|
self.params = args.clone();
|
||||||
|
self.param_count = self.params.len() as i32;
|
||||||
|
}
|
||||||
|
|
||||||
fn validate_flags(&mut self) {
|
fn validate_flags(&mut self) {
|
||||||
println!("Validating flags");
|
println!("Validating flags");
|
||||||
|
|
||||||
@@ -70,7 +86,7 @@ impl ActionManager {
|
|||||||
flg.flag = String::from(flag);
|
flg.flag = String::from(flag);
|
||||||
} else {
|
} else {
|
||||||
println!("Flag {} is not valid", flag);
|
println!("Flag {} is not valid", flag);
|
||||||
std::process::exit(-1);
|
utilities::checks::exit_program(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.flags.push(flg);
|
self.flags.push(flg);
|
||||||
@@ -102,7 +118,6 @@ impl ActionManager {
|
|||||||
|
|
||||||
fn does_flag_have_value(&self, flag: &String) -> bool {
|
fn does_flag_have_value(&self, flag: &String) -> bool {
|
||||||
let flags_tmp = self.parsed_flags();
|
let flags_tmp = self.parsed_flags();
|
||||||
|
|
||||||
let mut i_found: i32 = -1;
|
let mut i_found: i32 = -1;
|
||||||
|
|
||||||
for i in 0..flags_tmp.len() {
|
for i in 0..flags_tmp.len() {
|
||||||
@@ -151,71 +166,3 @@ impl ActionManager {
|
|||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::managers::action_managers::ActionManager;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn minimum_action_and_args() {
|
|
||||||
let args: Vec<String> = vec![
|
|
||||||
"icarus-dm".to_string(),
|
|
||||||
"download".to_string(),
|
|
||||||
"-u".to_string(),
|
|
||||||
"jamborie".to_string(),
|
|
||||||
"-p".to_string(),
|
|
||||||
"somethingsecr3t!".to_string(),
|
|
||||||
"-h".to_string(),
|
|
||||||
"https://music-server.com".to_string(),
|
|
||||||
];
|
|
||||||
let arg_count = args.len() as i32;
|
|
||||||
let minimum_arg_count = 8;
|
|
||||||
assert!(arg_count >= minimum_arg_count);
|
|
||||||
|
|
||||||
let mut act_mgr = ActionManager {
|
|
||||||
action: String::new(),
|
|
||||||
flags: Vec::new(),
|
|
||||||
params: args,
|
|
||||||
param_count: arg_count,
|
|
||||||
};
|
|
||||||
act_mgr.initialize();
|
|
||||||
let ica = act_mgr.retrieve_icarus_action();
|
|
||||||
let action = &ica.action;
|
|
||||||
let flags = &ica.flags;
|
|
||||||
|
|
||||||
assert!(action != "");
|
|
||||||
assert!(flags.len() > 2);
|
|
||||||
assert!(
|
|
||||||
!(action != "download"
|
|
||||||
&& action != "upload"
|
|
||||||
&& action != "retrieve"
|
|
||||||
&& action != "upload-meta")
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut all_flags_found = false;
|
|
||||||
let mut found_count = 0;
|
|
||||||
let mut flags_already_read = Vec::new();
|
|
||||||
|
|
||||||
for flag in flags {
|
|
||||||
if flags_already_read.contains(&flag.flag) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if flag.flag == "-u" {
|
|
||||||
found_count += 1;
|
|
||||||
flags_already_read.push(flag.flag.clone());
|
|
||||||
} else if flag.flag == "-p" {
|
|
||||||
found_count += 1;
|
|
||||||
flags_already_read.push(flag.flag.clone());
|
|
||||||
} else if flag.flag == "-h" {
|
|
||||||
found_count += 1;
|
|
||||||
flags_already_read.push(flag.flag.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
all_flags_found = found_count == 3;
|
|
||||||
|
|
||||||
assert_eq!(found_count, 3, "Three flags are required: -u, -p, -h");
|
|
||||||
assert!(all_flags_found, "All flags have not been found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+265
-391
@@ -8,11 +8,10 @@ use serde::{Deserialize, Serialize};
|
|||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
use crate::managers;
|
use crate::managers;
|
||||||
use crate::models::song::Album;
|
|
||||||
use crate::models::{self};
|
use crate::models::{self};
|
||||||
|
use crate::parsers;
|
||||||
use crate::syncers;
|
use crate::syncers;
|
||||||
use crate::utilities;
|
use crate::utilities;
|
||||||
use crate::{constants, parsers};
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct CommitManager {
|
pub struct CommitManager {
|
||||||
@@ -29,10 +28,6 @@ enum ActionValues {
|
|||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum _RetrieveTypes {
|
|
||||||
Songs,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
enum En {
|
enum En {
|
||||||
ImageFile,
|
ImageFile,
|
||||||
@@ -41,36 +36,47 @@ enum En {
|
|||||||
Other,
|
Other,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Album {
|
pub fn retrieve_song(
|
||||||
pub fn _print_info(&self) {
|
album: &icarus_models::album::collection::Album,
|
||||||
println!("Album: {}", self.title);
|
track: i32,
|
||||||
println!("Album Artist: {}", self.album_artist);
|
disc: i32,
|
||||||
println!("Genre: {}", self.genre);
|
directory: &String,
|
||||||
println!("Year: {}", self.year);
|
filename: &String,
|
||||||
println!("Track Count: {}", self.track_count);
|
) -> Result<icarus_models::song::Song> {
|
||||||
println!("Disc Count: {}\n", self.disc_count);
|
let mut found = false;
|
||||||
|
let mut song = icarus_models::song::Song::default();
|
||||||
|
|
||||||
|
for song_i in &album.tracks {
|
||||||
|
if song_i.track == track && song_i.disc == disc {
|
||||||
|
let track = song_i.clone();
|
||||||
|
song.album = album.title.clone();
|
||||||
|
song.album_artist = album.artist.clone();
|
||||||
|
song.artist = track.artist.clone();
|
||||||
|
song.audio_type = String::from(icarus_models::constants::DEFAULTMUSICEXTENSION);
|
||||||
|
song.disc = track.disc.clone();
|
||||||
|
song.disc_count = album.disc_count.clone();
|
||||||
|
song.duration = track.duration as i32;
|
||||||
|
song.genre = album.genre.clone();
|
||||||
|
song.title = track.title.clone();
|
||||||
|
song.year = album.year.clone();
|
||||||
|
song.track = track.track.clone();
|
||||||
|
song.track_count = album.track_count.clone();
|
||||||
|
song.directory = directory.clone();
|
||||||
|
song.filename = filename.clone();
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retrieve_song(&self, track: i32, disc: i32) -> Result<models::song::Song> {
|
if found {
|
||||||
let mut found = false;
|
return Ok(song);
|
||||||
let mut song = models::song::Song::default();
|
|
||||||
|
|
||||||
for song_i in &self.songs {
|
|
||||||
if song_i.track.unwrap() == track && song_i.disc.unwrap() == disc {
|
|
||||||
song = song_i.clone();
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if found {
|
|
||||||
return Ok(song);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::NotFound,
|
|
||||||
"Song not found",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::NotFound,
|
||||||
|
"Song not found",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommitManager {
|
impl CommitManager {
|
||||||
@@ -110,15 +116,17 @@ impl CommitManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn map_actions(&self) -> HashMap<String, ActionValues> {
|
fn map_actions(&self) -> HashMap<String, ActionValues> {
|
||||||
let mut actions: HashMap<String, ActionValues> = HashMap::new();
|
let actions: HashMap<String, ActionValues> = HashMap::from([
|
||||||
actions.insert("download".to_string(), ActionValues::DownloadAct);
|
("download".to_string(), ActionValues::DownloadAct),
|
||||||
actions.insert("upload".to_string(), ActionValues::UploadAct);
|
("download".to_string(), ActionValues::DownloadAct),
|
||||||
actions.insert(
|
("upload".to_string(), ActionValues::UploadAct),
|
||||||
"upload-meta".to_string(),
|
(
|
||||||
ActionValues::UploadSongWithMetadata,
|
"upload-meta".to_string(),
|
||||||
);
|
ActionValues::UploadSongWithMetadata,
|
||||||
actions.insert("retrieve".to_string(), ActionValues::RetrieveAct);
|
),
|
||||||
actions.insert("delete".to_string(), ActionValues::DeleteAct);
|
("retrieve".to_string(), ActionValues::RetrieveAct),
|
||||||
|
("delete".to_string(), ActionValues::DeleteAct),
|
||||||
|
]);
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
@@ -135,14 +143,14 @@ impl CommitManager {
|
|||||||
|
|
||||||
println!("Deleting song");
|
println!("Deleting song");
|
||||||
|
|
||||||
let mut song = models::song::Song::default();
|
let mut song = icarus_models::song::Song::default();
|
||||||
|
|
||||||
for arg in &self.ica_action.flags {
|
for arg in &self.ica_action.flags {
|
||||||
let flag = &arg.flag;
|
let flag = &arg.flag;
|
||||||
let value = &arg.value;
|
let value = &arg.value;
|
||||||
|
|
||||||
if flag == "-D" {
|
if flag == "-D" {
|
||||||
song.id = Some(value.parse::<i32>().unwrap());
|
song.id = value.parse::<i32>().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +173,7 @@ impl CommitManager {
|
|||||||
fn download_song(&self) {
|
fn download_song(&self) {
|
||||||
println!("Deleting song");
|
println!("Deleting song");
|
||||||
let dwn = self.ica_action.retrieve_flag_value(&String::from("-b"));
|
let dwn = self.ica_action.retrieve_flag_value(&String::from("-b"));
|
||||||
let num: i32 = dwn.parse::<i32>().unwrap();
|
let id: i32 = dwn.parse::<i32>().unwrap();
|
||||||
|
|
||||||
let mut prsr = parsers::api_parser::APIParser {
|
let mut prsr = parsers::api_parser::APIParser {
|
||||||
api: models::api::API::default(),
|
api: models::api::API::default(),
|
||||||
@@ -175,29 +183,38 @@ impl CommitManager {
|
|||||||
|
|
||||||
let api = prsr.retrieve_api();
|
let api = prsr.retrieve_api();
|
||||||
let token = self.parse_token(&api);
|
let token = self.parse_token(&api);
|
||||||
|
println!("Message: {}", token.message);
|
||||||
|
|
||||||
let mut dwn_loader = syncers::download::Download { api: api.clone() };
|
let mut dwn_loader = syncers::download::Download { api: api.clone() };
|
||||||
let mut song = models::song::Song::default();
|
let mut song = icarus_models::song::Song::default();
|
||||||
song.id = Some(num);
|
song.id = id;
|
||||||
let result_fut = dwn_loader.download_song(&token, &song);
|
let result_fut = dwn_loader.download_song(&token, &song);
|
||||||
let result = Runtime::new().unwrap().block_on(result_fut);
|
match Runtime::new().unwrap().block_on(result_fut) {
|
||||||
match result {
|
|
||||||
Ok(o) => {
|
Ok(o) => {
|
||||||
println!("Success");
|
println!("Success");
|
||||||
let mut filename = String::from("audio");
|
let filename =
|
||||||
filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
String::from("audio") + icarus_models::constants::DEFAULTMUSICEXTENSION;
|
||||||
let data = o.as_bytes();
|
let data = o.as_bytes();
|
||||||
let mut file = std::fs::File::create(filename).expect("Failed to save");
|
let mut file = std::fs::File::create(filename).expect("Failed to save");
|
||||||
file.write_all(&data).expect("ff");
|
file.write_all(&data)
|
||||||
|
.expect("Failed to save downloaded song");
|
||||||
}
|
}
|
||||||
Err(er) => {
|
Err(er) => {
|
||||||
println!("Error {:?}", er);
|
println!("Error {:?}", er);
|
||||||
|
match er {
|
||||||
|
syncers::download::MyError::Request(error) => {
|
||||||
|
println!("Error: {:?}", error);
|
||||||
|
}
|
||||||
|
syncers::download::MyError::Other(ss) => {
|
||||||
|
println!("Error: {:?}", ss);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_object(&self) {
|
fn retrieve_object(&self) {
|
||||||
println!("Deleting song");
|
println!("Retrieving song");
|
||||||
let rt = self.ica_action.retrieve_flag_value(&String::from("-rt"));
|
let rt = self.ica_action.retrieve_flag_value(&String::from("-rt"));
|
||||||
|
|
||||||
if rt != "songs" {
|
if rt != "songs" {
|
||||||
@@ -215,11 +232,13 @@ impl CommitManager {
|
|||||||
let mut repo = syncers::retrieve_records::RetrieveRecords { api: api.clone() };
|
let mut repo = syncers::retrieve_records::RetrieveRecords { api: api.clone() };
|
||||||
let result_fut = repo.get_all_songs(&token);
|
let result_fut = repo.get_all_songs(&token);
|
||||||
|
|
||||||
let result = Runtime::new().unwrap().block_on(result_fut);
|
match Runtime::new().unwrap().block_on(result_fut) {
|
||||||
match result {
|
|
||||||
Ok(o) => {
|
Ok(o) => {
|
||||||
for son in o {
|
for song in o {
|
||||||
son.print_info();
|
println!("Title: {:?}", song.title);
|
||||||
|
println!("Artist: {:?}", song.artist);
|
||||||
|
println!("Album: {:?}", song.album);
|
||||||
|
println!("Year: {:?}", song.year);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(er) => {
|
Err(er) => {
|
||||||
@@ -233,15 +252,12 @@ impl CommitManager {
|
|||||||
panic!("Not supported");
|
panic!("Not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_token(&self, api: &models::api::API) -> models::token::Token {
|
fn parse_token(&self, api: &models::api::API) -> icarus_models::token::AccessToken {
|
||||||
println!("Fetching token");
|
println!("Fetching token");
|
||||||
|
|
||||||
let mut usr_mgr: managers::user_manager::UserManager =
|
let mut usr_mgr: managers::user_manager::UserManager =
|
||||||
managers::user_manager::UserManager {
|
managers::user_manager::UserManager {
|
||||||
user: models::user::User {
|
user: icarus_models::user::User::default(),
|
||||||
username: String::new(),
|
|
||||||
password: String::new(),
|
|
||||||
},
|
|
||||||
ica_action: self.ica_action.clone(),
|
ica_action: self.ica_action.clone(),
|
||||||
};
|
};
|
||||||
usr_mgr.parse_user_from_actions();
|
usr_mgr.parse_user_from_actions();
|
||||||
@@ -309,6 +325,8 @@ impl CommitManager {
|
|||||||
let api = prsr.retrieve_api();
|
let api = prsr.retrieve_api();
|
||||||
let token = self.parse_token(&api);
|
let token = self.parse_token(&api);
|
||||||
|
|
||||||
|
println!("Token: {:?}", token.token);
|
||||||
|
|
||||||
let song_file = std::path::Path::new(&songpath);
|
let song_file = std::path::Path::new(&songpath);
|
||||||
|
|
||||||
if !song_file.exists() {
|
if !song_file.exists() {
|
||||||
@@ -316,70 +334,124 @@ impl CommitManager {
|
|||||||
panic!("Error");
|
panic!("Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cover_art = models::song::CoverArt::default();
|
let mut cover_art = icarus_models::coverart::CoverArt {
|
||||||
let mut song = models::song::Song::default();
|
id: 0,
|
||||||
let mut filenames = Vec::new();
|
title: String::new(),
|
||||||
let mut fp = String::new();
|
path: cover_path.clone(),
|
||||||
let mut dir = String::new();
|
data: Vec::new(),
|
||||||
|
};
|
||||||
let entry = &song_file;
|
let file_name = std::ffi::OsString::from(&song_file.file_name().unwrap());
|
||||||
|
|
||||||
let file_name = std::ffi::OsString::from(entry.file_name().unwrap());
|
|
||||||
|
|
||||||
println!("file name: {:?}", file_name);
|
|
||||||
|
|
||||||
match self.find_file_extension(&file_name) {
|
match self.find_file_extension(&file_name) {
|
||||||
En::ImageFile => {}
|
En::SongFile => match utilities::string::o_to_string(&file_name) {
|
||||||
En::MetadataFile => {}
|
Ok(s) => {
|
||||||
En::SongFile => {
|
println!("file name: {:?}", file_name);
|
||||||
let fname = self.o_to_string(&file_name);
|
|
||||||
|
|
||||||
match fname {
|
match icarus_models::album::collection::parse_album(&meta_path) {
|
||||||
Ok(s) => {
|
Ok(album) => {
|
||||||
filenames.push(s.clone());
|
let filename = s.clone();
|
||||||
fp = s.clone();
|
let directory = song_file.parent().unwrap().display().to_string();
|
||||||
dir = song_file.parent().unwrap().display().to_string();
|
let trck = i32::from_str(track_id).unwrap();
|
||||||
song.filepath = Some(s.clone());
|
let mut s =
|
||||||
song.directory = Some(dir.clone());
|
retrieve_song(&album, trck, 1, &directory, &filename).unwrap();
|
||||||
self.initialize_disc_and_track(&mut song);
|
println!("Directory: {:?}", s.directory);
|
||||||
|
println!("Filename: {:?}", s.filename);
|
||||||
|
println!("Path: {:?}", s.song_path());
|
||||||
|
s.data = s.to_data().unwrap();
|
||||||
|
|
||||||
|
cover_art.data = cover_art.to_data().unwrap();
|
||||||
|
|
||||||
|
let mut up = syncers::upload::Upload::default();
|
||||||
|
let host = self.ica_action.retrieve_flag_value(&String::from("-h"));
|
||||||
|
up.set_api(&host);
|
||||||
|
|
||||||
|
let res = up.upload_song_with_metadata(&token, &s, &cover_art);
|
||||||
|
|
||||||
|
match Runtime::new().unwrap().block_on(res) {
|
||||||
|
Ok(o) => {
|
||||||
|
println!("Successfully sent {:?}", o);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(er) => {
|
||||||
|
println!("Some error {:?}", er);
|
||||||
|
Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::Other,
|
||||||
|
er.to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("Error: {:?}", err);
|
||||||
|
Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::Other,
|
||||||
|
err.to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(er) => println!("Error: {:?}", er),
|
|
||||||
}
|
}
|
||||||
}
|
Err(er) => {
|
||||||
_ => {}
|
println!("Error: {:?}", er);
|
||||||
}
|
return Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::Other,
|
||||||
cover_art.path = Some(cover_path.clone());
|
er.to_string(),
|
||||||
|
));
|
||||||
let album = self.retrieve_metadata(&meta_path);
|
}
|
||||||
let trck = i32::from_str(track_id).unwrap();
|
},
|
||||||
let mut s = album.retrieve_song(trck, 1).unwrap();
|
_ => {
|
||||||
s.filepath = Some(fp);
|
return Err(std::io::Error::new(
|
||||||
s.directory = Some(dir);
|
std::io::ErrorKind::Other,
|
||||||
s.genre = Some(album.genre.clone());
|
"No sutitable file found".to_owned(),
|
||||||
s.year = Some(album.year.clone());
|
));
|
||||||
s.album = Some(album.title.clone());
|
|
||||||
s.data = Some(s.to_data().unwrap());
|
|
||||||
|
|
||||||
cover_art.data = Some(cover_art.to_data().unwrap());
|
|
||||||
|
|
||||||
let mut up = syncers::upload::Upload::default();
|
|
||||||
let host = self.ica_action.retrieve_flag_value(&String::from("-h"));
|
|
||||||
up.set_api(&host);
|
|
||||||
|
|
||||||
let res = up.upload_song_with_metadata(&token, &s, &cover_art, &album);
|
|
||||||
let tken = Runtime::new().unwrap().block_on(res);
|
|
||||||
|
|
||||||
match &tken {
|
|
||||||
Ok(o) => {
|
|
||||||
println!("Successfully sent {:?}", o);
|
|
||||||
}
|
|
||||||
Err(er) => {
|
|
||||||
println!("Some error {:?}", er);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
fn get_songs(
|
||||||
|
&self,
|
||||||
|
metadata_path: &String,
|
||||||
|
source_directory: &String,
|
||||||
|
) -> Result<Vec<icarus_models::song::Song>> {
|
||||||
|
match icarus_models::album::collection::parse_album(metadata_path) {
|
||||||
|
Ok(albums) => {
|
||||||
|
let mut songs: Vec<icarus_models::song::Song> = Vec::new();
|
||||||
|
|
||||||
|
for track in &albums.tracks {
|
||||||
|
let filename = if track.track < 10 {
|
||||||
|
"track0".to_owned()
|
||||||
|
+ &track.track.to_string()
|
||||||
|
+ icarus_models::constants::DEFAULTMUSICEXTENSION
|
||||||
|
} else {
|
||||||
|
"track".to_owned()
|
||||||
|
+ &track.track.to_string()
|
||||||
|
+ icarus_models::constants::DEFAULTMUSICEXTENSION
|
||||||
|
};
|
||||||
|
|
||||||
|
songs.push(icarus_models::song::Song {
|
||||||
|
id: -1,
|
||||||
|
title: track.title.clone(),
|
||||||
|
artist: track.artist.clone(),
|
||||||
|
disc: track.disc.clone(),
|
||||||
|
track: track.track.clone(),
|
||||||
|
duration: track.duration.clone() as i32,
|
||||||
|
year: albums.year.clone(),
|
||||||
|
album_artist: albums.artist.clone(),
|
||||||
|
genre: albums.genre.clone(),
|
||||||
|
disc_count: albums.disc_count.clone(),
|
||||||
|
track_count: albums.track_count.clone(),
|
||||||
|
album: albums.title.clone(),
|
||||||
|
audio_type: String::from("FLAC"),
|
||||||
|
directory: source_directory.clone(),
|
||||||
|
filename: filename,
|
||||||
|
user_id: -1,
|
||||||
|
data: Vec::new(),
|
||||||
|
date_created: String::new(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(songs)
|
||||||
|
}
|
||||||
|
Err(_) => Ok(Vec::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn multi_target_upload(&mut self, sourcepath: &String) -> std::io::Result<()> {
|
fn multi_target_upload(&mut self, sourcepath: &String) -> std::io::Result<()> {
|
||||||
@@ -397,150 +469,52 @@ impl CommitManager {
|
|||||||
panic!("Directory does not exist");
|
panic!("Directory does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cover_art = models::song::CoverArt::default();
|
let mut cover_art = icarus_models::coverart::CoverArt {
|
||||||
let mut songs: Vec<models::song::Song> = Vec::new();
|
id: 0,
|
||||||
let mut filenames: Vec<String> = Vec::new();
|
title: String::new(),
|
||||||
let mut metadatapath: String = String::new();
|
path: match self.get_cover_art_path(&sourcepath) {
|
||||||
|
Ok(o) => o,
|
||||||
// iterate files in metadatapath
|
Err(_) => String::new(),
|
||||||
let path = std::path::Path::new(directory_path);
|
},
|
||||||
|
data: Vec::new(),
|
||||||
for entry in read_dir(path)? {
|
};
|
||||||
let entry = entry?;
|
let metadatapath = match self.get_metadata_path(&sourcepath) {
|
||||||
|
Ok(o) => o,
|
||||||
let file_type = entry.file_type();
|
Err(_) => String::new(),
|
||||||
let file_name = entry.file_name();
|
};
|
||||||
|
|
||||||
println!("file type: {:?}", file_type);
|
|
||||||
println!("file name: {:?}", file_name);
|
|
||||||
|
|
||||||
match self.find_file_extension(&file_name) {
|
|
||||||
En::ImageFile => {
|
|
||||||
let directory_part = sourcepath.clone();
|
|
||||||
let fname = self.o_to_string(&file_name);
|
|
||||||
let fullpath = directory_part + "/" + &fname.unwrap();
|
|
||||||
cover_art.path = Some(fullpath);
|
|
||||||
}
|
|
||||||
En::MetadataFile => {
|
|
||||||
let directory_part = sourcepath.clone();
|
|
||||||
let fname = self.o_to_string(&file_name);
|
|
||||||
metadatapath = directory_part + "/" + &fname.unwrap();
|
|
||||||
}
|
|
||||||
En::SongFile => {
|
|
||||||
let mut song = models::song::Song::default();
|
|
||||||
let fname = self.o_to_string(&file_name);
|
|
||||||
|
|
||||||
match fname {
|
|
||||||
Ok(s) => {
|
|
||||||
filenames.push(s.clone());
|
|
||||||
song.filepath = Some(s.clone());
|
|
||||||
song.directory = Some(sourcepath.clone());
|
|
||||||
song.data = Some(song.to_data().unwrap());
|
|
||||||
self.initialize_disc_and_track(&mut song);
|
|
||||||
}
|
|
||||||
Err(er) => println!("Error: {:?}", er),
|
|
||||||
}
|
|
||||||
|
|
||||||
songs.push(song)
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
filenames.sort();
|
|
||||||
|
|
||||||
let mut album = self.retrieve_metadata(&metadatapath);
|
|
||||||
|
|
||||||
self.song_parsing(&mut album, &sourcepath, &filenames);
|
|
||||||
|
|
||||||
let mut up = syncers::upload::Upload::default();
|
let mut up = syncers::upload::Upload::default();
|
||||||
let host = self.ica_action.retrieve_flag_value(&String::from("-h"));
|
let host = self.ica_action.retrieve_flag_value(&String::from("-h"));
|
||||||
up.set_api(&host);
|
up.set_api(&host);
|
||||||
|
|
||||||
cover_art.data = Some(cover_art.to_data().unwrap());
|
cover_art.data = cover_art.to_data().unwrap();
|
||||||
|
|
||||||
println!("");
|
println!("");
|
||||||
|
|
||||||
for sng in &mut album.songs {
|
match self.get_songs(&metadatapath, &sourcepath) {
|
||||||
match sng.data {
|
Ok(sngs) => {
|
||||||
Some(_) => {}
|
for song in sngs {
|
||||||
None => {
|
match Runtime::new()
|
||||||
sng.data = Some(sng.to_data().unwrap());
|
.unwrap()
|
||||||
}
|
.block_on(up.upload_song_with_metadata(&token, &song, &cover_art))
|
||||||
};
|
{
|
||||||
}
|
Ok(o) => {
|
||||||
|
println!("Response: {:?}", o);
|
||||||
for song in &album.songs {
|
}
|
||||||
// Upload each song
|
Err(err) => {
|
||||||
println!("Sending song...");
|
println!("Error: {:?}", err);
|
||||||
let res = up.upload_song_with_metadata(&token, &song, &cover_art, &album);
|
}
|
||||||
let tken = Runtime::new().unwrap().block_on(res);
|
};
|
||||||
|
|
||||||
match &tken {
|
|
||||||
Ok(o) => {
|
|
||||||
println!("Successfully sent {:?}", o);
|
|
||||||
}
|
|
||||||
Err(er) => {
|
|
||||||
println!("Some error {:?}", er);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(error) => {
|
||||||
println!("");
|
println!("Error: {:?}", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes sure the elements in album.songs is populated
|
|
||||||
fn song_parsing(
|
|
||||||
&self,
|
|
||||||
album: &mut models::song::Album,
|
|
||||||
directory: &String,
|
|
||||||
filenames: &Vec<String>,
|
|
||||||
) {
|
|
||||||
// Apply directory
|
|
||||||
for song in &mut album.songs {
|
|
||||||
let dir = &song.directory;
|
|
||||||
match dir {
|
|
||||||
Some(s) => println!("{}", s),
|
|
||||||
None => {
|
|
||||||
song.directory = Some(directory.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply filename
|
|
||||||
let mut index = 0;
|
|
||||||
for song in &mut album.songs {
|
|
||||||
let filename = filenames[index].clone();
|
|
||||||
song.filepath = Some(filename);
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for song in &mut album.songs {
|
|
||||||
match &mut song.album {
|
|
||||||
Some(_) => {}
|
|
||||||
None => {
|
|
||||||
song.album = Some(album.title.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match &mut song.genre {
|
|
||||||
Some(_) => {}
|
|
||||||
None => {
|
|
||||||
song.genre = Some(album.genre.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match &mut song.year {
|
|
||||||
Some(_) => {}
|
|
||||||
None => {
|
|
||||||
song.year = Some(album.year.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_file_extension(&self, file_name: &std::ffi::OsString) -> En {
|
fn find_file_extension(&self, file_name: &std::ffi::OsString) -> En {
|
||||||
let file_name_str = Some(file_name.clone().into_string());
|
let file_name_str = Some(file_name.clone().into_string());
|
||||||
|
|
||||||
@@ -566,11 +540,16 @@ impl CommitManager {
|
|||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if extension == "wav" || extension == "flac" {
|
if extension == icarus_models::constants::WAVEXTENSION[1..]
|
||||||
|
|| extension == icarus_models::constants::FLACEXTENSION[1..]
|
||||||
|
{
|
||||||
return En::SongFile;
|
return En::SongFile;
|
||||||
} else if extension == "json" {
|
} else if extension == "json" {
|
||||||
return En::MetadataFile;
|
return En::MetadataFile;
|
||||||
} else if extension == "jpg" || extension == "jpeg" || extension == "png" {
|
} else if extension == icarus_models::constants::JPGEXTENSION[1..]
|
||||||
|
|| extension == "jpeg"
|
||||||
|
|| extension == "png"
|
||||||
|
{
|
||||||
return En::ImageFile;
|
return En::ImageFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,139 +561,51 @@ impl CommitManager {
|
|||||||
return En::Other;
|
return En::Other;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn o_to_string(&self, val: &std::ffi::OsString) -> Result<std::string::String> {
|
fn get_cover_art_path(&self, directory_path: &String) -> Result<String> {
|
||||||
let res = val.clone().into_string();
|
for entry in read_dir(std::path::Path::new(directory_path))? {
|
||||||
return match res {
|
let entry = entry?;
|
||||||
Ok(sss) => Ok(sss),
|
|
||||||
Err(_) => Ok(String::from("Error")),
|
let file_type = entry.file_type();
|
||||||
};
|
let file_name = entry.file_name();
|
||||||
|
|
||||||
|
println!("file type: {:?}", file_type);
|
||||||
|
println!("file name: {:?}", file_name);
|
||||||
|
|
||||||
|
match self.find_file_extension(&file_name) {
|
||||||
|
En::ImageFile => {
|
||||||
|
let directory_part = directory_path.clone();
|
||||||
|
let fname = utilities::string::o_to_string(&file_name);
|
||||||
|
let fullpath = directory_part + "/" + &fname.unwrap();
|
||||||
|
return Ok(fullpath);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(String::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standards
|
fn get_metadata_path(&self, directory_path: &String) -> Result<String> {
|
||||||
// * track01.cdda.wav - Disc 1, Track 1
|
for entry in read_dir(std::path::Path::new(directory_path))? {
|
||||||
// * track02d02.cdda.wav - Disc 2, Track 2
|
let entry = entry?;
|
||||||
fn initialize_disc_and_track(&mut self, song: &mut models::song::Song) {
|
|
||||||
let mut disc = 1;
|
|
||||||
let mut track = 1;
|
|
||||||
let mut mode = 0;
|
|
||||||
let filename =
|
|
||||||
&<std::option::Option<std::string::String> as Clone>::clone(&song.filepath).unwrap();
|
|
||||||
|
|
||||||
let trd = filename.contains("trackd");
|
let file_type = entry.file_type();
|
||||||
let tr = filename.contains("track");
|
let file_name = entry.file_name();
|
||||||
|
|
||||||
if tr {
|
println!("file type: {:?}", file_type);
|
||||||
mode = 1;
|
println!("file name: {:?}", file_name);
|
||||||
}
|
|
||||||
|
|
||||||
if trd {
|
match self.find_file_extension(&file_name) {
|
||||||
mode = 2;
|
En::MetadataFile => {
|
||||||
}
|
let directory_part = directory_path.clone();
|
||||||
|
let fname = utilities::string::o_to_string(&file_name);
|
||||||
let dl = |a: &char, b: &char| -> bool {
|
return Ok(directory_part + "/" + &fname.unwrap());
|
||||||
return a == b;
|
|
||||||
};
|
|
||||||
let d = utilities::checks::Checks::index_of_item_in_container(&filename, &'d', dl);
|
|
||||||
let k = utilities::checks::Checks::index_of_item_in_container(&filename, &'k', dl);
|
|
||||||
let dot = utilities::checks::Checks::index_of_item_in_container(&filename, &'.', dl);
|
|
||||||
let end = filename.len() as i32;
|
|
||||||
|
|
||||||
match mode {
|
|
||||||
1 => {
|
|
||||||
if k != end && dot != end {
|
|
||||||
let st = k + 1;
|
|
||||||
let ed = dot - 1;
|
|
||||||
let mut t: String = String::new();
|
|
||||||
let mut index = 0;
|
|
||||||
for a in filename.chars() {
|
|
||||||
if index >= st && index <= ed {
|
|
||||||
t.push(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if utilities::checks::Checks::is_numeric(&t) {
|
|
||||||
track = t.parse::<i32>().unwrap();
|
|
||||||
}
|
|
||||||
disc = 1
|
|
||||||
}
|
}
|
||||||
}
|
_ => {}
|
||||||
2 => {
|
|
||||||
if k != end && dot != end && d != end {
|
|
||||||
let st = k + 1;
|
|
||||||
let ed = dot - 1;
|
|
||||||
let mut t: String = String::new();
|
|
||||||
let mut index = 0;
|
|
||||||
for a in filename.chars() {
|
|
||||||
if index <= ed {
|
|
||||||
t.push(a);
|
|
||||||
} else if index >= st {
|
|
||||||
t.push(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if utilities::checks::Checks::is_numeric(&t) {
|
|
||||||
track = t.parse::<i32>().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let sst = d + 1;
|
|
||||||
let eed = dot;
|
|
||||||
let mut d_s = String::new();
|
|
||||||
index = 0;
|
|
||||||
for a in filename.chars() {
|
|
||||||
if index <= eed {
|
|
||||||
d_s.push(a);
|
|
||||||
} else if index >= sst {
|
|
||||||
d_s.push(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if utilities::checks::Checks::is_numeric(&d_s) {
|
|
||||||
track = d_s.parse::<i32>().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => println!(""),
|
|
||||||
}
|
|
||||||
|
|
||||||
song.disc = Some(disc);
|
|
||||||
song.track = Some(track);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn _parse_disc_and_track(&self, song: &mut models::song::Song, track_id: &String) {
|
|
||||||
let sep = |_a: &char, _b: &char| -> bool {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
let index = utilities::checks::Checks::index_of_item_in_container(track_id, &':', sep);
|
|
||||||
|
|
||||||
if index == -1 {
|
|
||||||
let mut d_str: String = String::new();
|
|
||||||
let t_str = String::new();
|
|
||||||
|
|
||||||
for c in track_id.chars().skip(0).take(index as usize) {
|
|
||||||
d_str.push(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
let start = index + 1;
|
|
||||||
let end = track_id.len() - 1;
|
|
||||||
|
|
||||||
for c in track_id.chars().skip(start as usize).take(end as usize) {
|
|
||||||
d_str.push(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
song.disc = Some(d_str.parse::<i32>().unwrap());
|
|
||||||
song.track = Some(t_str.parse::<i32>().unwrap());
|
|
||||||
} else {
|
|
||||||
if utilities::checks::Checks::is_numeric(track_id) {
|
|
||||||
song.track = Some(track_id.parse::<i32>().unwrap());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(String::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _check_for_no_confirm(&self) -> bool {
|
fn _check_for_no_confirm(&self) -> bool {
|
||||||
@@ -725,21 +616,4 @@ impl CommitManager {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_metadata(&self, path: &String) -> Album {
|
|
||||||
let content = self.retrieve_file_content(&path);
|
|
||||||
let val = content.unwrap();
|
|
||||||
|
|
||||||
let converted = serde_json::from_str(&val);
|
|
||||||
|
|
||||||
match &converted {
|
|
||||||
Ok(_) => println!("Good!"),
|
|
||||||
Err(er) => println!("Error {:?}", er),
|
|
||||||
}
|
|
||||||
return converted.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn retrieve_file_content(&self, path: &String) -> Result<String> {
|
|
||||||
return std::fs::read_to_string(path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
use std::default::Default;
|
|
||||||
|
|
||||||
|
|
||||||
pub struct FileManager {
|
|
||||||
pub filepath: String,
|
|
||||||
pub filebuffer: String,
|
|
||||||
pub file_read: bool,
|
|
||||||
pub file_buffer_length: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for FileManager {
|
|
||||||
fn default() -> Self {
|
|
||||||
FileManager {
|
|
||||||
filepath: String::new(),
|
|
||||||
filebuffer: String::new(),
|
|
||||||
file_read: false,
|
|
||||||
file_buffer_length: -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl FileManager {
|
|
||||||
// TODO: Implement
|
|
||||||
pub fn init(&mut self) {
|
|
||||||
self.read_file()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn save_file(&mut self, filepath: &String) {
|
|
||||||
if !self.file_read {
|
|
||||||
self.read_file();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut file = File::open(filepath)?;
|
|
||||||
let mut buffer = Vec::new();
|
|
||||||
file.read_to_end(&mut buffer)?;
|
|
||||||
self.file_buffer_length = buffer.len();
|
|
||||||
self.filebuffer = String::from_utf8(buffer); // Assuming UTF-8 encoding
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn modify_file_path(&mut self, file: &String) {
|
|
||||||
self.filepath = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn retrieve_file_buffer(&self) -> String {
|
|
||||||
self.filebuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn retrieve_file_length(&self) -> i32 {
|
|
||||||
self.file_buffer_length;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_file(&mut self) -> Vec<u8> {
|
|
||||||
let mut file = File::open(self.filepath)?;
|
|
||||||
let mut buffer = Vec::new();
|
|
||||||
file.read_to_end(&mut buffer)?;
|
|
||||||
self.file_buffer_length = buffer.len();
|
|
||||||
self.filebuffer = String::from_utf8(buffer); // Assuming UTF-8 encoding
|
|
||||||
self.file_read = true;
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -3,14 +3,14 @@ use std::default::Default;
|
|||||||
use crate::models;
|
use crate::models;
|
||||||
|
|
||||||
pub struct TokenManager {
|
pub struct TokenManager {
|
||||||
pub user: models::user::User,
|
pub user: icarus_models::user::User,
|
||||||
pub api: models::api::API,
|
pub api: models::api::API,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TokenManager {
|
impl Default for TokenManager {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let mut token = TokenManager {
|
let mut token = TokenManager {
|
||||||
user: models::user::User::default(),
|
user: icarus_models::user::User::default(),
|
||||||
api: models::api::API::default(),
|
api: models::api::API::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -21,14 +21,21 @@ impl Default for TokenManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TokenManager {
|
impl TokenManager {
|
||||||
pub async fn request_token(&self) -> Result<models::token::Token, std::io::Error> {
|
pub async fn request_token(&self) -> Result<icarus_models::token::AccessToken, std::io::Error> {
|
||||||
println!("Sending request for a token");
|
println!("Sending request for a token");
|
||||||
|
|
||||||
let url = self.retrieve_url();
|
let url = self.retrieve_url();
|
||||||
|
|
||||||
println!("URL: {}", url);
|
println!("URL: {}", url);
|
||||||
|
|
||||||
let mut token = models::token::Token::default();
|
let mut token = icarus_models::token::AccessToken {
|
||||||
|
user_id: -1,
|
||||||
|
username: String::new(),
|
||||||
|
token: String::new(),
|
||||||
|
token_type: String::new(),
|
||||||
|
expiration: -1,
|
||||||
|
message: String::new(),
|
||||||
|
};
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let response = client.post(&url).json(&self.user).send().await.unwrap();
|
let response = client.post(&url).json(&self.user).send().await.unwrap();
|
||||||
@@ -36,7 +43,7 @@ impl TokenManager {
|
|||||||
match response.status() {
|
match response.status() {
|
||||||
reqwest::StatusCode::OK => {
|
reqwest::StatusCode::OK => {
|
||||||
// on success, parse our JSON to an APIResponse
|
// on success, parse our JSON to an APIResponse
|
||||||
let s = response.json::<models::token::Token>().await;
|
let s = response.json::<icarus_models::token::AccessToken>().await;
|
||||||
match s {
|
match s {
|
||||||
//
|
//
|
||||||
Ok(parsed) => {
|
Ok(parsed) => {
|
||||||
@@ -66,7 +73,6 @@ impl TokenManager {
|
|||||||
let api = &self.api;
|
let api = &self.api;
|
||||||
let mut url = String::from(&api.url);
|
let mut url = String::from(&api.url);
|
||||||
url += &String::from(&api.endpoint);
|
url += &String::from(&api.endpoint);
|
||||||
url += &String::from("/");
|
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,36 +6,42 @@ use crate::models::{self};
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct UserManager {
|
pub struct UserManager {
|
||||||
pub user: models::user::User,
|
pub user: icarus_models::user::User,
|
||||||
pub ica_action: models::icarus_action::IcarusAction,
|
pub ica_action: models::icarus_action::IcarusAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UserManager {
|
impl Default for UserManager {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
UserManager {
|
UserManager {
|
||||||
user: models::user::User::default(),
|
user: icarus_models::user::User::default(),
|
||||||
ica_action: models::icarus_action::IcarusAction::default(),
|
ica_action: models::icarus_action::IcarusAction::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserManager {
|
impl UserManager {
|
||||||
pub fn retrieve_user(&self) -> models::user::User {
|
pub fn retrieve_user(&self) -> icarus_models::user::User {
|
||||||
return self.user.clone();
|
return self.user.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_user_from_actions(&mut self) {
|
pub fn parse_user_from_actions(&mut self) {
|
||||||
let args = &self.ica_action.flags;
|
let args = &self.ica_action.flags;
|
||||||
|
|
||||||
|
// Quit the loop when two are found
|
||||||
|
let mut amt: i32 = 0;
|
||||||
for arg in args {
|
for arg in args {
|
||||||
let flag = &arg.flag;
|
let flag = &arg.flag;
|
||||||
|
|
||||||
if flag == "-u" {
|
if flag == "-u" {
|
||||||
self.user.username = String::from(&arg.value);
|
self.user.username = String::from(&arg.value);
|
||||||
|
amt += 1;
|
||||||
|
} else if flag == "-p" {
|
||||||
|
self.user.password = String::from(&arg.value);
|
||||||
|
amt += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag == "-p" {
|
if amt == 2 {
|
||||||
self.user.password = String::from(&arg.value);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod flags;
|
pub mod flags;
|
||||||
pub mod icarus_action;
|
pub mod icarus_action;
|
||||||
pub mod song;
|
|
||||||
pub mod token;
|
|
||||||
pub mod upload_form;
|
pub mod upload_form;
|
||||||
pub mod user;
|
|
||||||
|
|||||||
@@ -1,171 +0,0 @@
|
|||||||
use std::default::Default;
|
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::constants;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Song {
|
|
||||||
#[serde(alias = "song_id")]
|
|
||||||
pub id: Option<i32>,
|
|
||||||
pub title: Option<String>,
|
|
||||||
pub artist: Option<String>,
|
|
||||||
pub album: Option<String>,
|
|
||||||
pub genre: Option<String>,
|
|
||||||
pub year: Option<i32>,
|
|
||||||
pub duration: Option<f64>,
|
|
||||||
pub track: Option<i32>,
|
|
||||||
pub disc: Option<i32>,
|
|
||||||
pub data: Option<Vec<u8>>,
|
|
||||||
pub filepath: Option<String>,
|
|
||||||
pub directory: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Album {
|
|
||||||
#[serde(alias = "album")]
|
|
||||||
pub title: String,
|
|
||||||
pub album_artist: String,
|
|
||||||
pub genre: String,
|
|
||||||
pub year: i32,
|
|
||||||
pub track_count: i32,
|
|
||||||
pub disc_count: i32,
|
|
||||||
#[serde(alias = "tracks")]
|
|
||||||
pub songs: Vec<Song>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Album {
|
|
||||||
fn default() -> Self {
|
|
||||||
Album {
|
|
||||||
title: String::new(),
|
|
||||||
album_artist: String::new(),
|
|
||||||
genre: String::new(),
|
|
||||||
year: 0,
|
|
||||||
track_count: 0,
|
|
||||||
disc_count: 0,
|
|
||||||
songs: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Song {
|
|
||||||
fn default() -> Self {
|
|
||||||
Song {
|
|
||||||
id: None,
|
|
||||||
title: None,
|
|
||||||
artist: None,
|
|
||||||
album: None,
|
|
||||||
genre: None,
|
|
||||||
year: None,
|
|
||||||
duration: None,
|
|
||||||
track: None,
|
|
||||||
disc: None,
|
|
||||||
data: None,
|
|
||||||
filepath: None,
|
|
||||||
directory: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Song {
|
|
||||||
pub fn print_info(&self) {
|
|
||||||
println!("Title: {:?}", self.title);
|
|
||||||
println!("Artist: {:?}", self.artist);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn song_path(&self) -> String {
|
|
||||||
let directory =
|
|
||||||
&<std::option::Option<std::string::String> as Clone>::clone(&self.directory).unwrap();
|
|
||||||
|
|
||||||
let mut buffer: String = directory.to_string();
|
|
||||||
let count = buffer.len();
|
|
||||||
|
|
||||||
if buffer.chars().nth(count - 1) != Some('/') {
|
|
||||||
buffer += "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
let filename =
|
|
||||||
&<std::option::Option<std::string::String> as Clone>::clone(&self.filepath).unwrap();
|
|
||||||
buffer += filename;
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
|
|
||||||
let path = self.song_path();
|
|
||||||
println!("Converting song to data");
|
|
||||||
println!("Path: {:?}", path);
|
|
||||||
|
|
||||||
let mut file = std::fs::File::open(path)?;
|
|
||||||
let mut buffer = Vec::new();
|
|
||||||
file.read_to_end(&mut buffer)?;
|
|
||||||
if buffer.len() == 0 {
|
|
||||||
println!("Why is it empty?");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
// if 1 - wav, if 0 - mp3, anything else defaults to wav
|
|
||||||
pub fn _generate_filename_from_track(&mut self, i_type: i32) -> i32 {
|
|
||||||
let mut filename: String = String::new();
|
|
||||||
if self.track.unwrap() < 10 {
|
|
||||||
filename += "0";
|
|
||||||
}
|
|
||||||
|
|
||||||
filename += &self.track.unwrap().to_string();
|
|
||||||
|
|
||||||
if i_type == 0 {
|
|
||||||
filename += constants::file_extensions::_MP3_FILE_EXTENSION;
|
|
||||||
} else {
|
|
||||||
filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.filepath = Some(filename);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn _to_metadata_json(&self) -> Result<String, serde_json::Error> {
|
|
||||||
return serde_json::to_string_pretty(&self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
|
||||||
pub struct CoverArt {
|
|
||||||
pub id: Option<i32>,
|
|
||||||
pub title: Option<String>,
|
|
||||||
pub path: Option<String>,
|
|
||||||
pub data: Option<Vec<u8>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for CoverArt {
|
|
||||||
fn default() -> Self {
|
|
||||||
CoverArt {
|
|
||||||
id: None,
|
|
||||||
title: None,
|
|
||||||
path: None,
|
|
||||||
data: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CoverArt {
|
|
||||||
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
|
|
||||||
let mut path: String = String::new();
|
|
||||||
match &self.path {
|
|
||||||
Some(val) => {
|
|
||||||
path = String::from(val);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut file = std::fs::File::open(path)?;
|
|
||||||
let mut buffer = Vec::new();
|
|
||||||
file.read_to_end(&mut buffer)?;
|
|
||||||
Ok(buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
use std::default::Default;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Token {
|
|
||||||
#[serde(alias = "user_id")]
|
|
||||||
pub user_id: i32,
|
|
||||||
#[serde(alias = "username")]
|
|
||||||
pub username: Option<String>,
|
|
||||||
#[serde(alias = "token")]
|
|
||||||
pub access_token: Option<String>,
|
|
||||||
#[serde(alias = "token_type")]
|
|
||||||
pub token_type: Option<String>,
|
|
||||||
#[serde(alias = "expiration")]
|
|
||||||
pub expiration: Option<i32>,
|
|
||||||
#[serde(alias = "message")]
|
|
||||||
pub message: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Token {
|
|
||||||
fn default() -> Self {
|
|
||||||
Token {
|
|
||||||
user_id: -1,
|
|
||||||
username: None,
|
|
||||||
access_token: None,
|
|
||||||
token_type: None,
|
|
||||||
expiration: None,
|
|
||||||
message: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Token {
|
|
||||||
pub fn bearer_token(&self) -> String {
|
|
||||||
let mut token: String = String::from("Bearer ");
|
|
||||||
|
|
||||||
match &self.access_token {
|
|
||||||
Some(tok) => {
|
|
||||||
token += tok;
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
use std::default::Default;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct User {
|
|
||||||
pub username: String,
|
|
||||||
pub password: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for User {
|
|
||||||
fn default() -> Self {
|
|
||||||
User {
|
|
||||||
username: String::new(),
|
|
||||||
password: String::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl User {
|
|
||||||
pub fn _to_json(&self) -> Result<String, serde_json::Error> {
|
|
||||||
return serde_json::to_string_pretty(&self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,9 +20,9 @@ impl Default for Delete {
|
|||||||
impl Delete {
|
impl Delete {
|
||||||
pub async fn delete_song(
|
pub async fn delete_song(
|
||||||
&mut self,
|
&mut self,
|
||||||
token: &models::token::Token,
|
token: &icarus_models::token::AccessToken,
|
||||||
song: &models::song::Song,
|
song: &icarus_models::song::Song,
|
||||||
) -> Result<models::song::Song, std::io::Error> {
|
) -> Result<icarus_models::song::Song, std::io::Error> {
|
||||||
self.api.endpoint = "song/data/delete".to_owned();
|
self.api.endpoint = "song/data/delete".to_owned();
|
||||||
let url = self.retrieve_url(&song);
|
let url = self.retrieve_url(&song);
|
||||||
let client = reqwest::Client::builder().build().unwrap();
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
@@ -33,14 +33,13 @@ impl Delete {
|
|||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut sng = models::song::Song::default();
|
let mut sng = icarus_models::song::Song::default();
|
||||||
|
|
||||||
match response.status() {
|
match response.status() {
|
||||||
reqwest::StatusCode::OK => {
|
reqwest::StatusCode::OK => {
|
||||||
println!("Success!");
|
println!("Success!");
|
||||||
let s = response.json::<models::song::Song>().await;
|
let s = response.json::<icarus_models::song::Song>().await;
|
||||||
match s {
|
match s {
|
||||||
//
|
|
||||||
Ok(parsed) => {
|
Ok(parsed) => {
|
||||||
sng = parsed;
|
sng = parsed;
|
||||||
}
|
}
|
||||||
@@ -57,7 +56,7 @@ impl Delete {
|
|||||||
return Ok(sng);
|
return Ok(sng);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_url(&self, song: &models::song::Song) -> String {
|
fn retrieve_url(&self, song: &icarus_models::song::Song) -> String {
|
||||||
let api = &self.api;
|
let api = &self.api;
|
||||||
let mut url: String = String::from(&api.url);
|
let mut url: String = String::from(&api.url);
|
||||||
url += &String::from("api/");
|
url += &String::from("api/");
|
||||||
@@ -65,7 +64,7 @@ impl Delete {
|
|||||||
url += &String::from("/");
|
url += &String::from("/");
|
||||||
url += &String::from(&api.endpoint);
|
url += &String::from(&api.endpoint);
|
||||||
url += &String::from("/");
|
url += &String::from("/");
|
||||||
url += &song.id.unwrap().to_string();
|
url += &song.id.to_string();
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-22
@@ -16,15 +16,15 @@ impl Default for Download {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum MyError {
|
pub enum MyError {
|
||||||
_Request(reqwest::Error),
|
Request(reqwest::Error),
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Download {
|
impl Download {
|
||||||
pub async fn download_song(
|
pub async fn download_song(
|
||||||
&mut self,
|
&mut self,
|
||||||
token: &models::token::Token,
|
token: &icarus_models::token::AccessToken,
|
||||||
song: &models::song::Song,
|
song: &icarus_models::song::Song,
|
||||||
) -> Result<String, MyError> {
|
) -> Result<String, MyError> {
|
||||||
self.api.endpoint = String::from("song/data/download");
|
self.api.endpoint = String::from("song/data/download");
|
||||||
let url = self.retrieve_url(&song);
|
let url = self.retrieve_url(&song);
|
||||||
@@ -41,33 +41,37 @@ impl Download {
|
|||||||
.get(&url)
|
.get(&url)
|
||||||
.header(reqwest::header::AUTHORIZATION, &access_token)
|
.header(reqwest::header::AUTHORIZATION, &access_token)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
match response.status() {
|
match response {
|
||||||
reqwest::StatusCode::OK => {
|
Ok(rep) => match rep.status() {
|
||||||
let data = response.text();
|
reqwest::StatusCode::OK => {
|
||||||
match data.await {
|
let data = rep.text();
|
||||||
Ok(e) => {
|
match data.await {
|
||||||
return Ok(e);
|
Ok(e) => {
|
||||||
}
|
return Ok(e);
|
||||||
Err(er) => {
|
}
|
||||||
println!("Error {:?}", er);
|
Err(er) => {
|
||||||
|
println!("Error {:?}", er);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
reqwest::StatusCode::UNAUTHORIZED => {
|
||||||
reqwest::StatusCode::UNAUTHORIZED => {
|
println!("Need to grab a new token");
|
||||||
println!("Need to grab a new token");
|
}
|
||||||
}
|
other => {
|
||||||
other => {
|
panic!("Uh oh! Something unexpected happened: {:?}", other);
|
||||||
panic!("Uh oh! Something unexpected happened: {:?}", other);
|
}
|
||||||
|
},
|
||||||
|
Err(er) => {
|
||||||
|
return Err(MyError::Request(er));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Err(MyError::Other(String::from("Error downloading")));
|
return Err(MyError::Other(String::from("Error downloading")));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_url(&self, song: &models::song::Song) -> String {
|
fn retrieve_url(&self, song: &icarus_models::song::Song) -> String {
|
||||||
let api = &self.api;
|
let api = &self.api;
|
||||||
let mut url: String = String::from(&api.url);
|
let mut url: String = String::from(&api.url);
|
||||||
url += &String::from("api/");
|
url += &String::from("api/");
|
||||||
@@ -75,7 +79,7 @@ impl Download {
|
|||||||
url += &String::from("/");
|
url += &String::from("/");
|
||||||
url += &String::from(&api.endpoint);
|
url += &String::from(&api.endpoint);
|
||||||
url += &String::from("/");
|
url += &String::from("/");
|
||||||
url += &song.id.unwrap().to_string();
|
url += &song.id.to_string();
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ impl Default for RetrieveRecords {
|
|||||||
impl RetrieveRecords {
|
impl RetrieveRecords {
|
||||||
pub async fn get_all_songs(
|
pub async fn get_all_songs(
|
||||||
&mut self,
|
&mut self,
|
||||||
token: &models::token::Token,
|
token: &icarus_models::token::AccessToken,
|
||||||
) -> Result<Vec<models::song::Song>, Error> {
|
) -> Result<Vec<icarus_models::song::Song>, Error> {
|
||||||
self.api.endpoint = String::from("song");
|
self.api.endpoint = String::from("song");
|
||||||
let mut songs: Vec<models::song::Song> = Vec::new();
|
let mut songs: Vec<icarus_models::song::Song> = Vec::new();
|
||||||
let url = self.retrieve_url();
|
let url = self.retrieve_url();
|
||||||
let access_token = token.bearer_token();
|
let access_token = token.bearer_token();
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ impl RetrieveRecords {
|
|||||||
match response.status() {
|
match response.status() {
|
||||||
reqwest::StatusCode::OK => {
|
reqwest::StatusCode::OK => {
|
||||||
// on success, parse our JSON to an APIResponse
|
// on success, parse our JSON to an APIResponse
|
||||||
let s = response.json::<Vec<models::song::Song>>().await;
|
let s = response.json::<Vec<icarus_models::song::Song>>().await;
|
||||||
match s {
|
match s {
|
||||||
//
|
//
|
||||||
Ok(parsed) => {
|
Ok(parsed) => {
|
||||||
|
|||||||
+32
-100
@@ -1,41 +1,14 @@
|
|||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
use http::HeaderMap;
|
|
||||||
use http::HeaderValue;
|
use http::HeaderValue;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use reqwest::multipart::Form;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::constants;
|
|
||||||
use crate::models;
|
use crate::models;
|
||||||
|
|
||||||
pub struct Upload {
|
pub struct Upload {
|
||||||
pub api: models::api::API,
|
pub api: models::api::API,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
|
||||||
struct Song {
|
|
||||||
title: String,
|
|
||||||
album: String,
|
|
||||||
artist: String,
|
|
||||||
album_artist: String,
|
|
||||||
year: i32,
|
|
||||||
genre: String,
|
|
||||||
duration: i32,
|
|
||||||
track: i32,
|
|
||||||
track_count: i32,
|
|
||||||
disc: i32,
|
|
||||||
disc_count: i32,
|
|
||||||
#[serde(skip_serializing)]
|
|
||||||
songpath: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Song {
|
|
||||||
pub fn to_metadata_json(&self) -> Result<String, serde_json::Error> {
|
|
||||||
return serde_json::to_string_pretty(&self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Upload {
|
impl Default for Upload {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Upload {
|
Upload {
|
||||||
@@ -47,15 +20,12 @@ impl Default for Upload {
|
|||||||
impl Upload {
|
impl Upload {
|
||||||
pub async fn upload_song_with_metadata(
|
pub async fn upload_song_with_metadata(
|
||||||
&mut self,
|
&mut self,
|
||||||
token: &models::token::Token,
|
token: &icarus_models::token::AccessToken,
|
||||||
song: &models::song::Song,
|
song: &icarus_models::song::Song,
|
||||||
cover: &models::song::CoverArt,
|
cover: &icarus_models::coverart::CoverArt,
|
||||||
album: &models::song::Album,
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
) -> Result<reqwest::Response, std::io::Error> {
|
|
||||||
self.api.endpoint = String::from("song/data/upload/with/data");
|
self.api.endpoint = String::from("song/data/upload/with/data");
|
||||||
let url = self.retrieve_url();
|
let url = self.retrieve_url();
|
||||||
let mut new_song = self.initialize_song(&song, &album);
|
|
||||||
new_song.songpath = song.song_path();
|
|
||||||
let access_token = token.bearer_token();
|
let access_token = token.bearer_token();
|
||||||
|
|
||||||
if url.is_empty() {
|
if url.is_empty() {
|
||||||
@@ -64,6 +34,7 @@ impl Upload {
|
|||||||
|
|
||||||
println!("Url: {}", url);
|
println!("Url: {}", url);
|
||||||
println!("Token: {}", access_token);
|
println!("Token: {}", access_token);
|
||||||
|
println!("Path: {:?}", song.song_path());
|
||||||
|
|
||||||
let mut headers = reqwest::header::HeaderMap::new();
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
headers.insert(
|
headers.insert(
|
||||||
@@ -72,65 +43,46 @@ impl Upload {
|
|||||||
);
|
);
|
||||||
headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*"));
|
headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*"));
|
||||||
|
|
||||||
let form = self.init_form(&new_song, &cover);
|
let form = self.init_form(&song, &cover);
|
||||||
let client = reqwest::Client::builder().build().unwrap();
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
let response = client
|
match client
|
||||||
.post(url)
|
.post(url)
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.multipart(form)
|
.multipart(form)
|
||||||
.send()
|
.send()
|
||||||
.await;
|
.await
|
||||||
let response_text = response.unwrap();
|
{
|
||||||
|
Ok(r) => {
|
||||||
println!("Something was sent");
|
return Ok(r);
|
||||||
println!("{:?}", response_text);
|
}
|
||||||
|
Err(err) => {
|
||||||
return Ok(response_text);
|
return Err(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _initialize_form(
|
fn init_form(
|
||||||
&self,
|
&self,
|
||||||
song_raw_data: Vec<u8>,
|
song: &icarus_models::song::Song,
|
||||||
cover_raw_data: Vec<u8>,
|
cover: &icarus_models::coverart::CoverArt,
|
||||||
song_detail: String,
|
) -> reqwest::multipart::Form {
|
||||||
) -> Form {
|
let songpath = match song.song_path() {
|
||||||
let mut headers = HeaderMap::new();
|
Ok(s) => s,
|
||||||
headers.insert(
|
Err(_) => String::new(),
|
||||||
http::header::CONTENT_TYPE,
|
};
|
||||||
http::HeaderValue::from_static("application/octet-stream"),
|
let coverpath = cover.path.clone();
|
||||||
);
|
println!("Cover path: {:?}", coverpath);
|
||||||
|
let song_detail = match song.to_metadata_json(true) {
|
||||||
let file = reqwest::multipart::Part::bytes(song_raw_data).headers(headers);
|
Ok(s) => s,
|
||||||
let mut headers_i = HeaderMap::new();
|
Err(_) => String::new(),
|
||||||
headers_i.insert(
|
};
|
||||||
http::header::CONTENT_TYPE,
|
|
||||||
http::HeaderValue::from_static("image/jpeg"),
|
|
||||||
);
|
|
||||||
|
|
||||||
let cover = reqwest::multipart::Part::bytes(cover_raw_data).headers(headers_i);
|
|
||||||
|
|
||||||
let mut song_filename = String::from("audio");
|
|
||||||
song_filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
|
||||||
let mut cover_filename = String::from("cover");
|
|
||||||
cover_filename += constants::file_extensions::JPG_FILE_EXTENSION;
|
|
||||||
|
|
||||||
return reqwest::multipart::Form::new()
|
|
||||||
.part("cover", cover.file_name(cover_filename))
|
|
||||||
.text("metadata", song_detail)
|
|
||||||
.part("file", file.file_name(song_filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init_form(&self, song: &Song, cover: &models::song::CoverArt) -> reqwest::multipart::Form {
|
|
||||||
let songpath = song.songpath.clone();
|
|
||||||
let coverpath = cover.path.clone().unwrap();
|
|
||||||
let song_detail = song.to_metadata_json().unwrap();
|
|
||||||
|
|
||||||
println!("\n{}\n", song_detail);
|
println!("\n{}\n", song_detail);
|
||||||
|
|
||||||
let mut song_filename = String::from("audio");
|
let mut song_filename = String::from("audio");
|
||||||
song_filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
song_filename += icarus_models::constants::DEFAULTMUSICEXTENSION;
|
||||||
let mut cover_filename = String::from("cover");
|
let mut cover_filename = String::from("cover");
|
||||||
cover_filename += constants::file_extensions::JPG_FILE_EXTENSION;
|
cover_filename += icarus_models::constants::JPGEXTENSION;
|
||||||
|
|
||||||
let form = reqwest::multipart::Form::new()
|
let form = reqwest::multipart::Form::new()
|
||||||
.part(
|
.part(
|
||||||
@@ -172,24 +124,4 @@ impl Upload {
|
|||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialize_song(&self, song: &models::song::Song, album: &models::song::Album) -> Song {
|
|
||||||
let dur = song.duration.clone().unwrap();
|
|
||||||
println!("Duration: {}", dur);
|
|
||||||
|
|
||||||
return Song {
|
|
||||||
title: String::from(&song.title.clone().unwrap()),
|
|
||||||
album: album.title.clone(),
|
|
||||||
artist: String::from(&song.artist.clone().unwrap().clone()),
|
|
||||||
album_artist: album.album_artist.clone(),
|
|
||||||
year: album.year.clone(),
|
|
||||||
genre: album.genre.clone(),
|
|
||||||
duration: f64::round(dur) as i32,
|
|
||||||
track: (song.track.clone().unwrap()),
|
|
||||||
track_count: album.track_count.clone(),
|
|
||||||
disc: song.disc.clone().unwrap(),
|
|
||||||
disc_count: album.disc_count.clone(),
|
|
||||||
songpath: String::new(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize};
|
|||||||
pub struct Checks {}
|
pub struct Checks {}
|
||||||
|
|
||||||
impl Checks {
|
impl Checks {
|
||||||
pub fn is_numeric(text: &String) -> bool {
|
pub fn _is_numeric(text: &String) -> bool {
|
||||||
text.parse::<f64>().is_ok()
|
text.parse::<f64>().is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index_of_item_in_container<F>(container: &String, item: &char, func: F) -> i32
|
pub fn _index_of_item_in_container<F>(container: &String, item: &char, func: F) -> i32
|
||||||
where
|
where
|
||||||
F: Fn(&char, &char) -> bool,
|
F: Fn(&char, &char) -> bool,
|
||||||
{
|
{
|
||||||
@@ -26,3 +26,7 @@ impl Checks {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn exit_program(code: i32) {
|
||||||
|
std::process::exit(code);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
pub mod checks;
|
pub mod checks;
|
||||||
|
pub mod string;
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
pub fn o_to_string(val: &std::ffi::OsString) -> Result<std::string::String, std::io::Error> {
|
||||||
|
match val.clone().into_string() {
|
||||||
|
Ok(value) => Ok(value),
|
||||||
|
Err(_) => Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::Other,
|
||||||
|
String::from("Error"),
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"album": "Sample Tracks 2",
|
||||||
|
"album_artist": "KD",
|
||||||
|
"genre": "Country",
|
||||||
|
"year": 2025,
|
||||||
|
"track_count": 3,
|
||||||
|
"disc_count": 1,
|
||||||
|
"tracks": [
|
||||||
|
{
|
||||||
|
"title": "Uh huh",
|
||||||
|
"artist": "KD",
|
||||||
|
"disc": 1,
|
||||||
|
"track": 1,
|
||||||
|
"duration": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Bold and brash",
|
||||||
|
"artist": "KD",
|
||||||
|
"disc": 1,
|
||||||
|
"track": 2,
|
||||||
|
"duration": 37
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "How does this work?",
|
||||||
|
"artist": "KD",
|
||||||
|
"disc": 1,
|
||||||
|
"track": 3,
|
||||||
|
"duration": 46
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user