From f610171d7d7ce20bf4f3d830cff94ff34bd18509 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Sun, 7 May 2023 04:06:21 +0200 Subject: [PATCH] Only show filename for untagged songs --- src/mpd.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/mpd.rs b/src/mpd.rs index e391629..fd776b2 100644 --- a/src/mpd.rs +++ b/src/mpd.rs @@ -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 { pub(crate) fn ls(path: &str) -> anyhow::Result> { let info = connect()?.lsinfo(path)?; - fn filename(path: &str) -> Cow { + 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(), }, })