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
This commit is contained in:
23
src/lib.rs
23
src/lib.rs
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user