Skip to content

Commit

Permalink
wip: refactor to unmarshal directly into slices, add VAST unmarshal test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunkers committed Feb 14, 2025
1 parent db5bc3f commit 173cd6c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 14 deletions.
59 changes: 59 additions & 0 deletions VMAP/sample-vmap/testVast.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<VAST version="4.0">
<Ad id="POD_AD-ID_001" sequence="1">
<InLine>
<Impression id="IMPRESSION-ID_001"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=alvedon-10s_1&progress=vast]]></Impression>
<AdSystem><![CDATA[Test Adserver]]></AdSystem>
<AdTitle><![CDATA[Ad That Test-Adserver Wants Player To See #1]]></AdTitle>
<Creatives>
<Creative id="CRETIVE-ID_001" adId="alvedon-10s" sequence="1">
<UniversalAdId idRegistry="test-ad-id.eyevinn" idValue="AAA%2FBBBB123%2F1"><![CDATA[AAA%2FBBBB123%2F1]]></UniversalAdId>
<Linear>
<TrackingEvents>
<Tracking event="start"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=alvedon-10s_1&progress=0]]></Tracking>
<Tracking event="firstQuartile"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=alvedon-10s_1&progress=25]]></Tracking>
<Tracking event="midpoint"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=alvedon-10s_1&progress=50]]></Tracking>
<Tracking event="thirdQuartile"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=alvedon-10s_1&progress=75]]></Tracking>
<Tracking event="complete"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=alvedon-10s_1&progress=100]]></Tracking>
</TrackingEvents>
<VideoClicks>
<ClickThrough id="Eyevinn Test AdServer"><![CDATA[https://github.com/Eyevinn/test-adserver]]></ClickThrough>
</VideoClicks>
<Duration><![CDATA[00:00:10]]></Duration>
<MediaFiles>
<MediaFile width="718" height="404" codec="H.264" delivery="progressive" type="video/mp4" bitrate="1300"><![CDATA[https://testcontent.eyevinn.technology/ads/alvedon-10s.mp4]]></MediaFile>
</MediaFiles>
</Linear>
</Creative>
</Creatives>
</InLine>
</Ad>
<Ad id="POD_AD-ID_002" sequence="2">
<InLine>
<Impression id="IMPRESSION-ID_002"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=bromwel-15s_2&progress=vast]]></Impression>
<AdSystem><![CDATA[Test Adserver]]></AdSystem>
<AdTitle><![CDATA[Ad That Test-Adserver Wants Player To See #2]]></AdTitle>
<Creatives>
<Creative id="CRETIVE-ID_002" adId="bromwel-15s" sequence="2">
<UniversalAdId idRegistry="test-ad-id.eyevinn" idValue="AAA%2FDDDD123%2F2"><![CDATA[AAA%2FDDDD123%2F2]]></UniversalAdId>
<Linear>
<TrackingEvents>
<Tracking event="start"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=bromwel-15s_2&progress=0]]></Tracking>
<Tracking event="firstQuartile"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=bromwel-15s_2&progress=25]]></Tracking>
<Tracking event="midpoint"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=bromwel-15s_2&progress=50]]></Tracking>
<Tracking event="thirdQuartile"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=bromwel-15s_2&progress=75]]></Tracking>
<Tracking event="complete"><![CDATA[http://eyevinnlab-adnormalizer.eyevinn-test-adserver.auto.prod.osaas.io/api/v1/sessions/07587bf5-1ab5-4f41-a398-25a5fbc3760d/tracking?adId=bromwel-15s_2&progress=100]]></Tracking>
</TrackingEvents>
<VideoClicks>
<ClickThrough id="Eyevinn Test AdServer"><![CDATA[https://github.com/Eyevinn/test-adserver]]></ClickThrough>
</VideoClicks>
<Duration><![CDATA[00:00:15]]></Duration>
<MediaFiles>
<MediaFile width="718" height="404" codec="H.264" delivery="progressive" type="video/mp4" bitrate="1000"><![CDATA[https://testcontent.eyevinn.technology/ads/bromwel-15s.mp4]]></MediaFile>
</MediaFiles>
</Linear>
</Creative>
</Creatives>
</InLine>
</Ad>
</VAST>
25 changes: 11 additions & 14 deletions VMAP/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ type VMAP struct {
}

type AdBreak struct {
AdSource *AdSource `xml:"AdSource"`
TrackingEvents *[]Tracking `xml:"TrackingEvents"`
Id string `xml:"breakId,attr"`
BreakType string `xml:"breakType,attr"`
TimeOffset string `xml:"timeOffset,attr"`
AdSource *AdSource `xml:"AdSource"`
TrackingEvents *[]TrackingEvent `xml:"TrackingEvents>Tracking"`
Id string `xml:"breakId,attr"`
BreakType string `xml:"breakType,attr"`
TimeOffset string `xml:"timeOffset,attr"`
}

type AdSource struct {
VASTData *VASTData `xml:"VASTAdData"`
}

type Tracking struct {
type TrackingEvent struct {
Event string `xml:"event,attr"`
Text string `xml:",chardata"`
}
Expand Down Expand Up @@ -51,7 +51,7 @@ type InLine struct {
AdSystem string `xml:"AdSystem"`
AdTitle string `xml:"AdTitle"`
Impression *Impression `xml:"Impression"`
Creatives []Creative `xml:"Creatives"`
Creatives []Creative `xml:"Creatives>Creative"`
}

type Impression struct {
Expand All @@ -61,15 +61,17 @@ type Impression struct {

type Creative struct {
Id string `xml:"id,attr"`
AdId string `xml:"adId,attr"`
UniversalAdId *UniversalAdId `xml:"UniversalAdId"`
Linear *Linear `xml:"Linear"`
}

type UniversalAdId struct{}

type Linear struct {
Duration string `xml:"Duration"` // TODO: Make into duration object
TrackingEvents []Tracking `xml:"TrackingEvents"`
Duration string `xml:"Duration"` // TODO: Make into duration object
TrackingEvents []TrackingEvent `xml:"TrackingEvents>Tracking"`
MediaFiles []MediaFile `xml:"MediaFiles>MediaFile"`
}

type VideoClicks struct {
Expand All @@ -81,11 +83,6 @@ type ClickThrough struct {
Text string `xml:",chardata"`
}

type MediaFiles struct {
Text string `xml:",chardata"`
MediaFile []MediaFile `xml:"MediaFile"`
}

type MediaFile struct {
Text string `xml:",chardata"`
Bitrate int `xml:"bitrate,attr"`
Expand Down
30 changes: 30 additions & 0 deletions VMAP/structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,33 @@ func TestUnmarshalVMAP(t *testing.T) {
is.True(thirdBreak.AdSource.VASTData.VAST != nil)
is.Equal(len(*thirdBreak.TrackingEvents), 1)
}

func TestUnmarshalVast(t *testing.T) {
is := is.New(t)
f, err := os.Open("sample-vmap/testVast.xml")
is.NoErr(err)
defer f.Close()

var vast VAST
xmlBytes, err := io.ReadAll(f)
is.NoErr(err)
err = xml.Unmarshal(xmlBytes, &vast)
is.NoErr(err)

is.Equal(len(vast.Ad), 2)
firstAd := vast.Ad[0]
is.Equal(firstAd.Id, "POD_AD-ID_001")
firstAdInLine := firstAd.InLine
is.Equal(firstAdInLine.AdSystem, "Test Adserver")
is.Equal(firstAdInLine.AdTitle, "Ad That Test-Adserver Wants Player To See #1")
firstAdImpression := firstAdInLine.Impression
is.Equal(firstAdImpression.Id, "IMPRESSION-ID_001")
firstAdCreatives := firstAdInLine.Creatives
is.Equal(len(firstAdCreatives), 1)
firstCreative := firstAdCreatives[0]
is.Equal(firstCreative.Id, "CRETIVE-ID_001")
is.Equal(firstCreative.AdId, "alvedon-10s")
is.Equal(len(firstCreative.Linear.TrackingEvents), 5)
is.Equal(firstCreative.Linear.Duration, "00:00:10")
is.Equal(len(firstCreative.Linear.MediaFiles), 1)
}

0 comments on commit 173cd6c

Please sign in to comment.