Only show filename for untagged songs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Sijmen 2023-05-07 04:06:21 +02:00
parent 4eab50d8cc
commit f610171d7d
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48

View file

@ -1,5 +1,3 @@
use std::borrow::Cow;
use anyhow::anyhow;
use async_std::{
io::{prelude::BufReadExt, BufReader, WriteExt},
@ -27,29 +25,29 @@ pub(crate) fn connect() -> Result<mpdrs::Client, mpdrs::error::Error> {
pub(crate) fn ls(path: &str) -> anyhow::Result<Vec<Entry>> {
let info = connect()?.lsinfo(path)?;
fn filename(path: &str) -> Cow<str> {
fn filename(path: &str) -> String {
std::path::Path::new(path)
.file_name()
.map(|x| x.to_string_lossy())
.unwrap_or(Cow::Borrowed("n/a"))
.map(|x| x.to_string_lossy().to_string())
.unwrap_or("n/a".to_string())
}
Ok(info
.iter()
.map(|e| match e {
LsInfoResponse::Song(song) => Entry::Song {
name: song.title.as_ref().unwrap_or(&song.file).clone(),
name: song.title.as_ref().unwrap_or(&filename(&song.file)).clone(),
artist: song.artist.clone().unwrap_or(String::new()),
path: song.file.clone(),
},
LsInfoResponse::Directory { path, .. } => Entry::Directory {
name: filename(path).to_string(),
name: filename(path),
path: path.to_string(),
},
LsInfoResponse::Playlist { path, .. } => Entry::Playlist {
name: filename(path).to_string(),
name: filename(path),
path: path.to_string(),
},
})