Skip to content

Commit

Permalink
GetRecordings (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloo authored Dec 5, 2024
1 parent c31567d commit 7df51be
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/recording/get_recordings.ex
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.Recording

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(&Recording.parse/1)
|> Enum.reduce([], fn raw_recording, acc ->
case Recording.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
169 changes: 169 additions & 0 deletions test/recording/fixture/get_recordings_success.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsa5="http://www.w3.org/2005/08/addressing"
xmlns:xmime="http://tempuri.org/xmime.xsd"
xmlns:xop="http://www.w3.org/2004/08/xop/include"
xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2"
xmlns:wstop="http://docs.oasis-open.org/wsn/t-1"
xmlns:tt="http://www.onvif.org/ver10/schema"
xmlns:acert="http://www.axis.com/vapix/ws/cert"
xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2"
xmlns:aa="http://www.axis.com/vapix/ws/action1"
xmlns:acertificates="http://www.axis.com/vapix/ws/certificates"
xmlns:aentry="http://www.axis.com/vapix/ws/entry"
xmlns:aev="http://www.axis.com/vapix/ws/event1"
xmlns:aeva="http://www.axis.com/vapix/ws/embeddedvideoanalytics1"
xmlns:ali1="http://www.axis.com/vapix/ws/light/CommonBinding"
xmlns:ali2="http://www.axis.com/vapix/ws/light/IntensityBinding"
xmlns:ali3="http://www.axis.com/vapix/ws/light/AngleOfIlluminationBinding"
xmlns:ali4="http://www.axis.com/vapix/ws/light/DayNightSynchronizeBinding"
xmlns:ali="http://www.axis.com/vapix/ws/light"
xmlns:apc="http://www.axis.com/vapix/ws/panopsiscalibration1"
xmlns:arth="http://www.axis.com/vapix/ws/recordedtour1"
xmlns:asd="http://www.axis.com/vapix/ws/shockdetection"
xmlns:aweb="http://www.axis.com/vapix/ws/webserver"
xmlns:tan1="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding"
xmlns:tan2="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding"
xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl"
xmlns:tds="http://www.onvif.org/ver10/device/wsdl"
xmlns:tev1="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding"
xmlns:tev2="http://www.onvif.org/ver10/events/wsdl/EventBinding"
xmlns:tev3="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding"
xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
xmlns:tev4="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding"
xmlns:tev="http://www.onvif.org/ver10/events/wsdl"
xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"
xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl"
xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl"
xmlns:tr2="http://www.onvif.org/ver20/media/wsdl"
xmlns:trc="http://www.onvif.org/ver10/recording/wsdl"
xmlns:trp="http://www.onvif.org/ver10/replay/wsdl"
xmlns:trt="http://www.onvif.org/ver10/media/wsdl"
xmlns:tse="http://www.onvif.org/ver10/search/wsdl"
xmlns:ter="http://www.onvif.org/ver10/error"
xmlns:tns1="http://www.onvif.org/ver10/topics"
xmlns:tnsaxis="http://www.axis.com/2009/event/topics">
<SOAP-ENV:Body>
<trc:GetRecordingsResponse>
<trc:RecordingItem>
<tt:RecordingToken>SD_DISK_20200422_123501_A2388AB3</tt:RecordingToken>
<tt:Configuration>
<tt:Source>
<tt:SourceId></tt:SourceId>
<tt:Name>paolo</tt:Name>
<tt:Location></tt:Location>
<tt:Description></tt:Description>
<tt:Address></tt:Address>
</tt:Source>
<tt:Content>beta cam 1</tt:Content>
<tt:MaximumRetentionTime>PT1H</tt:MaximumRetentionTime>
</tt:Configuration>
<tt:Tracks>
<tt:Track>
<tt:TrackToken>VIDEO001</tt:TrackToken>
<tt:Configuration>
<tt:TrackType>Video</tt:TrackType>
<tt:Description></tt:Description>
</tt:Configuration>
</tt:Track>
<tt:Track>
<tt:TrackToken>AUDIO001</tt:TrackToken>
<tt:Configuration>
<tt:TrackType>Audio</tt:TrackType>
<tt:Description></tt:Description>
</tt:Configuration>
</tt:Track>
<tt:Track>
<tt:TrackToken>META001</tt:TrackToken>
<tt:Configuration>
<tt:TrackType>Metadata</tt:TrackType>
<tt:Description></tt:Description>
</tt:Configuration>
</tt:Track>
</tt:Tracks>
</trc:RecordingItem>
<trc:RecordingItem>
<tt:RecordingToken>SD_DISK_20200422_132613_45A883F5</tt:RecordingToken>
<tt:Configuration>
<tt:Source>
<tt:SourceId></tt:SourceId>
<tt:Name>paolo2</tt:Name>
<tt:Location></tt:Location>
<tt:Description></tt:Description>
<tt:Address></tt:Address>
</tt:Source>
<tt:Content>beta cam 2</tt:Content>
<tt:MaximumRetentionTime>PT1H</tt:MaximumRetentionTime>
</tt:Configuration>
<tt:Tracks>
<tt:Track>
<tt:TrackToken>VIDEO001</tt:TrackToken>
<tt:Configuration>
<tt:TrackType>Video</tt:TrackType>
<tt:Description></tt:Description>
</tt:Configuration>
</tt:Track>
<tt:Track>
<tt:TrackToken>AUDIO001</tt:TrackToken>
<tt:Configuration>
<tt:TrackType>Audio</tt:TrackType>
<tt:Description></tt:Description>
</tt:Configuration>
</tt:Track>
<tt:Track>
<tt:TrackToken>META001</tt:TrackToken>
<tt:Configuration>
<tt:TrackType>Metadata</tt:TrackType>
<tt:Description></tt:Description>
</tt:Configuration>
</tt:Track>
</tt:Tracks>
</trc:RecordingItem>
<trc:RecordingItem>
<tt:RecordingToken>SD_DISK_20200422_132655_67086B52</tt:RecordingToken>
<tt:Configuration>
<tt:Source>
<tt:SourceId></tt:SourceId>
<tt:Name>paolo3</tt:Name>
<tt:Location></tt:Location>
<tt:Description></tt:Description>
<tt:Address></tt:Address>
</tt:Source>
<tt:Content>beta cam 3</tt:Content>
<tt:MaximumRetentionTime>PT1H</tt:MaximumRetentionTime>
</tt:Configuration>
<tt:Tracks>
<tt:Track>
<tt:TrackToken>VIDEO001</tt:TrackToken>
<tt:Configuration>
<tt:TrackType>Video</tt:TrackType>
<tt:Description></tt:Description>
</tt:Configuration>
</tt:Track>
<tt:Track>
<tt:TrackToken>AUDIO001</tt:TrackToken>
<tt:Configuration>
<tt:TrackType>Audio</tt:TrackType>
<tt:Description></tt:Description>
</tt:Configuration>
</tt:Track>
<tt:Track>
<tt:TrackToken>META001</tt:TrackToken>
<tt:Configuration>
<tt:TrackType>Metadata</tt:TrackType>
<tt:Description></tt:Description>
</tt:Configuration>
</tt:Track>
</tt:Tracks>
</trc:RecordingItem>
</trc:GetRecordingsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
27 changes: 27 additions & 0 deletions test/recording/get_recordings_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule Onvif.Recording.GetRecordingsTest do
use ExUnit.Case, async: true

@moduletag capture_log: true

describe "GetRecordings/1" do
test "successfully get a list of recordings" do
xml_response = File.read!("test/recording/fixture/get_recordings_success.xml")

device = Onvif.Factory.device()

Mimic.expect(Tesla, :request, fn _client, _opts ->
{:ok, %{status: 200, body: xml_response}}
end)

{:ok, response} = Onvif.Recording.GetRecordings.request(device)

assert Enum.map(response, fn r ->
r.recording_token
end) == [
"SD_DISK_20200422_132655_67086B52",
"SD_DISK_20200422_132613_45A883F5",
"SD_DISK_20200422_123501_A2388AB3"
]
end
end
end

0 comments on commit 7df51be

Please sign in to comment.