|
|
@ -57,12 +57,14 @@ struct Song {
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
enum SongError {
|
|
|
|
enum SongError {
|
|
|
|
#[error("Unknown song")]
|
|
|
|
#[error("Not a Newgrounds song")]
|
|
|
|
Unknown,
|
|
|
|
NotNewgrounds,
|
|
|
|
#[error("Official level song")]
|
|
|
|
|
|
|
|
Official,
|
|
|
|
|
|
|
|
#[error("Song mp3 not downloaded")]
|
|
|
|
#[error("Song mp3 not downloaded")]
|
|
|
|
MissingFile,
|
|
|
|
MissingFile(#[from] std::io::Error),
|
|
|
|
|
|
|
|
#[error("Couldn't decode mp3 file")]
|
|
|
|
|
|
|
|
BrokenSong(#[from] rodio::decoder::DecoderError),
|
|
|
|
|
|
|
|
#[error("Couldn't access song data on servers")]
|
|
|
|
|
|
|
|
ServerError(#[from] gd::SongRequestError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct BeatRateWidget<'a> {
|
|
|
|
struct BeatRateWidget<'a> {
|
|
|
@ -101,24 +103,21 @@ impl From<Color> for eframe::epaint::Color32 {
|
|
|
|
|
|
|
|
|
|
|
|
impl Song {
|
|
|
|
impl Song {
|
|
|
|
pub fn try_new(gd_song: gd::Song) -> Result<Self, SongError> {
|
|
|
|
pub fn try_new(gd_song: gd::Song) -> Result<Self, SongError> {
|
|
|
|
match gd_song {
|
|
|
|
match &gd_song {
|
|
|
|
gd::Song::Official { id: _ } => Err(SongError::Official),
|
|
|
|
|
|
|
|
gd::Song::Unknown => Err(SongError::Unknown),
|
|
|
|
|
|
|
|
gd::Song::Newgrounds { id } => {
|
|
|
|
gd::Song::Newgrounds { id } => {
|
|
|
|
let file_result = {
|
|
|
|
let song_data = gd_song.get_response()?;
|
|
|
|
let mut path = gd::gd_path();
|
|
|
|
file::open(gd::gd_path().join(format!("{}.mp3", id)))
|
|
|
|
path.push(format!("{}.mp3", id));
|
|
|
|
.or_else(|_| {
|
|
|
|
File::open(path)
|
|
|
|
|
|
|
|
};
|
|
|
|
})
|
|
|
|
match file_result {
|
|
|
|
todo!("if file is missing, try to download it from the SongResponse. If that fails, return an error. Otherwise, return file info")
|
|
|
|
Ok(file) => Ok(Song {
|
|
|
|
// Ok(Song {
|
|
|
|
name: unimplemented!(),
|
|
|
|
// name: todo!(),
|
|
|
|
id,
|
|
|
|
// id,
|
|
|
|
decoder: unimplemented!(),
|
|
|
|
// decoder: rodio::Decoder::new_mp3(file)?
|
|
|
|
}),
|
|
|
|
// })
|
|
|
|
Err(err) => Err(SongError::MissingFile),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_ => Err(SongError::NotNewgrounds)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|