remove temp. data storage (e.g. date), and look directly at data, don't re-download (e.g. on sundays) if url has already been downloaded; Fixes #3
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m25s
CI/CD Pipeline / deploy (push) Successful in 1m16s

This commit is contained in:
Philipp Hofer
2025-10-13 11:07:18 +02:00
parent 8e774a7e23
commit 2a421dfc1e
3 changed files with 50 additions and 27 deletions

View File

@@ -1,14 +1,23 @@
use chrono::NaiveDate;
use serde_json::Value;
pub async fn newest_morning_journal_streaming_url() -> Result<String, Box<dyn std::error::Error>> {
let url = get_newest_morning_journal().await?;
get_streaming_url(url).await
#[derive(Clone)]
pub struct Episode {
pub url: String,
pub date: NaiveDate,
}
pub async fn newest_morning_journal_streaming_url() -> Result<Episode, Box<dyn std::error::Error>> {
let (date, url) = get_newest_morning_journal().await?;
let url = get_streaming_url(url).await?;
Ok(Episode { url, date })
}
// List of broadcasts: https://audioapi.orf.at/oe1/api/json/current/broadcasts
//
// ^ contains link, e.g. https://audioapi.orf.at/oe1/api/json/4.0/broadcast/797577/20250611
async fn get_newest_morning_journal() -> Result<String, Box<dyn std::error::Error>> {
async fn get_newest_morning_journal() -> Result<(NaiveDate, String), Box<dyn std::error::Error>> {
let url = "https://audioapi.orf.at/oe1/api/json/current/broadcasts";
let data: Value = reqwest::get(url).await?.json().await?;
@@ -19,7 +28,11 @@ async fn get_newest_morning_journal() -> Result<String, Box<dyn std::error::Erro
if broadcast["title"] == "Ö1 Morgenjournal"
&& let Some(href) = broadcast["href"].as_str()
{
return Ok(href.into());
let date = broadcast["broadcastDay"].as_number().unwrap_or_else(|| {
panic!("There needs to be a broadcastDay! {}", &broadcast)
});
let date = NaiveDate::parse_from_str(&date.to_string(), "%Y%m%d").expect("broadcastDay in https://audioapi.orf.at/oe1/api/json/current/broadcasts not in a valid format");
return Ok((date, href.into()));
}
}
}