From 629acf48552f9302f869ead7b908735139f5f103 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 6 May 2024 18:00:28 +0200 Subject: [PATCH] Use builtin cmp.Or instead of custom one --- transcoder/src/codec.go | 3 ++- transcoder/src/info.go | 16 ++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/transcoder/src/codec.go b/transcoder/src/codec.go index 023ce166..e6afd0ac 100644 --- a/transcoder/src/codec.go +++ b/transcoder/src/codec.go @@ -1,6 +1,7 @@ package src import ( + "cmp" "fmt" "strings" @@ -14,7 +15,7 @@ import ( // // this code is addapted from https://github.com/jellyfin/jellyfin/blob/master/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs func GetMimeCodec(mi *mediainfo.File, kind mediainfo.StreamKind, i int) *string { - codec := Or( + codec := cmp.Or( mi.Parameter(kind, i, "InternetMediaType"), mi.Parameter(kind, i, "Format"), ) diff --git a/transcoder/src/info.go b/transcoder/src/info.go index b79fdeb8..5a78a1f2 100644 --- a/transcoder/src/info.go +++ b/transcoder/src/info.go @@ -1,6 +1,7 @@ package src import ( + "cmp" "encoding/base64" "encoding/json" "fmt" @@ -140,19 +141,6 @@ func ParseTime(str string) float32 { return (hours*60.+minutes)*60. + seconds + ms/1000. } -// Stolen from the cmp.Or code that is not yet released -// Or returns the first of its arguments that is not equal to the zero value. -// If no argument is non-zero, it returns the zero value. -func Or[T comparable](vals ...T) T { - var zero T - for _, val := range vals { - if val != zero { - return val - } - } - return zero -} - func Map[T, U any](ts []T, f func(T, int) U) []U { us := make([]U, len(ts)) for i := range ts { @@ -268,7 +256,7 @@ func getInfo(path string) (*MediaInfo, error) { Width: ParseUint(mi.Parameter(mediainfo.StreamVideo, i, "Width")), Height: ParseUint(mi.Parameter(mediainfo.StreamVideo, i, "Height")), Bitrate: ParseUint( - Or( + cmp.Or( mi.Parameter(mediainfo.StreamVideo, i, "BitRate"), mi.Parameter(mediainfo.StreamVideo, i, "OverallBitRate"), mi.Parameter(mediainfo.StreamVideo, i, "BitRate_Nominal"),