-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
93 lines (86 loc) · 3.13 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
81
82
83
84
85
86
87
88
89
90
91
92
93
// Set of 360 photo utilities
//
// See Readme.md
// see https://github.com/googleapis/google-api-go-client
package main
import (
"flag"
"fmt"
"log"
"os"
"os/exec"
"strings"
)
func main() {
// Flags
var (
clientID = flag.String("clientid", "", "Google OAuth 2.0 Client ID. If non-empty, overrides --clientid_file")
clientIDFile = flag.String("clientid-file", "clientid.dat",
"Name of a file containing just the project's Google OAuth 2.0 Client ID from https://developers.google.com/console.")
secret = flag.String("secret", "", "Google OAuth 2.0 Client Secret. If non-empty, overrides --secret_file")
secretFile = flag.String("secret-file", "clientsecret.dat",
"Name of a file containing just the project's OAuth 2.0 Client Secret from https://developers.google.com/console.")
apikey = flag.String("apikey", "", "Google API key. If non-empty, overrides --apikey_file")
apiKeyFile = flag.String("apikey-file", "apikey.dat",
"Name of a file containing just the project's Google API key from https://developers.google.com/console.")
cacheToken = flag.Bool("cachetoken", true, "cache the Google OAuth 2.0 token")
pois = flag.Bool("pois", false, "only list the nearest points of interest - requires api token")
skipConnections = flag.Bool("skip-connections", false, "skip Google Maps connections")
placeId = flag.String("placeid", "", "place id (from --pois output) to add to upload")
mapType = flag.String("map-type", "google", "Map type - google, for Google Street View, umap for OpenStreetMap uMap.")
outputDirectory = flag.String("output-dir", "umap", "Output directory for uMap files.")
webURL = flag.String("web-url", "", "URL of web server that hosts photos for uMap server.")
)
flag.Usage = func() {
fmt.Printf("Tools to upload 360 images to Google Maps and OpenStreetMap uMap\n\nUsage: %s [flags] [jpg files] [gpx files]\n\nWhere [flags] can be:\n\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() == 0 {
log.Println("No jpgs supplied")
flag.PrintDefaults()
os.Exit(1)
}
if *pois {
listPois(apikey, apiKeyFile, flag.Args())
os.Exit(0)
}
if *mapType == "google" {
uploadGoogleMaps(clientID, clientIDFile, secret, secretFile, apikey, apiKeyFile, cacheToken, skipConnections, placeId, flag.Args())
} else if *mapType == "umap" {
if len(*webURL) == 0 {
log.Println("Web URL must be provided")
flag.PrintDefaults()
os.Exit(1)
}
err := createUmapFiles(outputDirectory, webURL, flag.Args())
if err != nil {
log.Println(err)
os.Exit(1)
}
} else {
log.Println("Invalid map type - must be one of google or umap")
flag.PrintDefaults()
os.Exit(1)
}
}
func openURL(url string) {
try := []string{"xdg-open", "google-chrome", "open"}
for _, bin := range try {
err := exec.Command(bin, url).Run()
if err == nil {
return
}
}
log.Printf("Error opening URL in browser.")
}
func valueOrFileContents(value string, filename string) string {
if value != "" {
return value
}
slurp, err := os.ReadFile(filename)
if err != nil {
log.Fatalf("Error reading %q: %v", filename, err)
}
return strings.TrimSpace(string(slurp))
}