From b5f722f1cb3972ad233fb7aa1b1ae119b53eb6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20M=C3=BCndelein?= Date: Mon, 22 May 2023 11:02:42 +0200 Subject: [PATCH] Disentangle conflicting proto versions We diverged in working on the proto definition, which should now be resolved. --- crabidy-core/build.rs | 1 - crabidy-core/crabidy/v1/crabidy.proto | 92 ++++++++++++++++++ crabidy-core/proto/crabidy.proto | 128 -------------------------- crabidy-core/src/lib.rs | 8 +- tidaldy/src/lib.rs | 15 ++- tidaldy/src/models.rs | 8 +- 6 files changed, 107 insertions(+), 145 deletions(-) delete mode 100644 crabidy-core/proto/crabidy.proto diff --git a/crabidy-core/build.rs b/crabidy-core/build.rs index 3cbeb79..c580b63 100644 --- a/crabidy-core/build.rs +++ b/crabidy-core/build.rs @@ -1,5 +1,4 @@ fn main() -> Result<(), Box> { tonic_build::compile_protos("crabidy/v1/crabidy.proto")?; - tonic_build::compile_protos("crabidy/proto/crabidy.proto")?; Ok(()) } diff --git a/crabidy-core/crabidy/v1/crabidy.proto b/crabidy-core/crabidy/v1/crabidy.proto index 681b028..0fcd742 100644 --- a/crabidy-core/crabidy/v1/crabidy.proto +++ b/crabidy-core/crabidy/v1/crabidy.proto @@ -57,3 +57,95 @@ message GetTrackRequest { message GetTrackResponse { Track track = 1; } + +service Queue { + rpc QueueTrack (QueueTrackRequest) returns (EmptyResponse); + rpc QueueLibraryNode (QueueNodeRequest) returns (EmptyResponse); + rpc ReplaceWithTrack (QueueTrackRequest) returns (EmptyResponse); + rpc ReplaceWithNode (QueueNodeRequest) returns (EmptyResponse); + rpc AppendTrack (QueueTrackRequest) returns (EmptyResponse); + rpc AppendNode (QueueNodeRequest) returns (EmptyResponse); + rpc RemoveTracks (RemoveTracksRequest) returns (EmptyResponse); + rpc SetCurrentTrack (SetCurrentTrackRequest) returns (EmptyResponse); + rpc GetQueueUpdates (QueueUpdatesRequest) returns (stream QueueUpdateResponse); + rpc GetQueue(EmptyRequest) returns (CurrentQueue); + rpc SaveQueue (QueueSaveRequest) returns (EmptyResponse); +} + +message CurrentQueue { + uint64 timestamp =1; + uint32 current = 2; + repeated Track tracks = 3; +} + +message QueuePositionChange { + uint64 timestamp = 1; + uint32 new_position = 2; +} + +message QueueTrackRequest { + string uuid = 1; +} + +message QueueNodeRequest { + string uuid = 1; +} + +message RemoveTracksRequest { + repeated uint32 positions = 1; +} + +message SetCurrentTrackRequest { + uint32 position = 1; +} + + +message QueueUpdatesRequest { + uint64 timestamp =2; +} + +message QueueUpdateResponse { + oneof QueueUpdateResult{ + CurrentQueue full = 1; + QueuePositionChange position_change = 2; + } +} + +message QueueSaveRequest { + string name = 1; + // inside the configured path of crabidy + string path = 2; + +} + +service Playback { + rpc TogglePlay (EmptyRequest) returns (EmptyResponse); + rpc Stop (EmptyRequest) returns (EmptyResponse); + rpc GetActiveTrack (EmptyRequest) returns (ActiveTrack); + rpc GetTrackUpdates (ActiveTrackFilter) returns (stream ActiveTrack); +} + + +enum TrackPlayState { + TRACK_PLAY_STATE_STOPPED = 0; + TRACK_PLAY_STATE_LOADING = 1; + TRACK_PLAY_STATE_PLAYING = 2; + TRACK_PLAY_STATE_PAUSED = 3; +} + +message ActiveTrackFilter { + // defines how many of the update messages should be skipped + // before they are sent back via GetTrackUpdates + uint32 updates_skipped = 1; + repeated string type_whitelist = 2; + repeated string type_blacklist = 3; +} + +message ActiveTrack { + optional Track track = 1; + TrackPlayState play_state = 2; + uint32 completion = 3; +} + +message EmptyRequest { } +message EmptyResponse { } diff --git a/crabidy-core/proto/crabidy.proto b/crabidy-core/proto/crabidy.proto deleted file mode 100644 index 95cd696..0000000 --- a/crabidy-core/proto/crabidy.proto +++ /dev/null @@ -1,128 +0,0 @@ -syntax = "proto3"; -package crabidy; - - -service Library { - rpc GetLibraryNode (LibraryNodeRequest) returns (LibraryNodeResponse); -} - -// To signal whether it's loading data (for frontend only probably) -enum LibraryNodeState { - LIBRARY_NODE_STATE_UNSPECIFIED = 0; - LIBRARY_NODE_STATE_PENDING = 1; - LIBRARY_NODE_STATE_DONE = 2; -} - -message Track { - // Including provider - string uuid = 1; - string artist = 2; - string title = 3; -} - -message LibraryNodeRequest { - string uuid = 1; -} - -message LibraryNodeResponse { - // Including provider - string uuid = 1; - string name = 2; - repeated string children = 3; - optional string parent = 4; - LibraryNodeState state = 5; - repeated Track tracks = 6; - bool is_queable = 7; -} - -service Queue { - rpc QueueTrack (QueueTrackRequest) returns (EmptyResponse); - rpc QueueLibraryNode (QueueNodeRequest) returns (EmptyResponse); - rpc ReplaceWithTrack (QueueTrackRequest) returns (EmptyResponse); - rpc ReplaceWithNode (QueueNodeRequest) returns (EmptyResponse); - rpc AppendTrack (QueueTrackRequest) returns (EmptyResponse); - rpc AppendNode (QueueNodeRequest) returns (EmptyResponse); - rpc RemoveTracks (RemoveTracksRequest) returns (EmptyResponse); - rpc SetCurrentTrack (SetCurrentTrackRequest) returns (EmptyResponse); - rpc GetQueueUpdates (QueueUpdatesRequest) returns (stream QueueUpdateResponse); - rpc GetQueue(EmptyRequest) returns (CurrentQueue); - rpc SaveQueue (QueueSaveRequest) returns (EmptyResponse); -} - -message CurrentQueue { - uint64 timestamp =1; - uint32 current = 2; - repeated Track tracks = 3; -} - -message QueuePositionChange { - uint64 timestamp = 1; - uint32 new_position = 2; -} - -message QueueTrackRequest { - string uuid = 1; -} - -message QueueNodeRequest { - string uuid = 1; -} - -message RemoveTracksRequest { - repeated uint32 positions = 1; -} - -message SetCurrentTrackRequest { - uint32 position = 1; -} - - -message QueueUpdatesRequest { - uint64 timestamp =2; -} - -message QueueUpdateResponse { - oneof QueueUpdateResult{ - CurrentQueue full = 1; - QueuePositionChange position_change = 2; - } -} - -message QueueSaveRequest { - string name = 1; - // inside the configured path of crabidy - string path = 2; - -} - -service Playback { - rpc TogglePlay (EmptyRequest) returns (EmptyResponse); - rpc Stop (EmptyRequest) returns (EmptyResponse); - rpc GetActiveTrack (EmptyRequest) returns (ActiveTrack); - rpc GetTrackUpdates (ActiveTrackFilter) returns (stream ActiveTrack); -} - - -enum TrackPlayState { - TRACK_PLAY_STATE_STOPPED = 0; - TRACK_PLAY_STATE_LOADING = 1; - TRACK_PLAY_STATE_PLAYING = 2; - TRACK_PLAY_STATE_PAUSED = 3; -} - -message ActiveTrackFilter { - // defines how many of the update messages should be skipped - // before they are sent back via GetTrackUpdates - uint32 updates_skipped = 1; - repeated string type_whitelist = 2; - repeated string type_blacklist = 3; -} - -message ActiveTrack { - optional Track track = 1; - TrackPlayState play_state = 2; - uint32 completion = 3; -} - -message EmptyRequest { } -message EmptyResponse { } diff --git a/crabidy-core/src/lib.rs b/crabidy-core/src/lib.rs index 89e5e4b..d95a17e 100644 --- a/crabidy-core/src/lib.rs +++ b/crabidy-core/src/lib.rs @@ -2,8 +2,6 @@ pub mod proto; use async_trait::async_trait; - - #[async_trait] pub trait ProviderClient: std::fmt::Debug + Send + Sync { async fn init(raw_toml_settings: &str) -> Result @@ -11,11 +9,11 @@ pub trait ProviderClient: std::fmt::Debug + Send + Sync { Self: Sized; fn settings(&self) -> String; async fn get_urls_for_track(&self, track_uuid: &str) -> Result, ProviderError>; - fn get_library_root(&self) -> proto::crabidy::LibraryNodeResponse; + fn get_library_root(&self) -> proto::crabidy::LibraryNode; async fn get_library_node( &self, list_uuid: &str, - ) -> Result; + ) -> Result; } #[derive(Clone, Debug, Hash)] @@ -27,7 +25,7 @@ pub enum ProviderError { Other, } -impl proto::crabidy::LibraryNodeResponse { +impl proto::crabidy::LibraryNode { pub fn new() -> Self { Self { uuid: "/".to_string(), diff --git a/tidaldy/src/lib.rs b/tidaldy/src/lib.rs index c821e16..3430969 100644 --- a/tidaldy/src/lib.rs +++ b/tidaldy/src/lib.rs @@ -53,10 +53,10 @@ impl crabidy_core::ProviderClient for Client { Ok(manifest.urls) } - fn get_library_root(&self) -> crabidy_core::proto::crabidy::LibraryNodeResponse { - let global_root = crabidy_core::proto::crabidy::LibraryNodeResponse::new(); + fn get_library_root(&self) -> crabidy_core::proto::crabidy::LibraryNode { + let global_root = crabidy_core::proto::crabidy::LibraryNode::new(); let children = vec!["userplaylists".to_string()]; - crabidy_core::proto::crabidy::LibraryNodeResponse { + crabidy_core::proto::crabidy::LibraryNode { uuid: "tidal".to_string(), name: "tidal".to_string(), parent: Some(format!("{}", global_root.uuid)), @@ -70,16 +70,15 @@ impl crabidy_core::ProviderClient for Client { async fn get_library_node( &self, uuid: &str, - ) -> Result - { + ) -> Result { let Some(user_id) = self.settings.login.user_id.clone() else { return Err(crabidy_core::ProviderError::UnknownUser) }; let (module, uuid) = split_uuid(uuid); let node = match module.as_str() { "userplaylists" => { - let global_root = crabidy_core::proto::crabidy::LibraryNodeResponse::new(); - let mut node = crabidy_core::proto::crabidy::LibraryNodeResponse { + let global_root = crabidy_core::proto::crabidy::LibraryNode::new(); + let mut node = crabidy_core::proto::crabidy::LibraryNode { uuid: "userplaylists".to_string(), name: "playlists".to_string(), parent: Some(format!("{}", global_root.uuid)), @@ -97,7 +96,7 @@ impl crabidy_core::ProviderClient for Client { node } "playlist" => { - let mut node: crabidy_core::proto::crabidy::LibraryNodeResponse = + let mut node: crabidy_core::proto::crabidy::LibraryNode = self.get_playlist(&uuid).await?.into(); let tracks: Vec = self .get_playlist_tracks(&uuid) diff --git a/tidaldy/src/models.rs b/tidaldy/src/models.rs index 123809e..96a049d 100644 --- a/tidaldy/src/models.rs +++ b/tidaldy/src/models.rs @@ -188,6 +188,7 @@ impl From for crabidy_core::proto::crabidy::Track { uuid: track.id.to_string(), title: track.title, artist: track.artist.name, + duration: Some(track.duration as u32), } } } @@ -198,6 +199,7 @@ impl From<&Track> for crabidy_core::proto::crabidy::Track { uuid: track.id.to_string(), title: track.title.clone(), artist: track.artist.name.clone(), + duration: Some(track.duration as u32), } } } @@ -298,7 +300,7 @@ pub struct PlaylistAndFavorite { pub playlist: Playlist, } -impl From for crabidy_core::proto::crabidy::LibraryNodeResponse { +impl From for crabidy_core::proto::crabidy::LibraryNode { fn from(a: PlaylistAndFavorite) -> Self { a.playlist.into() } @@ -327,9 +329,9 @@ pub struct Playlist { pub last_item_added_at: Option, } -impl From for crabidy_core::proto::crabidy::LibraryNodeResponse { +impl From for crabidy_core::proto::crabidy::LibraryNode { fn from(a: Playlist) -> Self { - crabidy_core::proto::crabidy::LibraryNodeResponse { + crabidy_core::proto::crabidy::LibraryNode { name: a.title, uuid: format!("playlist:{}", a.uuid), tracks: Vec::new(),