diff --git a/src/main.rs b/src/main.rs index faa3d79..a715e7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,24 +15,24 @@ async fn main() -> Result<(), Box> { .route("/", get(streamer::stream_handler)) .with_state(state.clone()); - let scheduler = JobScheduler::new().await.unwrap(); - scheduler - .add( - Job::new_async( - "30 0 7 * * Mon,Tue,Wed,Thu,Fri,Sat", - move |_uuid, _locked| { - let state_for_task = state.clone(); - Box::pin(async move { - state_for_task.check_update().await; - println!("Task executed at: {}", Utc::now()); - }) - }, - ) - .unwrap(), - ) - .await - .unwrap(); - scheduler.start().await.unwrap(); + //let scheduler = JobScheduler::new().await.unwrap(); + //scheduler + // .add( + // Job::new_async( + // "30 0 7 * * Mon,Tue,Wed,Thu,Fri,Sat", + // move |_uuid, _locked| { + // let state_for_task = state.clone(); + // Box::pin(async move { + // state_for_task.check_update().await; + // println!("Task executed at: {}", Utc::now()); + // }) + // }, + // ) + // .unwrap(), + // ) + // .await + // .unwrap(); + //scheduler.start().await.unwrap(); println!("Streaming server running on http://localhost:3029"); diff --git a/src/streamer.rs b/src/streamer.rs index a9a3285..b8ab532 100644 --- a/src/streamer.rs +++ b/src/streamer.rs @@ -1,24 +1,32 @@ use crate::state::AppState; -use axum::{body::Body, extract::State, response::Response}; +use axum::{ + body::Body, + extract::State, + response::{Redirect, Response}, +}; +use player::newest_morning_journal_streaming_url; use std::sync::Arc; use tokio_stream::Stream; -pub async fn stream_handler(State(state): State>) -> Response { - state.clone().check_update().await; +pub async fn stream_handler(State(state): State>) -> Redirect { + let url = newest_morning_journal_streaming_url().await.unwrap(); + Redirect::to(&url) - let stream = create_chunk_stream(state); - let body = Body::from_stream(stream); + //state.clone().check_update().await; - Response::builder() - .header("Content-Type", "audio/mpeg") - .header("Cache-Control", "no-cache, no-store, must-revalidate") - .header("Pragma", "no-cache") - .header("Expires", "0") - .header("Accept-Ranges", "none") - .header("Transfer-Encoding", "chunked") - .header("X-Content-Duration", "infinity") - .body(body) - .unwrap() + //let stream = create_chunk_stream(state); + //let body = Body::from_stream(stream); + + //Response::builder() + // .header("Content-Type", "audio/mpeg") + // .header("Cache-Control", "no-cache, no-store, must-revalidate") + // .header("Pragma", "no-cache") + // .header("Expires", "0") + // .header("Accept-Ranges", "none") + // .header("Transfer-Encoding", "chunked") + // .header("X-Content-Duration", "infinity") + // .body(body) + // .unwrap() } fn create_chunk_stream(