diff options
| author | Yuval Adam <_@yuv.al> | 2024-05-31 15:30:20 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2024-05-31 15:32:26 +0200 |
| commit | ea0acfda17f94b88fa71218be7b3cd4736736698 (patch) | |
| tree | 4e29392c80ed37bc566bac9178047ee3756b876d /src | |
| parent | ef5668b85f6bf79fdd01ce98a010d593d2a5ea11 (diff) | |
Finalize rodio backend implementation
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio/rodio.rs | 4 | ||||
| -rw-r--r-- | src/channels.rs | 11 | ||||
| -rw-r--r-- | src/main.rs | 7 |
3 files changed, 18 insertions, 4 deletions
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) => { |
