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
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -879,6 +879,7 @@ dependencies = [
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"url",
|
"url",
|
||||||
|
"urlencoding",
|
||||||
"zbus",
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -5646,6 +5647,12 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "urlencoding"
|
||||||
|
version = "2.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "usvg"
|
name = "usvg"
|
||||||
version = "0.37.0"
|
version = "0.37.0"
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,4 @@ mpris2-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
||||||
serde = "1.0.130"
|
serde = "1.0.130"
|
||||||
url = "2"
|
url = "2"
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
|
urlencoding = "2.1.3"
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,4 @@ show-media-controls = Show Media Controls on Top Panel
|
||||||
sound-settings = Sound Settings...
|
sound-settings = Sound Settings...
|
||||||
disconnected = PulseAudio Disconnected
|
disconnected = PulseAudio Disconnected
|
||||||
no-device = No device selected
|
no-device = No device selected
|
||||||
|
unknown-artist = Unknown
|
||||||
|
|
|
||||||
|
|
@ -718,7 +718,7 @@ impl cosmic::Application for Audio {
|
||||||
artists
|
artists
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
fl!("unknown-artist")
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.push(column![text(title).size(14), text(artists).size(10),].into());
|
elements.push(column![text(title).size(14), text(artists).size(10),].into());
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use mpris2_zbus::{
|
||||||
player::{PlaybackStatus, Player},
|
player::{PlaybackStatus, Player},
|
||||||
};
|
};
|
||||||
use tokio::join;
|
use tokio::join;
|
||||||
|
use urlencoding::decode;
|
||||||
use zbus::{fdo::DBusProxy, Connection};
|
use zbus::{fdo::DBusProxy, Connection};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
@ -27,7 +28,16 @@ pub struct PlayerStatus {
|
||||||
impl PlayerStatus {
|
impl PlayerStatus {
|
||||||
async fn new(player: Player) -> Option<Self> {
|
async fn new(player: Player) -> Option<Self> {
|
||||||
let metadata = player.metadata().await.ok()?;
|
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
|
let artists = metadata
|
||||||
.artists()
|
.artists()
|
||||||
.map(|a| a.into_iter().map(Cow::from).collect::<Vec<_>>());
|
.map(|a| a.into_iter().map(Cow::from).collect::<Vec<_>>());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue