-
Notifications
You must be signed in to change notification settings - Fork 2
/
list.go
89 lines (83 loc) · 1.72 KB
/
list.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 list
import (
"flag"
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/coding-socks/ebml"
"github.com/coding-socks/matroska"
"github.com/coding-socks/matroska/cmd/mkc/internal/cli"
"io"
"log"
"os"
"strconv"
)
var Cmd = &cli.Command{
Flags: flag.NewFlagSet("list", flag.ContinueOnError),
}
func init() {
Cmd.Run = run
}
type arguments struct {
Input string
}
func run(flags *flag.FlagSet) {
args := arguments{
Input: flags.Arg(0),
}
var questions []*survey.Question
if args.Input == "" {
questions = append(questions, &survey.Question{
Name: "input",
Prompt: &survey.Input{Message: "Source matroska file:"},
Validate: survey.ComposeValidators(survey.Required, cli.ValidatorFile),
})
}
if err := survey.Ask(questions, &args); err == terminal.InterruptErr {
return
} else if err != nil {
log.Fatal(err)
}
f, err := os.Open(args.Input)
if err != nil {
log.Fatalf("Could not open input file: %s", args.Input)
}
r := ebml.NewReader(f)
for {
el, _, err := r.Next()
if err != nil {
log.Fatal(err)
}
switch el.ID {
default:
log.Fatalf("ebml: unexpected element %s in root", el.ID)
case ebml.IDVoid:
continue
case ebml.IDEBML:
fmt.Print("+ EBML head\n")
}
r.Seek(el.DataSize.Size(), io.SeekCurrent)
break
}
for {
el, _, err := r.Next()
if err != nil {
log.Fatal(err)
}
switch el.ID {
default:
log.Fatalf("ebml: unexpected element %s in root", el.ID)
case ebml.IDVoid:
continue
case matroska.IDSegment:
var size string
if el.DataSize.Known() {
size = strconv.FormatInt(el.DataSize.Size(), 10)
} else {
size = "unknown"
}
fmt.Printf("+ Segment: size %s\n", size)
}
break
}
}