summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2024-05-31 14:59:25 +0200
committerYuval Adam <_@yuv.al>2024-05-31 14:59:25 +0200
commit4a4c5b9174cf0182d4eb755f5d97ca432e5960ca (patch)
treee0d49598fa09ed0ad859b9afb95ea4b88e51d04f /src
parent10976b7bdfcdb57724d9e2b1dedd2c172b0b5973 (diff)
Add multiple backend support
Diffstat (limited to 'src')
-rw-r--r--src/audio/mod.rs25
-rw-r--r--src/audio/mpv.rs13
-rw-r--r--src/audio/rodio.rs9
-rw-r--r--src/main.rs10
-rw-r--r--src/mpv.rs0
5 files changed, 51 insertions, 6 deletions
diff --git a/src/audio/mod.rs b/src/audio/mod.rs
new file mode 100644
index 0000000..7fca1a7
--- /dev/null
+++ b/src/audio/mod.rs
@@ -0,0 +1,25 @@
+mod mpv;
+mod rodio;
+
+pub trait AudioBackend {
+ fn play(&self, url: &str);
+}
+
+#[allow(dead_code)]
+pub enum AudioBackends {
+ Mpv(mpv::Mpv),
+ Rodio(rodio::Rodio),
+}
+
+pub fn get_backend() -> AudioBackends {
+ AudioBackends::Mpv(mpv::Mpv {})
+}
+
+impl AudioBackend for AudioBackends {
+ fn play(&self, url: &str) {
+ match self {
+ AudioBackends::Mpv(m) => m.play(url),
+ AudioBackends::Rodio(r) => r.play(url),
+ }
+ }
+}
diff --git a/src/audio/mpv.rs b/src/audio/mpv.rs
new file mode 100644
index 0000000..dddb6b2
--- /dev/null
+++ b/src/audio/mpv.rs
@@ -0,0 +1,13 @@
+use super::AudioBackend;
+use std::process::Command;
+
+pub struct Mpv {}
+
+impl AudioBackend for Mpv {
+ fn play(&self, url: &str) {
+ Command::new("mpv")
+ .args([url])
+ .output()
+ .expect("Failed to start mpv, make sure it is installed.");
+ }
+}
diff --git a/src/audio/rodio.rs b/src/audio/rodio.rs
new file mode 100644
index 0000000..04883dd
--- /dev/null
+++ b/src/audio/rodio.rs
@@ -0,0 +1,9 @@
+use super::AudioBackend;
+
+pub struct Rodio {}
+
+impl AudioBackend for Rodio {
+ fn play(&self, _url: &str) {
+ todo!()
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index aa9f938..e18b909 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,9 @@
use crate::channels::Channel;
+use audio::AudioBackend;
use inquire::{InquireError, Select};
use spinners::{Spinner, Spinners};
-use std::process::Command;
+mod audio;
mod channels;
fn main() {
@@ -15,12 +16,9 @@ fn main() {
match ans {
Ok(ch) => {
- let _sp = Spinner::new(Spinners::Arrow3, format!("Playing {}", ch));
+ let _sp = Spinner::new(Spinners::Arrow3, format!("Playing {}", ch.title));
let url = format!("https://api.somafm.com/{}.pls", ch.id);
- Command::new("mpv")
- .args([url])
- .output()
- .expect("Failed to start mpv, make sure it is installed.");
+ audio::get_backend().play(&url);
}
Err(_e) => {
println!("\nNo channel selected, exiting.");
diff --git a/src/mpv.rs b/src/mpv.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/mpv.rs