generate rss feed
This commit is contained in:
@@ -1,56 +1,29 @@
|
||||
use crate::state::AppState;
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::State,
|
||||
response::{Redirect, Response},
|
||||
};
|
||||
use player::newest_morning_journal_streaming_url;
|
||||
use axum::extract::State;
|
||||
use std::sync::Arc;
|
||||
use tokio_stream::Stream;
|
||||
|
||||
pub async fn stream_handler(State(state): State<Arc<AppState>>) -> Redirect {
|
||||
let url = newest_morning_journal_streaming_url().await.unwrap();
|
||||
Redirect::temporary(&url)
|
||||
pub async fn stream_handler(State(state): State<Arc<AppState>>) -> String {
|
||||
state.clone().check_update().await;
|
||||
|
||||
//state.clone().check_update().await;
|
||||
|
||||
//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()
|
||||
feed(&state.urls.read().await.to_vec())
|
||||
}
|
||||
|
||||
fn create_chunk_stream(
|
||||
state: Arc<AppState>,
|
||||
) -> impl Stream<Item = Result<bytes::Bytes, std::io::Error>> {
|
||||
async_stream::stream! {
|
||||
let mut position = 0;
|
||||
fn feed(urls: &Vec<String>) -> String {
|
||||
let mut ret = String::new();
|
||||
ret.push_str(r#"<?xml version="1.0" encoding="UTF-8"?>\n"#);
|
||||
ret.push_str(r#"<rss version="2.0">"#);
|
||||
ret.push_str("<channel>");
|
||||
ret.push_str("<title>Ö1 Morgenjournal Feed</title>");
|
||||
ret.push_str("<link>news.hofer.link</link>");
|
||||
ret.push_str("<description>Feed für Ö1 Morgenjournal. Live.</description>");
|
||||
|
||||
loop {
|
||||
// Send available chunks
|
||||
let chunks = state.chunks.read().await;
|
||||
while position < chunks.len() {
|
||||
yield Ok(chunks[position].clone());
|
||||
position += 1;
|
||||
}
|
||||
drop(chunks);
|
||||
|
||||
// Exit if download complete and all chunks sent
|
||||
if state.is_complete().await && position >= state.chunk_count().await {
|
||||
break;
|
||||
}
|
||||
|
||||
// Wait for new chunks
|
||||
state.notify.notified().await;
|
||||
}
|
||||
for url in urls {
|
||||
ret.push_str(&format!("<title>{url}</title>"));
|
||||
ret.push_str(&format!("<link>{url}</link>"));
|
||||
ret.push_str(&format!("<description>{url}</description>"));
|
||||
}
|
||||
|
||||
ret.push_str("</channel>");
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user