mirror of
https://gitlab.com/vandechat96/radiorecord-tui.git
synced 2026-05-04 23:39:14 +02:00
Add station name to mpris metadata
This commit is contained in:
@@ -396,7 +396,7 @@ impl App {
|
||||
}
|
||||
Command::NowPlaying => {
|
||||
player_tx
|
||||
.send(Response::NowPlaying(self.music_title.to_string()))
|
||||
.send(Response::NowPlaying{title:self.music_title.to_string(),artist:self.playing_station.title.clone()})
|
||||
.unwrap();
|
||||
}
|
||||
Command::Status => {
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -61,10 +61,11 @@ async fn main() -> color_eyre::Result<()> {
|
||||
// background player in cli
|
||||
|
||||
let mut player = player::Player::new(list[0].stream_320.clone());
|
||||
if let Some(station) = station {
|
||||
let mut station_name = if let Some(station) = station {
|
||||
// if a station is selected play it
|
||||
if let Some(station_found) = list.iter().find(|s| s.prefix == station) {
|
||||
player.play(&station_found.stream_320);
|
||||
station_found.title.clone()
|
||||
} else {
|
||||
eprintln!("Station not found");
|
||||
exit(1);
|
||||
@@ -73,15 +74,17 @@ async fn main() -> color_eyre::Result<()> {
|
||||
// play random station
|
||||
let random = random::<usize>() % list.len();
|
||||
let station = &list[random];
|
||||
println!("Now playing : {}", station.title);
|
||||
player.play(&station.stream_320);
|
||||
}
|
||||
station.title.clone()
|
||||
};
|
||||
|
||||
println!("Now playing : {}", station_name);
|
||||
// launch and handle mpris interface
|
||||
let (mpris_tx, mpris_rx) = channel::bounded(1);
|
||||
let (tx, rx) = channel::bounded(1);
|
||||
|
||||
let _conn = launch_mpris_server(mpris_tx, rx).await?;
|
||||
|
||||
|
||||
thread::spawn(move || loop {
|
||||
if mpris_rx.is_empty() {
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
@@ -94,7 +97,8 @@ async fn main() -> color_eyre::Result<()> {
|
||||
mpris::Command::Play => player.resume(),
|
||||
mpris::Command::Next => {
|
||||
let random = random::<usize>() % list.len();
|
||||
let station = &list[random];
|
||||
let station = list[random].clone();
|
||||
station_name = station.title.clone();
|
||||
println!("Now playing : {}", station.title);
|
||||
player.force_play(&station.stream_320);
|
||||
}
|
||||
@@ -103,7 +107,7 @@ async fn main() -> color_eyre::Result<()> {
|
||||
#[cfg(feature = "libmpv_player")]
|
||||
{
|
||||
if let Some(title) = player.now_playing() {
|
||||
tx.send(Response::NowPlaying(title)).unwrap();
|
||||
tx.send(Response::NowPlaying{title,artist:station_name.clone()}).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
36
src/mpris.rs
36
src/mpris.rs
@@ -16,7 +16,7 @@ pub enum Command {
|
||||
}
|
||||
|
||||
pub enum Response {
|
||||
NowPlaying(String),
|
||||
NowPlaying { title: String, artist: String },
|
||||
Status(String),
|
||||
}
|
||||
|
||||
@@ -55,17 +55,22 @@ impl MediaPlayerInterface {
|
||||
}
|
||||
#[dbus_interface(property, name = "Metadata")]
|
||||
async fn Metadata(&self) -> HashMap<&str, Value> {
|
||||
self.tx.send(Event::Mpris(Command::NowPlaying)).expect("Could not send");
|
||||
self.tx
|
||||
.send(Event::Mpris(Command::NowPlaying))
|
||||
.expect("Could not send");
|
||||
let mut map = HashMap::new();
|
||||
if let Response::NowPlaying(title) = self.rx.recv().unwrap() {
|
||||
if let Response::NowPlaying{title, artist} = self.rx.recv().unwrap() {
|
||||
map.insert("xesam:title", Value::from(title));
|
||||
map.insert("xesam:artist", Value::from(artist));
|
||||
return map;
|
||||
}
|
||||
map
|
||||
}
|
||||
#[dbus_interface(property, name = "PlaybackStatus")]
|
||||
async fn PlaybackStatus(&self) -> String {
|
||||
self.tx.send(Event::Mpris(Command::Status)).expect("Could not send");
|
||||
self.tx
|
||||
.send(Event::Mpris(Command::Status))
|
||||
.expect("Could not send");
|
||||
if let Ok(Response::Status(status)) = self.rx.recv() {
|
||||
status
|
||||
} else {
|
||||
@@ -75,20 +80,30 @@ impl MediaPlayerInterface {
|
||||
|
||||
// Can be `async` as well.
|
||||
async fn Next(&mut self) {
|
||||
self.tx.send(Event::Mpris(Command::Next)).expect("Could not send")
|
||||
self.tx
|
||||
.send(Event::Mpris(Command::Next))
|
||||
.expect("Could not send")
|
||||
}
|
||||
async fn Previous(&mut self) {
|
||||
self.tx.send(Event::Mpris(Command::Previous)).expect("Could not send")
|
||||
self.tx
|
||||
.send(Event::Mpris(Command::Previous))
|
||||
.expect("Could not send")
|
||||
}
|
||||
|
||||
async fn Play(&mut self) {
|
||||
self.tx.send(Event::Mpris(Command::Play)).expect("Could not send")
|
||||
self.tx
|
||||
.send(Event::Mpris(Command::Play))
|
||||
.expect("Could not send")
|
||||
}
|
||||
async fn Stop(&mut self) {
|
||||
self.tx.send(Event::Mpris(Command::Stop)).expect("Could not send");
|
||||
self.tx
|
||||
.send(Event::Mpris(Command::Stop))
|
||||
.expect("Could not send");
|
||||
}
|
||||
async fn PlayPause(&mut self) {
|
||||
self.tx.send(Event::Mpris(Command::PlayPause)).expect("Could not send");
|
||||
self.tx
|
||||
.send(Event::Mpris(Command::PlayPause))
|
||||
.expect("Could not send");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +115,8 @@ pub async fn launch_mpris_server(
|
||||
let conn = ConnectionBuilder::session()?
|
||||
.name(INAME)?
|
||||
.serve_at("/org/mpris/MediaPlayer2", player)?
|
||||
.build().await?;
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
Ok(conn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user