-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (73 loc) · 1.93 KB
/
main.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
// Simple GPS track processor for sailing race tracks (.gpx)
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"sort"
"time"
"github.com/tkrajina/gpxgo/gpx"
)
var (
// Build Parameters
Built string // time built in UTC
Commit string // source commit SHA
Branch string // source branch
GoVersion string // Go version used to build
)
func main() {
// flags
out := flag.String("o", ".", "directory for generated files")
var videoOffset *time.Duration
flag.Func("vo", "video time offset for subtitles file, positive offset means video starts ahead of the track", func(ts string) error {
d, err := time.ParseDuration(ts)
if err != nil {
return err
}
videoOffset = &d
return nil
})
fVersion := flag.Bool("version", false, "print version information")
flag.Parse()
if *fVersion {
fmt.Println("built on " + Built)
fmt.Printf("built from %s@%s\n", Branch, Commit)
fmt.Println("built with " + GoVersion)
os.Exit(0)
}
// args
if len(flag.Args()) == 0 {
fmt.Println("Transforms specified gpx files into a gpx, svg and video subtitles files for individual race tracks")
fmt.Println("Usage: gpx [-o <dir>] [-vo <duration>] <files>")
flag.Usage()
return
}
var segments Segments
for _, fn := range flag.Args() {
g, err := gpx.ParseFile(fn)
if err != nil {
fmt.Printf("Error opening %s: %s\n", fn, err)
return
}
segments = append(segments, GetSegments(g, filepath.Base(fn))...)
}
sort.Sort(segments)
sn := len(segments)
segments = segments.Dedupe(20).Split(time.Hour).Dedupe(20)
fmt.Printf("Dropped %d duplicate and bogus segments\n", sn-len(segments))
for _, t := range segments.Tracks(time.Hour) {
fmt.Println(t.String())
if err := t.WriteMapFile(*out); err != nil {
fmt.Println(err)
}
if videoOffset != nil {
if err := t.WriteSubtitleFile(*out, *videoOffset); err != nil {
fmt.Println(err)
}
}
if err := t.WriteGpxFile(*out); err != nil {
fmt.Println(err)
}
}
}