fix(library): classify resolution by width + height, not height alone
Cinematic widescreen content (1920×804 at 2.39:1, 3840×1600 21:9, etc.) was being misclassified: a 1080p source presented as 1920×804 fell to 720p because 804 < 900. Same shape for 2160p sources letterboxed below 2000px tall. ResolveResolution now takes (width, height) and picks the larger of the width-derived and height-derived buckets, so anamorphic/letterboxed sources land in the right bucket.
This commit is contained in:
parent
0b2462c82a
commit
9df38c95a3
4 changed files with 62 additions and 20 deletions
|
|
@ -13,8 +13,17 @@ var (
|
|||
altEpRegex = regexp.MustCompile(`(?i)(\d{1,2})x(\d{2})`)
|
||||
)
|
||||
|
||||
// ResolveResolution maps a pixel height to a standard resolution label.
|
||||
func ResolveResolution(height int) string {
|
||||
// ResolveResolution maps video dimensions to a standard resolution label.
|
||||
// Uses both width and height so cinematic aspect ratios (2.35:1, 2.39:1, 21:9)
|
||||
// are not misclassified — e.g. a 1080p source presented as 1920×804 letterboxed
|
||||
// would fall to 720p if classified by height alone.
|
||||
func ResolveResolution(width, height int) string {
|
||||
byHeight := resolutionByHeight(height)
|
||||
byWidth := resolutionByWidth(width)
|
||||
return maxResolution(byHeight, byWidth)
|
||||
}
|
||||
|
||||
func resolutionByHeight(height int) string {
|
||||
switch {
|
||||
case height >= 2000:
|
||||
return "2160p"
|
||||
|
|
@ -29,6 +38,36 @@ func ResolveResolution(height int) string {
|
|||
}
|
||||
}
|
||||
|
||||
func resolutionByWidth(width int) string {
|
||||
switch {
|
||||
case width >= 3400:
|
||||
return "2160p"
|
||||
case width >= 1800:
|
||||
return "1080p"
|
||||
case width >= 1200:
|
||||
return "720p"
|
||||
case width >= 800:
|
||||
return "480p"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
var resolutionRank = map[string]int{
|
||||
"": 0,
|
||||
"480p": 1,
|
||||
"720p": 2,
|
||||
"1080p": 3,
|
||||
"2160p": 4,
|
||||
}
|
||||
|
||||
func maxResolution(a, b string) string {
|
||||
if resolutionRank[a] >= resolutionRank[b] {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// DeriveContentType guesses "movie" or "show" from parsed metadata.
|
||||
func DeriveContentType(item LibraryItem) string {
|
||||
if item.Season > 0 || item.Episode > 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue