-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ExportRecordedData #86
Closed
Closed
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d824376
friday experiments
paoloo 26d8f95
fix typo
paoloo 79926aa
create works
paoloo f94a672
add more parsing
paoloo 0d5f48f
fix GetRecordings
paoloo 7488bf9
update uri
paoloo 5a195e2
add success uri fixture
paoloo 7146e06
updated code
paoloo c91e54e
add more fixtures
paoloo bd3399a
fix functions
paoloo 49ed167
add more tests
paoloo 21e9c8b
mix format
paoloo b58a256
test for get_replay_uri
paoloo 3ea14e1
GetRecordingJobs
paoloo 4d67a05
GetRecordingJobs part 2
paoloo d00ba5c
GetRecordingsTest
paoloo 5f3ce50
Replay.GetServiceCapabilities
paoloo 4cbf64b
fix typo
paoloo a4bd3b3
Update lib/replay.ex
paoloo ec50826
fix typo in filename
paoloo b04ef6b
Update lib/recording/recording_jobs.ex
paoloo 21b9d7a
address review
paoloo 5d375ee
typo lib/recording/create_recording.ex
paoloo 54fdea6
fixes from thanksgiving
paoloo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
defmodule Onvif.Recording do | ||
@moduledoc """ | ||
Interface for making requests to the Onvif recording service | ||
http://www.onvif.org/onvif/ver10/recording.wsdl | ||
""" | ||
require Logger | ||
alias Onvif.Device | ||
|
||
@namespaces [ | ||
"xmlns:trc": "http://www.onvif.org/ver10/recording/wsdl", | ||
"xmlns:tt": "http://www.onvif.org/ver10/schema" | ||
] | ||
|
||
@spec request(Device.t(), module()) :: {:ok, any} | {:error, map()} | ||
def request(%Device{} = device, operation) do | ||
content = generate_content(operation) | ||
do_request(device, operation, content) | ||
end | ||
|
||
def request(%Device{} = device, args, operation) do | ||
content = generate_content(operation, args) | ||
do_request(device, operation, content) | ||
end | ||
|
||
defp do_request(device, operation, content) do | ||
device | ||
|> Onvif.API.client(service_path: :recording_service_path) | ||
|> Tesla.request( | ||
method: :post, | ||
headers: [{"Content-Type", "application/soap+xml"}, {"SOAPAction", operation.soap_action()}], | ||
body: %Onvif.Request{content: content, namespaces: @namespaces} | ||
) | ||
|> parse_response(operation) | ||
end | ||
|
||
defp generate_content(operation), do: operation.request_body() | ||
defp generate_content(operation, args), do: operation.request_body(args) | ||
|
||
defp parse_response({:ok, %{status: 200, body: body}}, operation) do | ||
operation.response(body) | ||
end | ||
|
||
defp parse_response({:ok, %{status: status_code, body: body}}, operation) | ||
when status_code >= 400, | ||
do: | ||
{:error, | ||
%{ | ||
status: status_code, | ||
reason: "Received #{status_code} from #{operation}", | ||
response: body | ||
}} | ||
|
||
defp parse_response({:error, response}, operation) do | ||
{:error, %{status: nil, reason: "Error performing #{operation}", response: response}} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule Onvif.Recording.CreateRecording do | ||
import SweetXml | ||
import XmlBuilder | ||
require Logger | ||
|
||
def soap_action, do: "http://www.onvif.org/ver10/recording/wsdl/CreateRecording" | ||
|
||
def request(device, args) do | ||
Onvif.Recording.request(device, args, __MODULE__) | ||
end | ||
|
||
def request_body(%{name: name, content: content, max_retention: max_retention}) do | ||
element(:"s:Body", [ | ||
element(:"trc:CreateRecording", [ | ||
element(:"trc:RecordingConfiguration", [ | ||
element(:"tt:Source", [ | ||
element(:"tt:SourceId", ""), | ||
element(:"tt:Name", name), | ||
element(:"tt:Location", ""), | ||
element(:"tt:Description", ""), | ||
element(:"tt:Address", "") | ||
]), | ||
element(:"tt:Content", content), | ||
element(:"tt:MaximumRetentionTime", max_retention) | ||
]) | ||
]) | ||
]) | ||
end | ||
|
||
def response(xml_response_body) do | ||
response_uri = | ||
xml_response_body | ||
|> parse(namespace_conformant: true, quiet: true) | ||
|> xpath( | ||
~x"//s:Envelope/s:Body/trc:CreateRecordingResponse/trc:RecordingToken/text()"s | ||
|> add_namespace("s", "http://www.w3.org/2003/05/soap-envelope") | ||
|> add_namespace("trc", "http://www.onvif.org/ver10/recording/wsdl") | ||
) | ||
|
||
{:ok, response_uri} | ||
paoloo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Onvif.Recording.CreateRecordingJob do | ||
import SweetXml | ||
import XmlBuilder | ||
require Logger | ||
|
||
def soap_action, do: "http://www.onvif.org/ver10/recording/wsdl/CreateRecordingJob" | ||
|
||
def request(device, args) do | ||
Onvif.Recording.request(device, args, __MODULE__) | ||
end | ||
|
||
def request_body(recording_token, priority \\ "0", mode \\ "Active") do | ||
element(:"s:Body", [ | ||
element(:"trc:CreateRecordingJob", [ | ||
element(:"trc:JobConfiguration", [ | ||
element(:"tt:RecordingToken", recording_token), | ||
element(:"tt:Mode", mode), | ||
element(:"tt:Priority", priority) | ||
]) | ||
]) | ||
]) | ||
end | ||
|
||
def response(xml_response_body) do | ||
parsed_result = | ||
xml_response_body | ||
|> parse(namespace_conformant: true, quiet: true) | ||
|> xpath( | ||
~x"//s:Envelope/s:Body/trc:CreateRecordingJobResponse" | ||
|> add_namespace("s", "http://www.w3.org/2003/05/soap-envelope") | ||
|> add_namespace("trc", "http://www.onvif.org/ver10/recording/wsdl"), | ||
job_token: ~x"//trc:JobToken/text()"so, | ||
recording_token: ~x"//trc:JobConfiguration/tt:RecordingToken/text()"so, | ||
mode: ~x"//trc:JobConfiguration/tt:Mode/text()"so, | ||
priority: ~x"//trc:JobConfiguration/tt:Priority/text()"so | ||
) | ||
|
||
{:ok, parsed_result} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
defmodule Onvif.Recording.GetRecordingJobs do | ||
import SweetXml | ||
import XmlBuilder | ||
require Logger | ||
|
||
alias Onvif.Recording.RecordingJobs | ||
|
||
def soap_action, do: "http://www.onvif.org/ver10/recording/wsdl/GetRecordingJobs" | ||
|
||
def request(device) do | ||
Onvif.Recording.request(device, __MODULE__) | ||
end | ||
|
||
def request_body() do | ||
element(:"s:Body", [ | ||
element(:"trc:GetRecordingJobs") | ||
]) | ||
end | ||
|
||
def response(xml_response_body) do | ||
response = | ||
xml_response_body | ||
|> parse(namespace_conformant: true, quiet: true) | ||
|> xpath( | ||
~x"//s:Envelope/s:Body/trc:GetRecordingJobsResponse/trc:JobItem"el | ||
|> add_namespace("s", "http://www.w3.org/2003/05/soap-envelope") | ||
|> add_namespace("trc", "http://www.onvif.org/ver10/recording/wsdl") | ||
|> add_namespace("tt", "http://www.onvif.org/ver10/schema") | ||
) | ||
|> Enum.map(&RecordingJobs.parse/1) | ||
|> Enum.reduce([], fn raw_job, acc -> | ||
case RecordingJobs.to_struct(raw_job) do | ||
{:ok, job} -> | ||
[job | acc] | ||
|
||
{:error, changeset} -> | ||
Logger.error("Discarding invalid recording: #{inspect(changeset)}") | ||
acc | ||
end | ||
end) | ||
|
||
{:ok, response} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
defmodule Onvif.Recording.GetRecordings do | ||
import SweetXml | ||
import XmlBuilder | ||
require Logger | ||
|
||
alias Onvif.Recording.Recordings | ||
|
||
def soap_action, do: "http://www.onvif.org/ver10/recording/wsdl/GetRecordings" | ||
|
||
def request(device) do | ||
Onvif.Recording.request(device, __MODULE__) | ||
end | ||
|
||
def request_body() do | ||
element(:"s:Body", [ | ||
element(:"trc:GetRecordings") | ||
]) | ||
end | ||
|
||
def response(xml_response_body) do | ||
response = | ||
xml_response_body | ||
|> parse(namespace_conformant: true, quiet: true) | ||
|> xpath( | ||
~x"//s:Envelope/s:Body/trc:GetRecordingsResponse/trc:RecordingItem"el | ||
|> add_namespace("s", "http://www.w3.org/2003/05/soap-envelope") | ||
|> add_namespace("trc", "http://www.onvif.org/ver10/recording/wsdl") | ||
|> add_namespace("tt", "http://www.onvif.org/ver10/schema") | ||
) | ||
|> Enum.map(&Recordings.parse/1) | ||
|> Enum.reduce([], fn raw_recording, acc -> | ||
case Recordings.to_struct(raw_recording) do | ||
{:ok, recording} -> | ||
[recording | acc] | ||
|
||
{:error, changeset} -> | ||
Logger.error("Discarding invalid recording: #{inspect(changeset)}") | ||
acc | ||
end | ||
end) | ||
|
||
{:ok, response} | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should accept recording configuration as input like we do here. So that we can set all the input attrs. Right now I see we are defaulting to "" for some attrs. With the current approach of map as input we need to start adding new keys if we want to support setting all the attrs from the spec.