-
Notifications
You must be signed in to change notification settings - Fork 0
/
hlsvalidator.go
89 lines (73 loc) · 1.79 KB
/
hlsvalidator.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
flag "github.com/spf13/pflag"
"github.com/ferpart/hlsvalidator/domain"
"github.com/ferpart/hlsvalidator/internal/reporter"
"github.com/ferpart/hlsvalidator/internal/validator"
"github.com/ferpart/hlsvalidator/pkg/appleHLSReport"
"github.com/ferpart/hlsvalidator/pkg/appleMediaStreamValidator"
)
var (
manifestURI string
times int
saveValid bool
parsePlaylist bool
)
func init() {
flag.StringVarP(
&manifestURI,
"manifest",
"m",
"https://example.com/playlist.m3u8",
"manifest url to verify with HLS spec",
)
flag.IntVarP(
×,
"times",
"t",
1,
"number of times to validate url",
)
flag.BoolVarP(
&saveValid,
"save-valid",
"s",
false,
"save reports for valid HLS manifests. validated jsons will always be generated",
)
flag.BoolVarP(
&parsePlaylist,
"parse-playlist-only",
"p",
false,
"Only parses an HLS playlist",
)
flag.Lookup("save-valid").NoOptDefVal = "true"
flag.Lookup("parse-playlist-only").NoOptDefVal = "true"
}
func main() {
flag.Parse()
HLSValidators := generateValidators()
validationMap := validator.Validate(manifestURI, HLSValidators)
HLSReporters := generateReporters(validationMap)
reporter.Report(HLSReporters)
fmt.Println("HLS spec validation done.")
}
func generateValidators() []domain.IHLSValidator {
var HLSValidators []domain.IHLSValidator
for i := 0; i < times; i++ {
HLSValidators = append(HLSValidators, appleMediaStreamValidator.New(parsePlaylist))
}
return HLSValidators
}
func generateReporters(validationMap map[string]bool) []domain.IHLSReporter {
var HLSReporters []domain.IHLSReporter
for uuid, isValid := range validationMap {
if !saveValid && isValid {
continue
}
HLSReporters = append(HLSReporters, appleHLSReport.New(uuid))
}
return HLSReporters
}