aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Entities/MediaStream.cs
diff options
context:
space:
mode:
authorMrTimscampi <julien.machiels@protonmail.com>2021-07-03 01:32:57 +0200
committerMrTimscampi <julien.machiels@protonmail.com>2021-07-03 01:45:24 +0200
commitbcae195cc3dc0b4c39acb00b7c4590c871daf61c (patch)
tree09df1f867c78a60adf5f5564936f4df1e9ff55a3 /MediaBrowser.Model/Entities/MediaStream.cs
parent1dcf03e33c4f52f6d8a1036510ee57a5d037009a (diff)
Refactor GetResolutionText
This improves GetResolutionText a little by making it easier to read and better parsing resolutions (Also adding a few new ones like PAL resolutions and 8K) Co-authored-by: Maxr1998 <max.rumpf1998@gmail.com>
Diffstat (limited to 'MediaBrowser.Model/Entities/MediaStream.cs')
-rw-r--r--MediaBrowser.Model/Entities/MediaStream.cs75
1 files changed, 22 insertions, 53 deletions
diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs
index c67f30d04..bc3586ff2 100644
--- a/MediaBrowser.Model/Entities/MediaStream.cs
+++ b/MediaBrowser.Model/Entities/MediaStream.cs
@@ -471,62 +471,31 @@ namespace MediaBrowser.Model.Entities
private string GetResolutionText()
{
- var i = this;
-
- if (i.Width.HasValue && i.Height.HasValue)
+ if (!this.Width.HasValue || !this.Height.HasValue)
{
- var width = i.Width.Value;
- var height = i.Height.Value;
-
- if (width >= 3800 || height >= 2000)
- {
- return "4K";
- }
-
- if (width >= 2500)
- {
- if (i.IsInterlaced)
- {
- return "1440i";
- }
-
- return "1440p";
- }
-
- if (width >= 1900 || height >= 1000)
- {
- if (i.IsInterlaced)
- {
- return "1080i";
- }
-
- return "1080p";
- }
-
- if (width >= 1260 || height >= 700)
- {
- if (i.IsInterlaced)
- {
- return "720i";
- }
-
- return "720p";
- }
-
- if (width >= 700 || height >= 440)
- {
- if (i.IsInterlaced)
- {
- return "480i";
- }
-
- return "480p";
- }
-
- return "SD";
+ return null;
}
- return null;
+ var width = this.Width.Value;
+ var height = this.Height.Value;
+
+ return width switch
+ {
+ <= 720 when height <= 480 => this.IsInterlaced ? "480i" : "480p",
+ // 720x576 (PAL) (768 when rescaled for square pixels)
+ <= 768 when height <= 576 => this.IsInterlaced ? "576i" : "576p",
+ // 960x540 (sometimes 544 which is multiple of 16)
+ <= 960 when height <= 544 => this.IsInterlaced ? "540i" : "540p",
+ // 1280x720
+ <= 1280 when height <= 962 => this.IsInterlaced ? "720i" : "720p",
+ // 1920x1080
+ <= 1920 when height <= 1440 => this.IsInterlaced ? "1080i" : "1080p",
+ // 4K
+ <= 4096 when height <= 3072 => "4K",
+ // 8K
+ <= 8192 when height <= 6144 => "8K",
+ _ => null
+ };
}
public static bool IsTextFormat(string format)