diff options
Diffstat (limited to 'import/src/tmdb.rs')
-rw-r--r-- | import/src/tmdb.rs | 70 |
1 files changed, 32 insertions, 38 deletions
diff --git a/import/src/tmdb.rs b/import/src/tmdb.rs index 1e7849f..3b3e7ed 100644 --- a/import/src/tmdb.rs +++ b/import/src/tmdb.rs @@ -44,48 +44,42 @@ impl Tmdb { } } pub async fn search(&self, kind: TmdbKind, query: &str) -> anyhow::Result<Arc<TmdbQuery>> { - async_cache_memory( - &["api-tmdb-search", query, &format!("{kind}")], - || async move { - info!("searching tmdb: {query:?}"); - Ok(self - .client - .get(format!( - "https://api.themoviedb.org/3/search/{kind}?query={}?api_key={}", - query.replace(" ", "+"), - self.key - )) - .send() - .await? - .error_for_status()? - .json::<TmdbQuery>() - .await?) - }, - ) + async_cache_memory("api-tmdb-search", (kind, query), || async move { + info!("searching tmdb: {query:?}"); + Ok(self + .client + .get(format!( + "https://api.themoviedb.org/3/search/{kind}?query={}?api_key={}", + query.replace(" ", "+"), + self.key + )) + .send() + .await? + .error_for_status()? + .json::<TmdbQuery>() + .await?) + }) .await } pub async fn details(&self, kind: TmdbKind, id: u64) -> anyhow::Result<Arc<TmdbDetails>> { - async_cache_memory( - &["api-tmdb-details", &format!("{kind} {id}")], - || async move { - info!("fetching details: {id:?}"); - Ok(self - .client - .get(format!( - "https://api.themoviedb.org/3/{kind}/{id}?api_key={}", - self.key, - )) - .send() - .await? - .error_for_status()? - .json() - .await?) - }, - ) + async_cache_memory("api-tmdb-details", (kind, id), || async move { + info!("fetching details: {id:?}"); + Ok(self + .client + .get(format!( + "https://api.themoviedb.org/3/{kind}/{id}?api_key={}", + self.key, + )) + .send() + .await? + .error_for_status()? + .json() + .await?) + }) .await } pub async fn person_image(&self, id: u64) -> anyhow::Result<Arc<TmdbPersonImage>> { - async_cache_memory(&["api-tmdb-search", &format!("{id}")], || async move { + async_cache_memory("api-tmdb-search", id, || async move { Ok(self .client .get(format!( @@ -101,7 +95,7 @@ impl Tmdb { .await } pub async fn image(&self, path: &str) -> anyhow::Result<CachePath> { - async_cache_file(&["api-tmdb-image", path], |mut file| async move { + async_cache_file("api-tmdb-image", path, |mut file| async move { info!("downloading image {path:?}"); let mut res = self .image_client @@ -123,7 +117,7 @@ impl Tmdb { season: usize, episode: usize, ) -> anyhow::Result<Arc<TmdbEpisode>> { - async_cache_memory(&["api-tmdb-episode-details", &format!("{series_id} {season} {episode}")], || async move { + async_cache_memory("api-tmdb-episode-details", (series_id,season,episode), || async move { info!("tmdb episode details {series_id} S={season} E={episode}"); Ok(self .image_client |