Create the stupid get_name function

This commit is contained in:
Anas Elgarhy 2023-02-04 22:49:16 +02:00
parent 5873c99924
commit 9c92f690fc
No known key found for this signature in database
GPG key ID: 0501802A1D496528

View file

@ -95,6 +95,16 @@ impl TrackMetadata {
} }
} }
impl Track {
/// Returns the name of the track.
///
/// This is the title, if it exists, otherwise it's the file name without the extension.
pub fn get_name(&self) -> String {
self.metadata.get("title").unwrap_or_else(|| self.path.split('/').last()
.unwrap_or("").split_once(".").unwrap_or(("", "")).0).to_string()
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {