50 lines
2.3 KiB
Go
50 lines
2.3 KiB
Go
package arr
|
|
|
|
import (
|
|
"encoding/json"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func attrs(t *testing.T, raw string) FileAttrs {
|
|
t.Helper()
|
|
var f MediaFile
|
|
if err := json.Unmarshal([]byte(raw), &f); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return f.Attrs()
|
|
}
|
|
|
|
func TestAttrsFromMediaInfo(t *testing.T) {
|
|
a := attrs(t, `{"quality":{"quality":{"name":"Bluray-2160p","resolution":2160}},
|
|
"mediaInfo":{"videoCodec":"x265","videoDynamicRange":"HDR","videoDynamicRangeType":"DV HDR10"},
|
|
"languages":[{"name":"English"},{"name":"German"}]}`)
|
|
want := FileAttrs{Resolution: 2160, Codec: CodecX265, HDR: true, DV: true, Languages: []string{"English", "German"}}
|
|
if !reflect.DeepEqual(a, want) {
|
|
t.Errorf("got %+v, want %+v", a, want)
|
|
}
|
|
}
|
|
|
|
func TestAttrsVariants(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, raw string
|
|
check func(FileAttrs) bool
|
|
}{
|
|
{"hevc codec", `{"mediaInfo":{"videoCodec":"HEVC"}}`, func(a FileAttrs) bool { return a.Codec == CodecX265 }},
|
|
{"h264 codec", `{"mediaInfo":{"videoCodec":"h264"}}`, func(a FileAttrs) bool { return a.Codec == CodecX264 }},
|
|
{"avc codec", `{"mediaInfo":{"videoCodec":"AVC"}}`, func(a FileAttrs) bool { return a.Codec == CodecX264 }},
|
|
{"av1 codec", `{"mediaInfo":{"videoCodec":"AV1"}}`, func(a FileAttrs) bool { return a.Codec == CodecAV1 }},
|
|
{"unoffered codec is not guessed from the name", `{"sceneName":"x264.Movie","mediaInfo":{"videoCodec":"VC-1"}}`, func(a FileAttrs) bool { return a.Codec == "" }},
|
|
{"codec from scene name", `{"sceneName":"Movie.2020.1080p.BluRay.x265-GRP"}`, func(a FileAttrs) bool { return a.Codec == CodecX265 && a.Resolution == 1080 }},
|
|
{"dv from path", `{"relativePath":"Movie.2160p.DV.HDR10.mkv"}`, func(a FileAttrs) bool { return a.DV && a.HDR && a.Resolution == 2160 }},
|
|
{"dv only", `{"mediaInfo":{"videoDynamicRangeType":"DV"}}`, func(a FileAttrs) bool { return a.DV && !a.HDR }},
|
|
{"hlg is hdr", `{"mediaInfo":{"videoDynamicRangeType":"HLG"}}`, func(a FileAttrs) bool { return a.HDR && !a.DV }},
|
|
{"sdr", `{"mediaInfo":{"videoCodec":"x264"},"sceneName":"Movie.HDRip.x264"}`, func(a FileAttrs) bool { return !a.HDR && !a.DV }},
|
|
{"hdr word in a title is not enough with media info", `{"relativePath":"Hdr.Story.mkv","mediaInfo":{"videoDynamicRange":"SDR"}}`, func(a FileAttrs) bool { return !a.HDR }},
|
|
} {
|
|
if !tc.check(attrs(t, tc.raw)) {
|
|
t.Errorf("%s: got %+v", tc.name, attrs(t, tc.raw))
|
|
}
|
|
}
|
|
}
|