Skip to content

feat(api): add provider to request parameters #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion proto/tunein/v1alpha1/browse.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ package tunein.v1alpha1;
import "objects/v1alpha1/category.proto";
import "objects/v1alpha1/station.proto";

message GetCategoriesRequest {}
message GetCategoriesRequest {
optional string provider = 1;
optional uint32 offset = 2;
optional uint32 limit = 3;
}

message GetCategoriesResponse {
repeated objects.v1alpha1.Category categories = 1;
}

message BrowseCategoryRequest {
string category_id = 1;
optional string provider = 2;
optional uint32 offset = 3;
optional uint32 limit = 4;
}

message BrowseCategoryResponse {
Expand All @@ -21,6 +28,7 @@ message BrowseCategoryResponse {

message GetStationDetailsRequest {
string id = 1;
optional string provider = 2;
}

message GetStationDetailsResponse {
Expand All @@ -29,6 +37,7 @@ message GetStationDetailsResponse {

message SearchRequest {
string query = 1;
optional string provider = 2;
}

message SearchResponse {
Expand Down
3 changes: 2 additions & 1 deletion proto/tunein/v1alpha1/playback.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ message StopResponse {}

message PlayRequest {
string station_name_or_id = 1;
optional string provider = 2;
}

message PlayResponse {}
Expand All @@ -20,4 +21,4 @@ service PlaybackService {
rpc Play(PlayRequest) returns (PlayResponse) {}
rpc Stop(StopRequest) returns (StopResponse) {}
rpc PlayOrPause(PlayOrPauseRequest) returns (PlayOrPauseResponse) {}
}
}
Binary file modified src/api/descriptor.bin
Binary file not shown.
23 changes: 21 additions & 2 deletions src/api/tunein.v1alpha1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// This file is @generated by prost-build.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct GetCategoriesRequest {}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetCategoriesRequest {
#[prost(string, optional, tag = "1")]
pub provider: ::core::option::Option<::prost::alloc::string::String>,
#[prost(uint32, optional, tag = "2")]
pub offset: ::core::option::Option<u32>,
#[prost(uint32, optional, tag = "3")]
pub limit: ::core::option::Option<u32>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetCategoriesResponse {
#[prost(message, repeated, tag = "1")]
Expand All @@ -10,6 +17,12 @@ pub struct GetCategoriesResponse {
pub struct BrowseCategoryRequest {
#[prost(string, tag = "1")]
pub category_id: ::prost::alloc::string::String,
#[prost(string, optional, tag = "2")]
pub provider: ::core::option::Option<::prost::alloc::string::String>,
#[prost(uint32, optional, tag = "3")]
pub offset: ::core::option::Option<u32>,
#[prost(uint32, optional, tag = "4")]
pub limit: ::core::option::Option<u32>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BrowseCategoryResponse {
Expand All @@ -20,6 +33,8 @@ pub struct BrowseCategoryResponse {
pub struct GetStationDetailsRequest {
#[prost(string, tag = "1")]
pub id: ::prost::alloc::string::String,
#[prost(string, optional, tag = "2")]
pub provider: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetStationDetailsResponse {
Expand All @@ -32,6 +47,8 @@ pub struct GetStationDetailsResponse {
pub struct SearchRequest {
#[prost(string, tag = "1")]
pub query: ::prost::alloc::string::String,
#[prost(string, optional, tag = "2")]
pub provider: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SearchResponse {
Expand Down Expand Up @@ -576,6 +593,8 @@ pub struct StopResponse {}
pub struct PlayRequest {
#[prost(string, tag = "1")]
pub station_name_or_id: ::prost::alloc::string::String,
#[prost(string, optional, tag = "2")]
pub provider: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct PlayResponse {}
Expand Down
75 changes: 60 additions & 15 deletions src/server/browse.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use tunein_cli::api::{
objects::v1alpha1::{Category, Station, StationLinkDetails},
tunein::v1alpha1::{
browse_service_server::BrowseService, BrowseCategoryRequest, BrowseCategoryResponse,
GetCategoriesRequest, GetCategoriesResponse, GetStationDetailsRequest,
GetStationDetailsResponse, SearchRequest, SearchResponse,
use tunein_cli::{
api::{
objects::v1alpha1::{Category, Station, StationLinkDetails},
tunein::v1alpha1::{
browse_service_server::BrowseService, BrowseCategoryRequest, BrowseCategoryResponse,
GetCategoriesRequest, GetCategoriesResponse, GetStationDetailsRequest,
GetStationDetailsResponse, SearchRequest, SearchResponse,
},
},
provider::radiobrowser::Radiobrowser,
};

use tunein_cli::provider::{tunein::Tunein, Provider};
Expand All @@ -16,11 +19,22 @@ pub struct Browse;
impl BrowseService for Browse {
async fn get_categories(
&self,
_request: tonic::Request<GetCategoriesRequest>,
request: tonic::Request<GetCategoriesRequest>,
) -> Result<tonic::Response<GetCategoriesResponse>, tonic::Status> {
let client: Box<dyn Provider + Send + Sync> = Box::new(Tunein::new());
let offset = 0;
let limit = 100;
let req = request.into_inner();
let provider = req.provider.as_deref();

let client: Box<dyn Provider + Send + Sync> = match provider {
Some("tunein") => Box::new(Tunein::new()),
Some("radiobrowser") => Box::new(Radiobrowser::new().await),
None => Box::new(Tunein::new()),
_ => {
return Err(tonic::Status::internal("Unsupported provider"));
}
};

let offset = req.offset.unwrap_or(0);
let limit = req.limit.unwrap_or(100);
let result = client
.categories(offset, limit)
.await
Expand All @@ -38,10 +52,20 @@ impl BrowseService for Browse {
let req = request.into_inner();
let category_id = req.category_id;

let offset = 0;
let limit = 100;
let offset = req.offset.unwrap_or(0);
let limit = req.limit.unwrap_or(100);

let provider = req.provider.as_deref();

let client: Box<dyn Provider + Send + Sync> = match provider {
Some("tunein") => Box::new(Tunein::new()),
Some("radiobrowser") => Box::new(Radiobrowser::new().await),
None => Box::new(Tunein::new()),
_ => {
return Err(tonic::Status::internal("Unsupported provider"));
}
};

let client: Box<dyn Provider + Send + Sync> = Box::new(Tunein::new());
let results = client
.browse(category_id, offset, limit)
.await
Expand All @@ -57,7 +81,18 @@ impl BrowseService for Browse {
) -> Result<tonic::Response<GetStationDetailsResponse>, tonic::Status> {
let req = request.into_inner();
let station_id = req.id;
let client: Box<dyn Provider + Send + Sync> = Box::new(Tunein::new());

let provider = req.provider.as_deref();

let client: Box<dyn Provider + Send + Sync> = match provider {
Some("tunein") => Box::new(Tunein::new()),
Some("radiobrowser") => Box::new(Radiobrowser::new().await),
None => Box::new(Tunein::new()),
_ => {
return Err(tonic::Status::internal("Unsupported provider"));
}
};

let result = client
.get_station(station_id)
.await
Expand All @@ -77,7 +112,17 @@ impl BrowseService for Browse {
request: tonic::Request<SearchRequest>,
) -> Result<tonic::Response<SearchResponse>, tonic::Status> {
let req = request.into_inner();
let client: Box<dyn Provider + Send + Sync> = Box::new(Tunein::new());
let provider = req.provider.as_deref();

let client: Box<dyn Provider + Send + Sync> = match provider {
Some("tunein") => Box::new(Tunein::new()),
Some("radiobrowser") => Box::new(Radiobrowser::new().await),
None => Box::new(Tunein::new()),
_ => {
return Err(tonic::Status::internal("Unsupported provider"));
}
};

let results = client
.search(req.query)
.await
Expand Down
28 changes: 19 additions & 9 deletions src/server/playback.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::sync::{Arc, Mutex};

use crate::player::{Player, PlayerCommand};
use tokio::sync::mpsc;
use tunein_cli::api::tunein::v1alpha1::{
playback_service_server::PlaybackService, PlayOrPauseRequest, PlayOrPauseResponse, PlayRequest,
PlayResponse, StopRequest, StopResponse,
};

use crate::{
player::{Player, PlayerCommand},
provider::{tunein::Tunein, Provider},
use tunein_cli::provider::{tunein::Tunein, Provider};
use tunein_cli::{
api::tunein::v1alpha1::{
playback_service_server::PlaybackService, PlayOrPauseRequest, PlayOrPauseResponse,
PlayRequest, PlayResponse, StopRequest, StopResponse,
},
provider::radiobrowser::Radiobrowser,
};

pub struct Playback {
Expand All @@ -33,7 +33,17 @@ impl PlaybackService for Playback {
) -> Result<tonic::Response<PlayResponse>, tonic::Status> {
let req = request.into_inner();

let client: Box<dyn Provider + Send + Sync> = Box::new(Tunein::new());
let provider = req.provider.as_deref();

let client: Box<dyn Provider + Send + Sync> = match provider {
Some("tunein") => Box::new(Tunein::new()),
Some("radiobrowser") => Box::new(Radiobrowser::new().await),
None => Box::new(Tunein::new()),
_ => {
return Err(tonic::Status::internal("Unsupported provider"));
}
};

let station = client
.get_station(req.station_name_or_id.clone())
.await
Expand Down
Loading