feat(audio): add fallback when title/artist not found
This commit is contained in:
parent
b7c6cc0a97
commit
59af0f1b8b
5 changed files with 21 additions and 2 deletions
|
|
@ -23,3 +23,4 @@ mpris2-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
|||
serde = "1.0.130"
|
||||
url = "2"
|
||||
zbus.workspace = true
|
||||
urlencoding = "2.1.3"
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ show-media-controls = Show Media Controls on Top Panel
|
|||
sound-settings = Sound Settings...
|
||||
disconnected = PulseAudio Disconnected
|
||||
no-device = No device selected
|
||||
unknown-artist = Unknown
|
||||
|
|
|
|||
|
|
@ -718,7 +718,7 @@ impl cosmic::Application for Audio {
|
|||
artists
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
fl!("unknown-artist")
|
||||
};
|
||||
|
||||
elements.push(column![text(title).size(14), text(artists).size(10),].into());
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use mpris2_zbus::{
|
|||
player::{PlaybackStatus, Player},
|
||||
};
|
||||
use tokio::join;
|
||||
use urlencoding::decode;
|
||||
use zbus::{fdo::DBusProxy, Connection};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -27,7 +28,16 @@ pub struct PlayerStatus {
|
|||
impl PlayerStatus {
|
||||
async fn new(player: Player) -> Option<Self> {
|
||||
let metadata = player.metadata().await.ok()?;
|
||||
let title = metadata.title().map(Cow::from);
|
||||
let pathname = metadata.url().unwrap_or("".into());
|
||||
let pathbuf = PathBuf::from(pathname);
|
||||
|
||||
let title = metadata
|
||||
.title()
|
||||
.or(pathbuf
|
||||
.file_name()
|
||||
.and_then(|s| s.to_str())
|
||||
.and_then(|s| decode(s).map_or(None, |s| Some(s.into_owned()))))
|
||||
.map(Cow::from);
|
||||
let artists = metadata
|
||||
.artists()
|
||||
.map(|a| a.into_iter().map(Cow::from).collect::<Vec<_>>());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue