Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

feat(cache): add moviebox subtitle caching

Samir Hossainsf96984cd4b1c
diff --git a/src/cache.rs b/src/cache.rs
index 9626ca6..4825e70 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -386,3 +386,18 @@ pub fn set_namespaced_image_cache(namespace: &str, id: &str, bytes: &[u8]) {
}
}
}
+
+pub fn get_captions_path(subject_id: &str, resource_id: &str) -> PathBuf {
+ let mut path = get_provider_cache_dir(ProviderKind::MovieBox, "captions");
+ let hashed_id = hash_key(&format!("{}_{}", subject_id, resource_id));
+ path.push(format!("captions_{}.json", hashed_id));
+ path
+}
+
+pub fn get_captions_cache(subject_id: &str, resource_id: &str) -> Option<serde_json::Value> {
+ read_json_cache(&get_captions_path(subject_id, resource_id), CACHE_EXPIRY_SECS)
+}
+
+pub fn set_captions_cache(subject_id: &str, resource_id: &str, data: &serde_json::Value) {
+ write_json_cache(&get_captions_path(subject_id, resource_id), data);
+}
diff --git a/src/tui/app.rs b/src/tui/app.rs
index d11a398..1d9e303 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -3257,7 +3257,14 @@ impl App {
let sender = self.action_sender.clone();
let link_clone = link.clone();
tokio::spawn(async move {
+ if let Some(res) = crate::cache::get_captions_cache(&subject_id, &rid) {
+ sender
+ .send(Action::ShowSubtitlePopup(link_clone.clone(), res, open_with))
+ .ok();
+ return;
+ }
if let Ok(res) = client.get_ext_captions(&subject_id, &rid).await {
+ crate::cache::set_captions_cache(&subject_id, &rid, &res);
sender
.send(Action::ShowSubtitlePopup(link_clone, res, open_with))
.ok();