aboutsummaryrefslogtreecommitdiff
path: root/import/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-04-18 23:33:29 +0200
committermetamuffin <metamuffin@disroot.org>2025-04-18 23:33:29 +0200
commita123a1997f3ab527ab83b44ca18bec94883f46d0 (patch)
tree761c4f0e8e9bbb7834e59af3d6904dee39932923 /import/src
parent5b6fd021cc84ae7f5e1719ff398ff4627493a13c (diff)
downloadjellything-a123a1997f3ab527ab83b44ca18bec94883f46d0.tar
jellything-a123a1997f3ab527ab83b44ca18bec94883f46d0.tar.bz2
jellything-a123a1997f3ab527ab83b44ca18bec94883f46d0.tar.zst
use impl Hash for cache key instead of string
Diffstat (limited to 'import/src')
-rw-r--r--import/src/acoustid.rs2
-rw-r--r--import/src/tmdb.rs70
-rw-r--r--import/src/trakt.rs55
3 files changed, 56 insertions, 71 deletions
diff --git a/import/src/acoustid.rs b/import/src/acoustid.rs
index fe47290..7406976 100644
--- a/import/src/acoustid.rs
+++ b/import/src/acoustid.rs
@@ -17,7 +17,7 @@ pub(crate) struct Fingerprint {
}
pub(crate) async fn acoustid_fingerprint(path: &Path) -> Result<Arc<Fingerprint>> {
- async_cache_memory(&["fpcalc", &path.to_string_lossy()], || async move {
+ async_cache_memory("fpcalc", path, || async move {
let child = Command::new("fpcalc")
.arg("-json")
.arg(path)
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
diff --git a/import/src/trakt.rs b/import/src/trakt.rs
index 52a5cb0..2f8618d 100644
--- a/import/src/trakt.rs
+++ b/import/src/trakt.rs
@@ -48,7 +48,7 @@ impl Trakt {
kinds: &[TraktKind],
query: &str,
) -> anyhow::Result<Arc<Vec<TraktSearchResult>>> {
- async_cache_memory(&["api-trakt-lookup", query], || async move {
+ async_cache_memory("api-trakt-lookup", (kinds, query), || async move {
let url = format!(
"https://api.trakt.tv/search/{}?query={}&extended=full",
kinds
@@ -66,38 +66,32 @@ impl Trakt {
}
pub async fn lookup(&self, kind: TraktKind, id: u64) -> anyhow::Result<Arc<TraktMediaObject>> {
- async_cache_memory(
- &["api-trakt-lookup", &format!("{kind} {id}")],
- || async move {
- info!("trakt lookup {kind:?}:{id:?}");
- let url = format!("https://api.trakt.tv/{}/{id}?extended=full", kind.plural());
- let res = self.client.get(url).send().await?.error_for_status()?;
- Ok(res.json().await?)
- },
- )
+ async_cache_memory("api-trakt-lookup", (kind, id), || async move {
+ info!("trakt lookup {kind:?}:{id:?}");
+ let url = format!("https://api.trakt.tv/{}/{id}?extended=full", kind.plural());
+ let res = self.client.get(url).send().await?.error_for_status()?;
+ Ok(res.json().await?)
+ })
.await
.context("trakt lookup")
}
pub async fn people(&self, kind: TraktKind, id: u64) -> anyhow::Result<Arc<TraktPeople>> {
- async_cache_memory(
- &["api-trakt-people", &format!("{kind} {id}")],
- || async move {
- info!("trakt people {kind:?}:{id:?}");
- let url = format!(
- "https://api.trakt.tv/{}/{id}/people?extended=full",
- kind.plural()
- );
- let res = self.client.get(url).send().await?.error_for_status()?;
- Ok(res.json().await?)
- },
- )
+ async_cache_memory("api-trakt-people", (kind, id), || async move {
+ info!("trakt people {kind:?}:{id:?}");
+ let url = format!(
+ "https://api.trakt.tv/{}/{id}/people?extended=full",
+ kind.plural()
+ );
+ let res = self.client.get(url).send().await?.error_for_status()?;
+ Ok(res.json().await?)
+ })
.await
.context("trakt people")
}
pub async fn show_seasons(&self, id: u64) -> anyhow::Result<Arc<Vec<TraktSeason>>> {
- async_cache_memory(&["api-trakt-seasons", &id.to_string()], || async move {
+ async_cache_memory("api-trakt-seasons", id, || async move {
info!("trakt seasons {id:?}");
let url = format!("https://api.trakt.tv/shows/{id}/seasons?extended=full");
let res = self.client.get(url).send().await?.error_for_status()?;
@@ -112,15 +106,12 @@ impl Trakt {
id: u64,
season: usize,
) -> anyhow::Result<Arc<Vec<TraktEpisode>>> {
- async_cache_memory(
- &["api-trakt-episodes", &id.to_string(), &season.to_string()],
- || async move {
- info!("trakt episodes {id:?} season={season}");
- let url = format!("https://api.trakt.tv/shows/{id}/seasons/{season}?extended=full");
- let res = self.client.get(url).send().await?.error_for_status()?;
- Ok(res.json().await?)
- },
- )
+ async_cache_memory("api-trakt-episodes", (id, season), || async move {
+ info!("trakt episodes {id:?} season={season}");
+ let url = format!("https://api.trakt.tv/shows/{id}/seasons/{season}?extended=full");
+ let res = self.client.get(url).send().await?.error_for_status()?;
+ Ok(res.json().await?)
+ })
.await
.context("trakt show season episodes")
}