From 2594a8463f87bbdb2bc2c044bcb10c900dea8ff8 Mon Sep 17 00:00:00 2001 From: matt-hb <122568249+matt-hb@users.noreply.github.com> Date: Fri, 7 Nov 2025 11:13:50 +0100 Subject: [PATCH] fix: Bitrate display in Media Info (#556) --- lib/models/information_model.dart | 7 ++++--- lib/util/bitrate_formatting.dart | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 lib/util/bitrate_formatting.dart diff --git a/lib/models/information_model.dart b/lib/models/information_model.dart index a6a5050..738c303 100644 --- a/lib/models/information_model.dart +++ b/lib/models/information_model.dart @@ -1,6 +1,7 @@ // ignore_for_file: constant_identifier_names import 'package:fladder/jellyfin/jellyfin_open_api.swagger.dart'; +import 'package:fladder/util/bitrate_formatting.dart'; import 'package:fladder/util/size_formatting.dart'; class InformationModel { @@ -35,10 +36,10 @@ class InformationModel { "Profile": e.profile, "Level": e.level, "Resolution": "${e.width}x${e.height}", - "Aspect Ration": e.aspectRatio, + "Aspect Ratio": e.aspectRatio, "Interlaced": e.isInterlaced, "FrameRate": e.realFrameRate, - "Bitrate": "${e.bitRate} kbps", + "Bitrate": e.bitRate.videoBitrateFormat, "Bit depth": e.bitDepth, "Video range": e.videoRange, "Video range type": e.videoRangeType, @@ -53,7 +54,7 @@ class InformationModel { "Language": e.language, "Codec": e.codec, "Layout": e.channelLayout, - "Bitrate": "${e.bitRate} kbps", + "Bitrate": e.bitRate.audioBitrateFormat, "Sample Rate": "${e.sampleRate} Hz", "Default": e.isDefault, "Forced": e.isForced, diff --git a/lib/util/bitrate_formatting.dart b/lib/util/bitrate_formatting.dart new file mode 100644 index 0000000..d87de68 --- /dev/null +++ b/lib/util/bitrate_formatting.dart @@ -0,0 +1,23 @@ +// ignore_for_file: constant_identifier_names + +extension BitrateFormats on int? { + String? get audioBitrateFormat { + final bitrate = this; + if (bitrate == null) return null; + return "${(bitrate / 1000).round()} kbps"; + } + + String? get videoBitrateFormat { + const int highBitrateCutoff = 10000000; + const int kb = 1000; + const int Mb = kb * kb; + + final bitrate = this; + if (bitrate == null) return null; + if (bitrate >= highBitrateCutoff) { + return "${(bitrate / Mb).toStringAsFixed(1)} Mbps"; + } else { + return "${(bitrate / kb).round()} kbps"; + } + } +}