aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--import/src/lib.rs8
-rw-r--r--import/src/tmdb.rs19
2 files changed, 21 insertions, 6 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs
index 473ed53..bf3c48d 100644
--- a/import/src/lib.rs
+++ b/import/src/lib.rs
@@ -141,7 +141,11 @@ pub fn generate_node_paths(db: &DataAcid) -> anyhow::Result<()> {
let txn = db.inner.begin_write()?;
let table = txn.open_table(T_NODE)?;
- let mut node = table.get(&*c)?.ok_or(anyhow!("your mum"))?.value().0;
+ let mut node = table
+ .get(&*c)?
+ .ok_or(anyhow!("missing child when generating paths: {c:?} at {path:?}"))?
+ .value()
+ .0;
if node.public.path.is_empty() {
node.public.path = path.clone();
@@ -372,7 +376,7 @@ async fn process_source(
.insert(Rating::Tmdb, details.vote_average);
if let Some(date) = details.release_date.clone() {
node.public.release_date =
- Some(parse_release_date(&date).context("parsing release date")?);
+ parse_release_date(&date).context("parsing release date")?;
}
insert_node(&id, node)?;
diff --git a/import/src/tmdb.rs b/import/src/tmdb.rs
index b651223..c349edf 100644
--- a/import/src/tmdb.rs
+++ b/import/src/tmdb.rs
@@ -5,7 +5,7 @@ use std::{fmt::Display, sync::Arc};
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
-use anyhow::Context;
+use anyhow::{anyhow, bail, Context};
use bincode::{Decode, Encode};
use jellybase::cache::{async_cache_file, async_cache_memory};
use jellycommon::{
@@ -22,6 +22,7 @@ use tokio::io::AsyncWriteExt;
pub struct Tmdb {
client: Client,
+ image_client: Client,
key: String,
}
@@ -34,8 +35,10 @@ impl Tmdb {
)]))
.build()
.unwrap();
+ let image_client = ClientBuilder::new().build().unwrap();
Self {
client,
+ image_client,
key: api_key.to_owned(),
}
}
@@ -99,7 +102,10 @@ impl Tmdb {
pub async fn image(&self, path: &str) -> anyhow::Result<AssetLocation> {
async_cache_file(&["api-tmdb-image", path], |mut file| async move {
info!("downloading image {path:?}");
- let mut res = reqwest::get(&format!("https://image.tmdb.org/t/p/original{path}"))
+ let mut res = self
+ .image_client
+ .get(&format!("https://image.tmdb.org/t/p/original{path}"))
+ .send()
.await?
.error_for_status()?;
while let Some(chunk) = res.chunk().await? {
@@ -111,7 +117,12 @@ impl Tmdb {
}
}
-pub fn parse_release_date(d: &str) -> anyhow::Result<i64> {
+pub fn parse_release_date(d: &str) -> anyhow::Result<Option<i64>> {
+ if d.is_empty() {
+ return Ok(None);
+ } else if d.len() < 10 {
+ bail!(anyhow!("date string too short"))
+ }
let (year, month, day) = (&d[0..4], &d[5..7], &d[8..10]);
let (year, month, day) = (
year.parse().context("parsing year")?,
@@ -127,7 +138,7 @@ pub fn parse_release_date(d: &str) -> anyhow::Result<i64> {
p.hour_mod_12 = Some(0);
p.minute = Some(0);
p.second = Some(0);
- Ok(p.to_datetime_with_timezone(&Utc)?.timestamp_millis())
+ Ok(Some(p.to_datetime_with_timezone(&Utc)?.timestamp_millis()))
}
#[derive(Debug, Clone, Deserialize, Encode, Decode)]