Create the stupid get_name function
This commit is contained in:
parent
5873c99924
commit
9c92f690fc
1 changed files with 10 additions and 0 deletions
|
@ -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)]
|
||||
mod tests {
|
||||
|
|
Loading…
Reference in a new issue