A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at feat/pgpull 49 lines 1.6 kB view raw
1use anyhow::Error; 2use async_trait::async_trait; 3use owo_colors::OwoColorize; 4use tokio::sync::mpsc::Sender; 5 6pub mod jellyfin; 7pub mod kodi; 8pub mod mopidy; 9pub mod mpd; 10pub mod mpris; 11pub mod vlc; 12 13pub const SUPPORTED_PLAYERS: [&str; 6] = ["jellyfin", "kodi", "mopidy", "mpd", "mpris", "vlc"]; 14 15#[async_trait] 16pub trait Player { 17 async fn play(&self) -> Result<(), Error>; 18 async fn pause(&self) -> Result<(), Error>; 19 async fn next(&self) -> Result<(), Error>; 20 async fn previous(&self) -> Result<(), Error>; 21 async fn seek(&self, position: u64) -> Result<(), Error>; 22 async fn broadcast_now_playing(&self, tx: Sender<String>) -> Result<(), Error>; 23 async fn broadcast_status(&self, tx: Sender<String>) -> Result<(), Error>; 24} 25 26pub fn get_current_player() -> Result<Box<dyn Player + Send + Sync>, Error> { 27 let player_type = std::env::var("ROCKSKY_PLAYER"); 28 if player_type.is_err() { 29 return Err(Error::msg(format!( 30 "{} environment variable not set", 31 "ROCKSKY_PLAYER".green() 32 ))); 33 } 34 35 let player_type = player_type.unwrap(); 36 37 match player_type.as_str() { 38 "jellyfin" => Ok(Box::new(jellyfin::new())), 39 "kodi" => Ok(Box::new(kodi::new()?)), 40 "mopidy" => Ok(Box::new(mopidy::new())), 41 "mpd" => Ok(Box::new(mpd::new())), 42 "mpris" => Ok(Box::new(mpris::new())), 43 "vlc" => Ok(Box::new(vlc::new())), 44 _ => Err(Error::msg(format!( 45 "Unsupported player type: {}", 46 player_type.magenta() 47 ))), 48 } 49}