Skip to content

Commit

Permalink
Add the streams subcomand to onvif-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jfsmig committed Feb 18, 2023
1 parent 21604e7 commit 6796b24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 13 additions & 2 deletions bin/onvif-cli/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ package main
import (
"context"
"fmt"
"github.com/jfsmig/onvif/sdk"
"net"

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

func discover(ctx context.Context) error {
func discover(ctx context.Context, flagStreams bool) error {
interfaces, err := net.Interfaces()
if err != nil {
return err
Expand All @@ -25,7 +26,17 @@ func discover(ctx context.Context) error {
if dev.Uuid == "" {
dev.Uuid = "-"
}
fmt.Println(dev.Xaddr, dev.Uuid)
if !flagStreams {
fmt.Println(dev.Xaddr, dev.Uuid)
} else {
if cam, err := sdk.NewDevice(ctx, dev, auth, &httpClient); err != nil {
Logger.Error().Err(err).Msg("Camera instanciation failure")
} else {
for id, profile := range cam.FetchProfiles(ctx).Profiles {
fmt.Println(dev.Xaddr, dev.Uuid, id, profile.Uris.Stream.Uri, profile.Uris.Snapshot.Uri)
}
}
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions bin/onvif-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ func main() {
Aliases: []string{"find", "crawl", "probe"},
Short: "Discover the local cameras",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { return discover(ctx) },
RunE: func(cmd *cobra.Command, args []string) error { return discover(ctx, false) },
}

cmdStreams := &cobra.Command{
Use: "streams",
Aliases: []string{"streams", "stream"},
Short: "Print the stream URL for the cameras locally discovered",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { return discover(ctx, true) },
}

cmdDump := &cobra.Command{
Expand Down Expand Up @@ -139,7 +147,7 @@ func main() {

cmdDump.AddCommand(cmdDumpDescr, cmdDumpAll)
cmdDump.AddCommand(cmdDumpMedia, cmdDumpPtz, cmdDumpEvents, cmdDumpProfiles, cmdDumpDevice)
cmd.AddCommand(cmdDiscover, cmdDump)
cmd.AddCommand(cmdDiscover, cmdStreams, cmdDump)

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

0 comments on commit 6796b24

Please sign in to comment.