From 70f9a2a06849a72613d7b39a16583b7a86b0ae53 Mon Sep 17 00:00:00 2001 From: Ondrej Sery Date: Thu, 29 Sep 2022 10:56:13 +0200 Subject: [PATCH] Add media get-snapshot-uri command. --- cmd/gonvif/media/cmd.go | 1 + cmd/gonvif/media/get-snapshot-uri.go | 37 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 cmd/gonvif/media/get-snapshot-uri.go diff --git a/cmd/gonvif/media/cmd.go b/cmd/gonvif/media/cmd.go index 4cd47f1..26e66b6 100644 --- a/cmd/gonvif/media/cmd.go +++ b/cmd/gonvif/media/cmd.go @@ -19,6 +19,7 @@ func init() { cmd.AddCommand( getAnalyticsConfigurations, getProfiles, + getSnapshotURI, getVideoSourceConfigurations, ) } diff --git a/cmd/gonvif/media/get-snapshot-uri.go b/cmd/gonvif/media/get-snapshot-uri.go new file mode 100644 index 0000000..6dd3de3 --- /dev/null +++ b/cmd/gonvif/media/get-snapshot-uri.go @@ -0,0 +1,37 @@ +package media + +import ( + "github.com/spf13/cobra" + + "github.com/eyetowers/gonvif/cmd/gonvif/root" + "github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl" + "github.com/eyetowers/gonvif/pkg/util" +) + +var getSnapshotURI = &cobra.Command{ + Use: "get-snapshot-uri", + Short: "Get Onvif device media snapshot URI", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + client, err := ServiceClient(root.URL, root.Username, root.Password, root.Verbose) + if err != nil { + return nil + } + return runGetSnapshotURI(client, profileToken) + }, +} + +func init() { + getSnapshotURI.Flags().StringVarP(&profileToken, "profile_token", "t", "", "The ProfileToken element indicates the media profile to use and will define the source and dimensions of the snapshot.") + root.MustMarkFlagRequired(getSnapshotURI, "profile_token") +} + +func runGetSnapshotURI(client wsdl.Media2, profileToken string) error { + resp, err := client.GetSnapshotUri(&wsdl.GetSnapshotUri{ + ProfileToken: util.NewReferenceTokenPtr(profileToken), + }) + if err != nil { + return err + } + return root.OutputJSON(resp) +}