Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(tv): reread local playlists directly
Samir Hossains78e429423a61
diff --git a/docs/cache.md b/docs/cache.mdindex b30847c..2bee59e 100644--- a/docs/cache.md+++ b/docs/cache.md@@ -14,7 +14,7 @@ Disk caching lives in `cache.rs`; in-memory caches live in `AppState`.moviebox/homepage/<tab>_<page>.jsoncaptions/captions_<hash>.json- tv_playlists/<md5>.m3u+ tv_playlists/<md5>.m3u cached remote playlist snapshots```The cache directory is `dirs::cache_dir()/moviebox-tui` (macOS@@ -26,7 +26,8 @@ The cache directory is `dirs::cache_dir()/moviebox-tui` (macOSdifferent providers never collide. Image caches are namespaced by provider (or`iptv` for channel logos).- **TTL**: streams expire after 2h; search/details/captions/images after 24h;- homepage after 1h.+ homepage after 1h; remote TV playlist snapshots after 24h. Local file playlists are+ reread directly instead of being served from the cache.- **Atomic writes**: data is written to a temp file then renamed, so a crash neverleaves a corrupt cache entry.- **Validation**: search/stream entries are only cached (and only served) if theydiff --git a/docs/tv-mode.md b/docs/tv-mode.mdindex be6f183..b14cb00 100644--- a/docs/tv-mode.md+++ b/docs/tv-mode.md@@ -18,8 +18,9 @@ groups, dedupes and lets you search and play them.2. Select `[ Add URL ]` or `[ Add file ]`, type the source, `Enter` to add.- URL example: `https://example.com/playlist.m3u`- File example: `~/playlists/mine.m3u`-3. Sources persist in `tv_config.json` (under the config dir) and are re-fetched on- every TV-mode entry.+3. Sources persist in `tv_config.json` (under the config dir). Local file playlists are+ reread directly on every TV-mode entry; remote URL playlists may reuse a recent+ cached snapshot for up to 24 hours.4. Highlight a source and press `d` (or `Enter`) to remove it; the list reloads.## Parsing and searchdiff --git a/src/providers/m3u.rs b/src/providers/m3u.rsindex 96850bc..e11f7b4 100644--- a/src/providers/m3u.rs+++ b/src/providers/m3u.rs@@ -40,24 +40,24 @@ impl M3UParser {&self,url: &str,) -> Result<Vec<Channel>, Box<dyn std::error::Error>> {- let file_path = self.cache_dir.join(cache_filename(url));- let mut needs_download = true;+ let trimmed = url.trim();+ let content = if trimmed.starts_with("http://") || trimmed.starts_with("https://") {+ let file_path = self.cache_dir.join(cache_filename(trimmed));+ let mut needs_download = true;- if file_path.exists() {- if let Ok(metadata) = tokio::fs::metadata(&file_path).await {- if let Ok(modified) = metadata.modified() {- if let Ok(duration) = SystemTime::now().duration_since(modified) {- if duration.as_secs() < 24 * 3600 {- needs_download = false;+ if file_path.exists() {+ if let Ok(metadata) = tokio::fs::metadata(&file_path).await {+ if let Ok(modified) = metadata.modified() {+ if let Ok(duration) = SystemTime::now().duration_since(modified) {+ if duration.as_secs() < 24 * 3600 {+ needs_download = false;+ }}}}}- }- let content = if needs_download {- let trimmed = url.trim();- if trimmed.starts_with("http://") || trimmed.starts_with("https://") {+ if needs_download {let res = self.client.get(trimmed)@@ -69,15 +69,13 @@ impl M3UParser {let _ = tokio::fs::write(&file_path, &res).await;res} else {- let path = std::path::PathBuf::from(trimmed);- let local = tokio::fs::read_to_string(&path).await.map_err(|error| {- format!("failed to read playlist file {}: {error}", trimmed)- })?;- let _ = tokio::fs::write(&file_path, &local).await;- local+ tokio::fs::read_to_string(&file_path).await?}} else {- tokio::fs::read_to_string(&file_path).await?+ let path = std::path::PathBuf::from(trimmed);+ tokio::fs::read_to_string(&path)+ .await+ .map_err(|error| format!("failed to read playlist file {}: {error}", trimmed))?};Ok(self.parse_m3u(&content))