model/resolution.go

43 lines
735 B
Go
Raw Normal View History

2022-08-04 16:45:36 +02:00
package model
import (
"fmt"
2022-08-04 16:45:36 +02:00
"strconv"
"strings"
)
type Resolution int
const (
2022-08-04 17:49:59 +02:00
Resolution4K Resolution = 2160
ResolutionQuadHD Resolution = 1440
ResolutionFullHD Resolution = 1080
ResolutionHD Resolution = 720
ResolutionSD Resolution = 480
2022-08-04 16:45:36 +02:00
ResolutionUnknown Resolution = 0
)
func ParseResolution(str string) (Resolution, error) {
switch strings.TrimSpace(str) {
case "4K":
return Resolution4K, nil
case "HD":
return ResolutionHD, nil
case "SD":
return ResolutionSD, nil
default:
2022-08-04 17:49:59 +02:00
v, err := strconv.Atoi(strings.TrimSuffix(str, "p"))
2022-08-04 16:45:36 +02:00
return Resolution(v), err
}
}
func (r Resolution) String() string {
switch r {
case Resolution4K:
return "4K"
default:
2022-08-15 14:31:55 +02:00
return fmt.Sprintf("%dp", r)
}
}