-
Notifications
You must be signed in to change notification settings - Fork 2
/
resolution.go
56 lines (49 loc) · 1.56 KB
/
resolution.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package torrentparser
import (
"regexp"
"strings"
)
var (
resolutionX = regexp.MustCompile(`(?i)[0-9]{3,4}x([0-9]{3,4})`)
resolution4k = regexp.MustCompile(`(?i)\b4k\b`)
resolution8k = regexp.MustCompile(`(?i)\b8k\b`)
resolutionGeneral = regexp.MustCompile(`(?i)[0-9]{3,4}[pi]`)
)
type Resolution string
const (
Resolution480p Resolution = "480p"
Resolution576p Resolution = "576p"
Resolution720p Resolution = "720p"
Resolution1080i Resolution = "1080i"
Resolution1080p Resolution = "1080p"
Resolution4k Resolution = "2160p"
Resolution8k Resolution = "4320p"
ResolutionUnknown Resolution = ""
)
func (r Resolution) Verify() bool {
switch r {
case Resolution480p, Resolution576p, Resolution720p, Resolution1080i, Resolution1080p, Resolution4k, Resolution8k:
return true
default:
return false
}
}
func (p *parser) GetResolution() Resolution {
resolution := p.FindString("resolution", resolutionX, FindStringOptions{Handler: func(str string) string {
return strings.ToLower(str) + "p"
}})
if resolution != "" {
return Resolution(resolution)
}
resolution = p.FindString("resolution", resolutionGeneral, FindStringOptions{Handler: func(str string) string {
return strings.ToLower(str)
}})
if resolution != "" {
return Resolution(resolution)
}
resolution = p.FindString("resolution", resolution4k, FindStringOptions{Value: string(Resolution4k)})
if resolution != "" {
return Resolution(resolution)
}
return Resolution(p.FindString("resolution", resolution8k, FindStringOptions{Value: string(Resolution8k)}))
}