Language Migration #21
@@ -167,10 +167,9 @@ impl CommitManager {
|
|||||||
println!("Deleting song");
|
println!("Deleting song");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement
|
|
||||||
// NOTE: Might not need to implement. I will see how this goes
|
|
||||||
fn upload_song(&self) {
|
fn upload_song(&self) {
|
||||||
println!("Deleting song");
|
println!("Deleting song");
|
||||||
|
panic!("Not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_token(&self, api: &models::api::API) -> models::token::Token {
|
fn parse_token(&self, api: &models::api::API) -> models::token::Token {
|
||||||
@@ -198,7 +197,6 @@ impl CommitManager {
|
|||||||
return token.unwrap();
|
return token.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement
|
|
||||||
fn upload_song_with_metadata(&mut self) {
|
fn upload_song_with_metadata(&mut self) {
|
||||||
println!("Uplodaring song with metadara");
|
println!("Uplodaring song with metadara");
|
||||||
|
|
||||||
@@ -234,7 +232,6 @@ impl CommitManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement
|
|
||||||
fn sing_target_upload(
|
fn sing_target_upload(
|
||||||
&mut self,
|
&mut self,
|
||||||
songpath: &String,
|
songpath: &String,
|
||||||
@@ -264,32 +261,16 @@ impl CommitManager {
|
|||||||
let mut fp = String::new();
|
let mut fp = String::new();
|
||||||
let mut dir = String::new();
|
let mut dir = String::new();
|
||||||
|
|
||||||
// song_file.file_name();
|
|
||||||
|
|
||||||
// for entry in read_dir(song_file)? {
|
|
||||||
// for entry in read_file(song_file)? {
|
|
||||||
let entry = &song_file;
|
let entry = &song_file;
|
||||||
|
|
||||||
// let file_type = entry.file_type();
|
|
||||||
let file_name = std::ffi::OsString::from(entry.file_name().unwrap());
|
let file_name = std::ffi::OsString::from(entry.file_name().unwrap());
|
||||||
|
|
||||||
// println!("file type: {:?}", file_type);
|
|
||||||
println!("file name: {:?}", file_name);
|
println!("file name: {:?}", file_name);
|
||||||
|
|
||||||
match self.find_file_extension(&file_name) {
|
match self.find_file_extension(&file_name) {
|
||||||
En::ImageFile => {
|
En::ImageFile => {}
|
||||||
// let directory_part = sourcepath.clone();
|
En::MetadataFile => {}
|
||||||
// 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 => {
|
En::SongFile => {
|
||||||
// let mut song = models::song::Song::default();
|
|
||||||
let fname = self.o_to_string(&file_name);
|
let fname = self.o_to_string(&file_name);
|
||||||
|
|
||||||
match fname {
|
match fname {
|
||||||
@@ -303,17 +284,13 @@ impl CommitManager {
|
|||||||
}
|
}
|
||||||
Err(er) => println!("Error: {:?}", er),
|
Err(er) => println!("Error: {:?}", er),
|
||||||
}
|
}
|
||||||
|
|
||||||
// songs.push(song)
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
cover_art.path = Some(cover_path.clone());
|
cover_art.path = Some(cover_path.clone());
|
||||||
|
|
||||||
let mut album = self.retrieve_metadata(&meta_path);
|
let album = self.retrieve_metadata(&meta_path);
|
||||||
// self.song_parsing(&mut album, &song.directory.unwrap(), &filenames);
|
|
||||||
let trck = i32::from_str(track_id).unwrap();
|
let trck = i32::from_str(track_id).unwrap();
|
||||||
let mut s = album.retrieve_song(trck, 1).unwrap();
|
let mut s = album.retrieve_song(trck, 1).unwrap();
|
||||||
s.filepath = Some(fp);
|
s.filepath = Some(fp);
|
||||||
@@ -343,7 +320,7 @@ impl CommitManager {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
// TODO: Implement
|
|
||||||
fn multi_target_upload(&mut self, sourcepath: &String) -> std::io::Result<()> {
|
fn multi_target_upload(&mut self, sourcepath: &String) -> std::io::Result<()> {
|
||||||
let mut prsr = parsers::api_parser::APIParser {
|
let mut prsr = parsers::api_parser::APIParser {
|
||||||
api: models::api::API::default(),
|
api: models::api::API::default(),
|
||||||
@@ -356,8 +333,7 @@ impl CommitManager {
|
|||||||
let directory_path = std::path::Path::new(&sourcepath);
|
let directory_path = std::path::Path::new(&sourcepath);
|
||||||
|
|
||||||
if !directory_path.exists() {
|
if !directory_path.exists() {
|
||||||
println!("Directory does not exist");
|
panic!("Directory does not exist");
|
||||||
std::process::exit(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cover_art = models::song::CoverArt::default();
|
let mut cover_art = models::song::CoverArt::default();
|
||||||
@@ -424,6 +400,15 @@ impl CommitManager {
|
|||||||
|
|
||||||
println!("");
|
println!("");
|
||||||
|
|
||||||
|
for sng in &mut album.songs {
|
||||||
|
match sng.data {
|
||||||
|
Some(_) => {}
|
||||||
|
None => {
|
||||||
|
sng.data = Some(sng.to_data().unwrap());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
for song in &album.songs {
|
for song in &album.songs {
|
||||||
// Upload each song
|
// Upload each song
|
||||||
println!("Sending song...");
|
println!("Sending song...");
|
||||||
|
|||||||
+34
-49
@@ -27,6 +27,8 @@ struct Song {
|
|||||||
track_count: i32,
|
track_count: i32,
|
||||||
disc: i32,
|
disc: i32,
|
||||||
disc_count: i32,
|
disc_count: i32,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
|
songpath: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Song {
|
impl Song {
|
||||||
@@ -67,7 +69,6 @@ impl Upload {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: Implement
|
|
||||||
pub async fn upload_song_with_metadata(
|
pub async fn upload_song_with_metadata(
|
||||||
&mut self,
|
&mut self,
|
||||||
token: &models::token::Token,
|
token: &models::token::Token,
|
||||||
@@ -77,39 +78,17 @@ impl Upload {
|
|||||||
) -> Result<reqwest::Response, std::io::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 new_song = self.initialize_song(&song, &album);
|
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();
|
||||||
|
|
||||||
let song_data = song.data.clone().unwrap();
|
|
||||||
let cover_data = cover.data.clone().unwrap();
|
|
||||||
let song_detail = new_song.to_metadata_json().unwrap();
|
|
||||||
|
|
||||||
let song_raw_data_as = (async { song_data.clone() });
|
|
||||||
let cover_raw_data_as = async { cover_data.clone() };
|
|
||||||
let song_raw_data = song_raw_data_as.await;
|
|
||||||
let cover_raw_data: Vec<u8> = cover_raw_data_as.await;
|
|
||||||
|
|
||||||
if url.is_empty() {
|
if url.is_empty() {
|
||||||
println!("Url is empty");
|
println!("Url is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Url: {}", url);
|
println!("Url: {}", url);
|
||||||
println!("Length: {:?}", song_raw_data.len());
|
|
||||||
println!("Token: {}", access_token);
|
println!("Token: {}", access_token);
|
||||||
|
|
||||||
/*
|
|
||||||
let form_as = async {
|
|
||||||
self.initialize_form(
|
|
||||||
song_raw_data.clone(),
|
|
||||||
cover_raw_data.clone(),
|
|
||||||
song_detail.clone(),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
// let form = self.initialize_form(song_raw_data, cover_raw_data, song_detail.clone());
|
|
||||||
// let form = form_as.await;
|
|
||||||
|
|
||||||
let mut headers = reqwest::header::HeaderMap::new();
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
headers.insert(
|
headers.insert(
|
||||||
reqwest::header::AUTHORIZATION,
|
reqwest::header::AUTHORIZATION,
|
||||||
@@ -117,30 +96,7 @@ impl Upload {
|
|||||||
);
|
);
|
||||||
headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*"));
|
headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*"));
|
||||||
|
|
||||||
let songpath = song.song_path();
|
let form = self.init_form(&new_song, &cover);
|
||||||
let coverpath = cover.path.clone().unwrap();
|
|
||||||
|
|
||||||
println!("\n{}\n", song_detail);
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
let form = reqwest::multipart::Form::new()
|
|
||||||
.part(
|
|
||||||
"file",
|
|
||||||
reqwest::multipart::Part::bytes(std::fs::read(songpath)?).file_name(song_filename),
|
|
||||||
)
|
|
||||||
.part(
|
|
||||||
"cover",
|
|
||||||
reqwest::multipart::Part::bytes(std::fs::read(coverpath)?)
|
|
||||||
.file_name(cover_filename),
|
|
||||||
)
|
|
||||||
.text("metadata", song_detail);
|
|
||||||
|
|
||||||
println!("Form: {:?}", form);
|
|
||||||
|
|
||||||
let client = reqwest::Client::builder().build().unwrap();
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
let response = client
|
let response = client
|
||||||
.post(url)
|
.post(url)
|
||||||
@@ -188,6 +144,34 @@ impl Upload {
|
|||||||
.part("file", file.file_name(song_filename));
|
.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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
let form = reqwest::multipart::Form::new()
|
||||||
|
.part(
|
||||||
|
"file",
|
||||||
|
reqwest::multipart::Part::bytes(std::fs::read(songpath).unwrap())
|
||||||
|
.file_name(song_filename),
|
||||||
|
)
|
||||||
|
.part(
|
||||||
|
"cover",
|
||||||
|
reqwest::multipart::Part::bytes(std::fs::read(coverpath).unwrap())
|
||||||
|
.file_name(cover_filename),
|
||||||
|
)
|
||||||
|
.text("metadata", song_detail);
|
||||||
|
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_api(&mut self, host: &String) {
|
pub fn set_api(&mut self, host: &String) {
|
||||||
let mut api = models::api::API::default();
|
let mut api = models::api::API::default();
|
||||||
api.url = host.clone();
|
api.url = host.clone();
|
||||||
@@ -229,6 +213,7 @@ impl Upload {
|
|||||||
track_count: album.track_count.clone(),
|
track_count: album.track_count.clone(),
|
||||||
disc: song.disc.clone().unwrap(),
|
disc: song.disc.clone().unwrap(),
|
||||||
disc_count: album.disc_count.clone(),
|
disc_count: album.disc_count.clone(),
|
||||||
|
songpath: String::new(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user