Only show filename for untagged songs
continuous-integration/drone/push Build is passing Details

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
1 changed files with 6 additions and 8 deletions

View File

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