Skip to content

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

refactor(moviebox): move clean_moviebox_title to the provider

Samir Hossainse56e0cfd5363
diff --git a/src/providers/moviebox/mod.rs b/src/providers/moviebox/mod.rs
index cda54e9..cb096c5 100644
--- a/src/providers/moviebox/mod.rs
+++ b/src/providers/moviebox/mod.rs
@@ -1,5 +1,8 @@
pub mod client;
pub mod crypto;
+pub mod title;
+
+pub use title::clean_moviebox_title;
use client::{MovieBoxClient, ScraperError};
use serde_json::{Value, json};
diff --git a/src/providers/moviebox/title.rs b/src/providers/moviebox/title.rs
new file mode 100644
index 0000000..e3b0179
--- /dev/null
+++ b/src/providers/moviebox/title.rs
@@ -0,0 +1,24 @@
+pub fn clean_moviebox_title(raw_title: &str) -> String {
+ let mut end = raw_title.len();
+
+ if let Some(start) = raw_title[..end].find(" [") {
+ end = start;
+ }
+ if let Some(start) = raw_title[..end].find(" (") {
+ let inside = &raw_title[start..end].to_lowercase();
+ if inside.contains("dub") || inside.contains("hindi") {
+ end = start;
+ }
+ }
+
+ if let Some(s_idx) = raw_title[..end].rfind(" S") {
+ let suffix = &raw_title[s_idx + 2..end];
+ let is_season = suffix
+ .chars()
+ .all(|c| c.is_ascii_digit() || c == '-' || c == 'S');
+ if is_season && suffix.chars().next().is_some_and(|c| c.is_ascii_digit()) {
+ end = s_idx;
+ }
+ }
+ raw_title[..end].trim_end().to_string()
+}
diff --git a/src/tui/app/download.rs b/src/tui/app/download.rs
index 4a4305b..a871ca5 100644
--- a/src/tui/app/download.rs
+++ b/src/tui/app/download.rs
@@ -44,7 +44,7 @@ impl App {
.unwrap_or(1);
let season = self.state.selected_season;
let episode = self.state.selected_episode;
- let clean_title = crate::tui::app::clean_moviebox_title(title);
+ let clean_title = crate::providers::moviebox::clean_moviebox_title(title);
let safe_title = crate::download::safe_file_stem(&clean_title);
let extension = self
diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rs
index e24bfe2..d20a2a7 100644
--- a/src/tui/app/mod.rs
+++ b/src/tui/app/mod.rs
@@ -17,31 +17,6 @@ mod run;
mod system;
mod tv;
-pub fn clean_moviebox_title(raw_title: &str) -> String {
- let mut end = raw_title.len();
-
- if let Some(start) = raw_title[..end].find(" [") {
- end = start;
- }
- if let Some(start) = raw_title[..end].find(" (") {
- let inside = &raw_title[start..end].to_lowercase();
- if inside.contains("dub") || inside.contains("hindi") {
- end = start;
- }
- }
-
- if let Some(s_idx) = raw_title[..end].rfind(" S") {
- let suffix = &raw_title[s_idx + 2..end];
- let is_season = suffix
- .chars()
- .all(|c| c.is_ascii_digit() || c == '-' || c == 'S');
- if is_season && suffix.chars().next().is_some_and(|c| c.is_ascii_digit()) {
- end = s_idx;
- }
- }
- raw_title[..end].trim_end().to_string()
-}
-
pub struct App {
state: AppState,
theme: Theme,
diff --git a/src/tui/app/requests.rs b/src/tui/app/requests.rs
index 949db06..87a0c10 100644
--- a/src/tui/app/requests.rs
+++ b/src/tui/app/requests.rs
@@ -612,7 +612,8 @@ impl App {
.unwrap_or("Unknown")
.to_string();
- let clean_title = crate::tui::app::clean_moviebox_title(&raw_title);
+ let clean_title =
+ crate::providers::moviebox::clean_moviebox_title(&raw_title);
let normalized_query = query
.to_lowercase()
@@ -853,7 +854,7 @@ impl App {
.and_then(|t| t.as_str())
.unwrap_or("Unknown")
.to_string();
- let clean_title = crate::tui::app::clean_moviebox_title(&raw_title);
+ let clean_title = crate::providers::moviebox::clean_moviebox_title(&raw_title);
let stype = item
.get("subjectType")
.and_then(|st| st.as_i64())
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index 2bf9869..720e222 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -120,7 +120,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.get("title")
.and_then(|t| t.as_str())
.unwrap_or("Unknown Title");
- let title = crate::tui::app::clean_moviebox_title(raw_title);
+ let title = crate::providers::moviebox::clean_moviebox_title(raw_title);
let intro = details_json
.get("description")
.and_then(|d| d.as_str())