summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2024-05-31 15:30:20 +0200
committerYuval Adam <_@yuv.al>2024-05-31 15:32:26 +0200
commitea0acfda17f94b88fa71218be7b3cd4736736698 (patch)
tree4e29392c80ed37bc566bac9178047ee3756b876d
parentef5668b85f6bf79fdd01ce98a010d593d2a5ea11 (diff)
Finalize rodio backend implementation
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--README.md4
-rw-r--r--src/audio/rodio.rs4
-rw-r--r--src/channels.rs11
-rw-r--r--src/main.rs7
6 files changed, 22 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9e2d941..5036456 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1451,7 +1451,7 @@ dependencies = [
[[package]]
name = "somafm"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"inquire",
"reqwest",
diff --git a/Cargo.toml b/Cargo.toml
index 9a70353..996899e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "somafm"
description = "A Rust-based command line player for SomaFM radio"
-version = "0.2.0"
+version = "0.3.0"
authors = ["Yuval Adam <_@yuv.al>"]
edition = "2021"
license = "MIT"
diff --git a/README.md b/README.md
index 55bf8f1..a2d1550 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
# somafm.rs
-A Rust-based command line player for SomaFM radio
+A Rust-based command line player for SomaFM radio.
-Currently requires `mpv` installed as the media backend, pure-rust media output is planned.
+Implements a pure-Rust audio backend, but can fallback to using a `mpv` as an optional dependency.
## Install
diff --git a/src/audio/rodio.rs b/src/audio/rodio.rs
index f3f0ffd..3dffa5e 100644
--- a/src/audio/rodio.rs
+++ b/src/audio/rodio.rs
@@ -15,9 +15,7 @@ pub struct Rodio {}
impl Rodio {
pub async fn play(&self, url: &str) {
let reader = StreamDownload::new_http(
- "https://ice6.somafm.com/groovesalad-256-mp3"
- .parse()
- .unwrap(),
+ url.parse().unwrap(),
TempStorageProvider::new(),
Settings::default(),
)
diff --git a/src/channels.rs b/src/channels.rs
index fdb8844..1c7ed3c 100644
--- a/src/channels.rs
+++ b/src/channels.rs
@@ -27,6 +27,17 @@ pub async fn get_channels() -> Vec<Channel> {
channels.channels
}
+pub async fn get_stream_url(pls: &str) -> Option<String> {
+ let res = reqwest::get(pls).await.unwrap().text().await.unwrap();
+ for line in res.lines() {
+ let url = line.split_once("File1=");
+ if url.is_some() {
+ return Some(url.unwrap().1.to_string());
+ }
+ }
+ None
+}
+
mod tests {
#[test]
fn test_channel_parse() {
diff --git a/src/main.rs b/src/main.rs
index e7aaaa1..9b98c2d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
use crate::channels::Channel;
+use channels::get_stream_url;
use inquire::{InquireError, Select};
use spinners::{Spinner, Spinners};
@@ -16,8 +17,12 @@ async fn main() {
match ans {
Ok(ch) => {
+ let mut sp = Spinner::new(Spinners::Dots, "Fetching channel streams...".into());
+ let pls = format!("https://api.somafm.com/{}.pls", ch.id);
+ let url = get_stream_url(&pls).await.unwrap();
+ sp.stop_with_newline();
+
let _sp = Spinner::new(Spinners::Arrow3, format!("Playing {}", ch.title));
- let url = format!("https://api.somafm.com/{}.pls", ch.id);
audio::get_backend().play(&url).await
}
Err(_e) => {