Compare commits
4 Commits
b21863298b
...
main
Author | SHA1 | Date | |
---|---|---|---|
2411320522 | |||
34811c15af | |||
eebea71fca | |||
9260d80458 |
@@ -13,4 +13,4 @@ async-stream = "0.3"
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
stream-download = "0.22"
|
stream-download = "0.22"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
tokio-cron-scheduler = "0.14.0"
|
tokio-cron-scheduler = "0.14"
|
||||||
|
10
src/lib.rs
10
src/lib.rs
@@ -16,11 +16,11 @@ async fn get_newest_morning_journal() -> Result<String, Box<dyn std::error::Erro
|
|||||||
for day in days.iter().rev() {
|
for day in days.iter().rev() {
|
||||||
if let Some(broadcasts) = day["broadcasts"].as_array() {
|
if let Some(broadcasts) = day["broadcasts"].as_array() {
|
||||||
for broadcast in broadcasts.iter().rev() {
|
for broadcast in broadcasts.iter().rev() {
|
||||||
//if broadcast["title"] == "Ö1 Morgenjournal" {
|
if broadcast["title"] == "Ö1 Morgenjournal"
|
||||||
if broadcast["title"] == "Eröffnungskonzert Allegro Vivo"
|
&& let Some(href) = broadcast["href"].as_str()
|
||||||
&& let Some(href) = broadcast["href"].as_str() {
|
{
|
||||||
return Ok(href.into());
|
return Ok(href.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
36
src/main.rs
36
src/main.rs
@@ -15,24 +15,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.route("/", get(streamer::stream_handler))
|
.route("/", get(streamer::stream_handler))
|
||||||
.with_state(state.clone());
|
.with_state(state.clone());
|
||||||
|
|
||||||
let scheduler = JobScheduler::new().await.unwrap();
|
//let scheduler = JobScheduler::new().await.unwrap();
|
||||||
scheduler
|
//scheduler
|
||||||
.add(
|
// .add(
|
||||||
Job::new_async(
|
// Job::new_async(
|
||||||
"30 0 7 * * Mon,Tue,Wed,Thu,Fri,Sat",
|
// "30 0 7 * * Mon,Tue,Wed,Thu,Fri,Sat",
|
||||||
move |_uuid, _locked| {
|
// move |_uuid, _locked| {
|
||||||
let state_for_task = state.clone();
|
// let state_for_task = state.clone();
|
||||||
Box::pin(async move {
|
// Box::pin(async move {
|
||||||
state_for_task.check_update().await;
|
// state_for_task.check_update().await;
|
||||||
println!("Task executed at: {}", Utc::now());
|
// println!("Task executed at: {}", Utc::now());
|
||||||
})
|
// })
|
||||||
},
|
// },
|
||||||
)
|
// )
|
||||||
.unwrap(),
|
// .unwrap(),
|
||||||
)
|
// )
|
||||||
.await
|
// .await
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
scheduler.start().await.unwrap();
|
//scheduler.start().await.unwrap();
|
||||||
|
|
||||||
println!("Streaming server running on http://localhost:3029");
|
println!("Streaming server running on http://localhost:3029");
|
||||||
|
|
||||||
|
@@ -1,24 +1,32 @@
|
|||||||
use crate::state::AppState;
|
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 std::sync::Arc;
|
||||||
use tokio_stream::Stream;
|
use tokio_stream::Stream;
|
||||||
|
|
||||||
pub async fn stream_handler(State(state): State<Arc<AppState>>) -> Response {
|
pub async fn stream_handler(State(state): State<Arc<AppState>>) -> Redirect {
|
||||||
state.clone().check_update().await;
|
let url = newest_morning_journal_streaming_url().await.unwrap();
|
||||||
|
Redirect::temporary(&url)
|
||||||
|
|
||||||
let stream = create_chunk_stream(state);
|
//state.clone().check_update().await;
|
||||||
let body = Body::from_stream(stream);
|
|
||||||
|
|
||||||
Response::builder()
|
//let stream = create_chunk_stream(state);
|
||||||
.header("Content-Type", "audio/mpeg")
|
//let body = Body::from_stream(stream);
|
||||||
.header("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
||||||
.header("Pragma", "no-cache")
|
//Response::builder()
|
||||||
.header("Expires", "0")
|
// .header("Content-Type", "audio/mpeg")
|
||||||
.header("Accept-Ranges", "none")
|
// .header("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||||
.header("Transfer-Encoding", "chunked")
|
// .header("Pragma", "no-cache")
|
||||||
.header("X-Content-Duration", "infinity")
|
// .header("Expires", "0")
|
||||||
.body(body)
|
// .header("Accept-Ranges", "none")
|
||||||
.unwrap()
|
// .header("Transfer-Encoding", "chunked")
|
||||||
|
// .header("X-Content-Duration", "infinity")
|
||||||
|
// .body(body)
|
||||||
|
// .unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_chunk_stream(
|
fn create_chunk_stream(
|
||||||
|
Reference in New Issue
Block a user