model/resolution.go

43 lines
735 B
Go
Raw Permalink Normal View History

2022-08-04 16:45:36 +02:00
package model
import (
2022-08-15 14:23:39 +02:00
"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
}
}
2022-08-15 14:23:39 +02:00
func (r Resolution) String() string {
switch r {
case Resolution4K:
return "4K"
default:
return fmt.Sprintf("%dp", r)
}
}