Skip to content

Commit

Permalink
mpd: return playlist infos
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Nov 9, 2024
1 parent 27f3fb5 commit e90f125
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions crates/mpd/src/handlers/playback.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Error;
use rockbox_rpc::api::rockbox::v1alpha1::{
CurrentTrackRequest, GetGlobalSettingsRequest, NextRequest, PauseRequest, PlayRequest,
PreviousRequest, ResumeRequest, SaveSettingsRequest, StatusRequest,
CurrentTrackRequest, GetCurrentRequest, GetGlobalSettingsRequest, NextRequest, PauseRequest,
PlayRequest, PreviousRequest, ResumeRequest, SaveSettingsRequest, StatusRequest,
};
use tokio::{
io::{AsyncWriteExt, BufReader},
Expand Down Expand Up @@ -121,9 +121,14 @@ pub async fn handle_status(
let single = ctx.single.lock().await;
let single = single.as_str().replace("\"", "");

let response = ctx.playlist.get_current(GetCurrentRequest {}).await?;
let response = response.into_inner();
let playlistlength = response.amount;
let song = response.index;

let response = format!(
"state: {}\nrepeat: {}\nsingle: {}\nrandom: {}\ntime: {}\nelapsed: {}\nOK\n",
status, repeat, single, random, time, elapsed
"state: {}\nrepeat: {}\nsingle: {}\nrandom: {}\ntime: {}\nelapsed: {}\nplaylistlength: {}\nsong: {}\nOK\n",
status, repeat, single, random, time, elapsed, playlistlength, song
);

if !ctx.batch {
Expand Down
6 changes: 5 additions & 1 deletion crates/mpd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use handlers::{
};
use rockbox_rpc::api::rockbox::v1alpha1::{
library_service_client::LibraryServiceClient, playback_service_client::PlaybackServiceClient,
settings_service_client::SettingsServiceClient, sound_service_client::SoundServiceClient,
playlist_service_client::PlaylistServiceClient, settings_service_client::SettingsServiceClient,
sound_service_client::SoundServiceClient,
};
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
Expand All @@ -35,6 +36,7 @@ pub struct Context {
pub playback: PlaybackServiceClient<Channel>,
pub settings: SettingsServiceClient<Channel>,
pub sound: SoundServiceClient<Channel>,
pub playlist: PlaylistServiceClient<Channel>,
pub single: Arc<Mutex<String>>,
pub batch: bool,
}
Expand Down Expand Up @@ -146,12 +148,14 @@ pub async fn setup_context(batch: bool) -> Result<Context, Error> {
let playback = PlaybackServiceClient::connect(url.clone()).await?;
let settings = SettingsServiceClient::connect(url.clone()).await?;
let sound = SoundServiceClient::connect(url.clone()).await?;
let playlist = PlaylistServiceClient::connect(url.clone()).await?;

Ok(Context {
library,
playback,
settings,
sound,
playlist,
single: Arc::new(Mutex::new("\"0\"".to_string())),
batch,
})
Expand Down

0 comments on commit e90f125

Please sign in to comment.