Skip to content

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

fix(tui): improve stream sorting by source label on size ties

Samir Hossainsf6697c7896fa
diff --git a/src/providers/addons/aggregator.rs b/src/providers/addons/aggregator.rs
index d1ef90b..eefa6ea 100644
--- a/src/providers/addons/aggregator.rs
+++ b/src/providers/addons/aggregator.rs
@@ -70,7 +70,14 @@ pub async fn aggregate_streams(
std::cmp::Ordering::Equal => {
let size_a = a.size_bytes.unwrap_or(0);
let size_b = b.size_bytes.unwrap_or(0);
- size_b.cmp(&size_a)
+ match size_b.cmp(&size_a) {
+ std::cmp::Ordering::Equal => {
+ let label_a = a.mirrors.first().map(|m| m.label.as_str()).unwrap_or("");
+ let label_b = b.mirrors.first().map(|m| m.label.as_str()).unwrap_or("");
+ label_a.cmp(label_b)
+ }
+ other => other,
+ }
}
other => other,
}
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index 0048e1c..cd394d6 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -785,7 +785,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.get("codecName")
.and_then(|c| c.as_str())
.unwrap_or("None");
- let size_str = file.get("size").and_then(|s| s.as_str()).unwrap_or("0");
+ let size_str = file.get("size").and_then(|s| s.as_str());
let duration = file.get("duration").and_then(|d| d.as_u64()).unwrap_or(0);
let duration_str = if duration > 0 {
@@ -801,15 +801,19 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
"--:--".to_string()
};
- let size_formatted = if let Ok(bytes) = size_str.parse::<f64>() {
- let mb = bytes / 1024.0 / 1024.0;
- if mb > 1024.0 {
- format!("{:.1}GB", mb / 1024.0)
+ let size_formatted = if let Some(s) = size_str {
+ if let Ok(bytes) = s.parse::<f64>() {
+ let mb = bytes / 1024.0 / 1024.0;
+ if mb > 1024.0 {
+ format!("{:.1}GB", mb / 1024.0)
+ } else {
+ format!("{:.0}MB", mb)
+ }
} else {
- format!("{:.0}MB", mb)
+ "--".to_string()
}
} else {
- "Unknown".to_string()
+ "--".to_string()
};
let is_selected = Some(i) == selected_idx;