Skip to content

Commit 6796b24

Browse files
committed
Add the streams subcomand to onvif-cli
1 parent 21604e7 commit 6796b24

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

bin/onvif-cli/discover.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ package main
55
import (
66
"context"
77
"fmt"
8+
"github.com/jfsmig/onvif/sdk"
89
"net"
910

1011
wsdiscovery "github.com/jfsmig/onvif/ws-discovery"
1112
)
1213

13-
func discover(ctx context.Context) error {
14+
func discover(ctx context.Context, flagStreams bool) error {
1415
interfaces, err := net.Interfaces()
1516
if err != nil {
1617
return err
@@ -25,7 +26,17 @@ func discover(ctx context.Context) error {
2526
if dev.Uuid == "" {
2627
dev.Uuid = "-"
2728
}
28-
fmt.Println(dev.Xaddr, dev.Uuid)
29+
if !flagStreams {
30+
fmt.Println(dev.Xaddr, dev.Uuid)
31+
} else {
32+
if cam, err := sdk.NewDevice(ctx, dev, auth, &httpClient); err != nil {
33+
Logger.Error().Err(err).Msg("Camera instanciation failure")
34+
} else {
35+
for id, profile := range cam.FetchProfiles(ctx).Profiles {
36+
fmt.Println(dev.Xaddr, dev.Uuid, id, profile.Uris.Stream.Uri, profile.Uris.Snapshot.Uri)
37+
}
38+
}
39+
}
2940
}
3041
}
3142
}

bin/onvif-cli/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ func main() {
5757
Aliases: []string{"find", "crawl", "probe"},
5858
Short: "Discover the local cameras",
5959
Args: cobra.NoArgs,
60-
RunE: func(cmd *cobra.Command, args []string) error { return discover(ctx) },
60+
RunE: func(cmd *cobra.Command, args []string) error { return discover(ctx, false) },
61+
}
62+
63+
cmdStreams := &cobra.Command{
64+
Use: "streams",
65+
Aliases: []string{"streams", "stream"},
66+
Short: "Print the stream URL for the cameras locally discovered",
67+
Args: cobra.NoArgs,
68+
RunE: func(cmd *cobra.Command, args []string) error { return discover(ctx, true) },
6169
}
6270

6371
cmdDump := &cobra.Command{
@@ -139,7 +147,7 @@ func main() {
139147

140148
cmdDump.AddCommand(cmdDumpDescr, cmdDumpAll)
141149
cmdDump.AddCommand(cmdDumpMedia, cmdDumpPtz, cmdDumpEvents, cmdDumpProfiles, cmdDumpDevice)
142-
cmd.AddCommand(cmdDiscover, cmdDump)
150+
cmd.AddCommand(cmdDiscover, cmdStreams, cmdDump)
143151

144152
if err := cmd.Execute(); err != nil {
145153
Logger.Fatal().Err(err).Msg("Aborting")

0 commit comments

Comments
 (0)