aboutsummaryrefslogtreecommitdiff
path: root/ui/src/format.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/format.rs')
-rw-r--r--ui/src/format.rs84
1 files changed, 42 insertions, 42 deletions
diff --git a/ui/src/format.rs b/ui/src/format.rs
index 11040de..811211a 100644
--- a/ui/src/format.rs
+++ b/ui/src/format.rs
@@ -4,7 +4,10 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use jellycommon::{LANG_ENG, Language};
+use jellycommon::{
+ jellyobject::{Object, Tag},
+ *,
+};
use crate::locale::tr;
use std::fmt::Write;
@@ -71,50 +74,47 @@ fn test_duration_long() {
pub fn format_size(size: u64) -> String {
humansize::format_size(size, humansize::DECIMAL)
}
-pub fn format_kind(k: NodeKind, lang: Language) -> TrString<'static> {
- trs(
- &lang,
- match k {
- NodeKind::Unknown => "kind.unknown",
- NodeKind::Movie => "kind.movie",
- NodeKind::Video => "kind.video",
- NodeKind::Music => "kind.music",
- NodeKind::ShortFormVideo => "kind.short_form_video",
- NodeKind::Collection => "kind.collection",
- NodeKind::Channel => "kind.channel",
- NodeKind::Show => "kind.show",
- NodeKind::Series => "kind.series",
- NodeKind::Season => "kind.season",
- NodeKind::Episode => "kind.episode",
+pub fn format_kind(lang: Language, kind: Tag) -> &'static str {
+ tr(
+ lang,
+ match kind {
+ KIND_MOVIE => "kind.movie",
+ KIND_VIDEO => "kind.video",
+ KIND_MUSIC => "kind.music",
+ KIND_SHORTFORMVIDEO => "kind.short_form_video",
+ KIND_COLLECTION => "kind.collection",
+ KIND_CHANNEL => "kind.channel",
+ KIND_SHOW => "kind.show",
+ KIND_SERIES => "kind.series",
+ KIND_SEASON => "kind.season",
+ KIND_EPISODE => "kind.episode",
+ _ => "kind.unknown",
},
)
}
-pub trait MediaInfoExt {
- fn resolution_name(&self) -> &'static str;
-}
-impl MediaInfoExt for &MediaInfo {
- fn resolution_name(&self) -> &'static str {
- let mut maxdim = 0;
- for t in &self.tracks {
- if let SourceTrackKind::Video { width, height, .. } = &t.kind {
- maxdim = maxdim.max(*width.max(height))
- }
+pub fn node_resolution_name(node: &Object) -> &'static str {
+ let mut maxdim = 0;
+ for t in node.iter(NO_TRACK) {
+ if let Some(width) = t.get(TR_PIXEL_WIDTH) {
+ maxdim = maxdim.max(width)
}
-
- match maxdim {
- 30720.. => "32K",
- 15360.. => "16K",
- 7680.. => "8K UHD",
- 5120.. => "5K UHD",
- 3840.. => "4K UHD",
- 2560.. => "QHD 1440p",
- 1920.. => "FHD 1080p",
- 1280.. => "HD 720p",
- 854.. => "SD 480p",
- _ => "Unkown",
+ if let Some(height) = t.get(TR_PIXEL_HEIGHT) {
+ maxdim = maxdim.max(height)
}
}
+ match maxdim {
+ 30720.. => "32K",
+ 15360.. => "16K",
+ 7680.. => "8K UHD",
+ 5120.. => "5K UHD",
+ 3840.. => "4K UHD",
+ 2560.. => "QHD 1440p",
+ 1920.. => "FHD 1080p",
+ 1280.. => "HD 720p",
+ 854.. => "SD 480p",
+ _ => "Unkown",
+ }
}
pub fn format_count(n: impl Into<usize>) -> String {
@@ -129,13 +129,13 @@ pub fn format_count(n: impl Into<usize>) -> String {
}
}
-pub fn format_chapter(c: &Chapter) -> (String, String) {
+pub fn format_chapter(c: &Object) -> (String, String) {
(
format!(
"{}-{}",
- c.time_start.map(format_duration).unwrap_or_default(),
- c.time_end.map(format_duration).unwrap_or_default(),
+ c.get(CH_START).map(format_duration).unwrap_or_default(),
+ c.get(CH_END).map(format_duration).unwrap_or_default(),
),
- c.labels.first().map(|l| l.1.clone()).unwrap_or_default(),
+ c.get(CH_NAME).unwrap_or_default().to_string(),
)
}