Skip to content

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

fix(download): ensure MovieBox-TUI subfolder hierarchy is created inside custom download directories

Samir Hossains14a71eac9216
diff --git a/docs/downloads.md b/docs/downloads.md
index edfc4da..460a0b1 100644
--- a/docs/downloads.md
+++ b/docs/downloads.md
@@ -25,7 +25,7 @@ and length is capped.
- **Series downloads:** Saved under `<base_dir>/Series/<Title>/Season <N>/<Title> - S<N:02>E<E:02>.<ext>` (and subtitle `<Title> - S<N:02>E<E:02>.<lang>.<sub_ext>`).
- **Movie downloads:** Saved under `<base_dir>/Movies/<Title>/<Title>.<ext>` (and subtitle `<Title>.<lang>.<sub_ext>`).
- **Default path:** Files go to the user's OS download directory (`~/Downloads/MovieBox-TUI`). On Android-family environments the code prefers shared `storage/downloads` when present.
-- **Custom path:** Users can set a custom download directory using `/download-dir <path>` or revert with `/download-dir reset`. Target directories are validated with active write probes before saving, and the engine automatically falls back to default if custom storage becomes unavailable at runtime.
+- **Custom path:** Users can set a custom download directory using `/download-dir <path>` or revert with `/download-dir reset`. Target directories are validated with active write probes before saving, consistently creating the organized `MovieBox-TUI` subfolder hierarchy (`Movies/` and `Series/`), and the engine automatically falls back to default if custom storage becomes unavailable at runtime.
## Contextual triggers & Seasons
diff --git a/src/tui/app/download.rs b/src/tui/app/download.rs
index ae07999..3e55355 100644
--- a/src/tui/app/download.rs
+++ b/src/tui/app/download.rs
@@ -2,6 +2,22 @@ use super::App;
use crate::providers::models::ProviderKind;
use crate::tui::{action::Action, overlay::NotificationKind, state::Screen};
+fn ensure_moviebox_subdir(path: &std::path::Path) -> std::path::PathBuf {
+ let is_already_mb = path
+ .file_name()
+ .map(|name| {
+ let s = name.to_string_lossy();
+ s.eq_ignore_ascii_case("MovieBox-TUI") || s.eq_ignore_ascii_case("MovieBox")
+ })
+ .unwrap_or(false);
+
+ if is_already_mb {
+ path.to_path_buf()
+ } else {
+ path.join("MovieBox-TUI")
+ }
+}
+
impl App {
pub(super) fn resolve_download_base_dir(&self) -> std::path::PathBuf {
if let Some(ref custom_dir) = self.state.download_dir {
@@ -16,7 +32,7 @@ impl App {
}
}
if cached_ok {
- return custom_dir.clone();
+ return ensure_moviebox_subdir(custom_dir);
}
if std::fs::create_dir_all(custom_dir).is_ok() {
let probe = custom_dir.join(format!(".mb_probe_{}", std::process::id()));
@@ -25,7 +41,7 @@ impl App {
if let Ok(mut guard) = LAST_PROBE.lock() {
*guard = Some((custom_dir.clone(), std::time::Instant::now()));
}
- return custom_dir.clone();
+ return ensure_moviebox_subdir(custom_dir);
}
}
log::warn!("Custom download directory inaccessible; falling back to default");
@@ -46,7 +62,7 @@ impl App {
base_dir
};
- base_dir.join("MovieBox-TUI")
+ ensure_moviebox_subdir(&base_dir)
}
pub(super) fn start_resilient_download(
diff --git a/src/tui/app/search.rs b/src/tui/app/search.rs
index 397902d..35e1963 100644
--- a/src/tui/app/search.rs
+++ b/src/tui/app/search.rs
@@ -188,14 +188,7 @@ impl App {
self.state.input_mode = InputMode::Normal;
if raw_arg.is_empty() {
- let current = if let Some(ref custom) = self.state.download_dir {
- crate::logging::sanitize_path(custom)
- } else {
- let default_base = dirs::download_dir()
- .or_else(|| dirs::home_dir().map(|h| h.join("Downloads")))
- .unwrap_or_else(|| std::path::PathBuf::from("."));
- crate::logging::sanitize_path(default_base.join("MovieBox-TUI"))
- };
+ let current = crate::logging::sanitize_path(self.resolve_download_base_dir());
self.state
.notify(NotificationKind::Info, "Download Directory", current);
return Some(true);
@@ -266,10 +259,12 @@ impl App {
};
self.state.download_dir = Some(clean_path.clone());
self.persist_config();
+ let effective =
+ crate::logging::sanitize_path(self.resolve_download_base_dir());
self.state.notify(
NotificationKind::Success,
"Download Directory",
- format!("Saved: {}", clean_path.display()),
+ format!("Saved: {effective}"),
);
}
Err(err) => {