Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ads()
- G = conf()
- this = {}
- this.G = G
- this.adIface = Roku_Ads()
- if G.ENV = "development"
- this.adIface.setDebugOutput(true)
- end if
- if G.NIELSEN_APP_ID <> invalid
- this.adIface.enableNielsenDAR(true)
- this.adIface.setNielsenAppId(G.NIELSEN_APP_ID)
- end if
- this.adIface.setAdPrefs(false)
- this.set_video_content = set_video_content
- this.ads_to_play = ads_to_play
- this.play_ads = play_ads
- this.site_uuid = "INVALID"
- return this
- end function
- function set_video_content(video_content)
- this = m
- this.video_content = video_content
- if this.video_content.site_uuid <> invalid
- this.site_uuid = this.video_content.site_uuid
- end if
- if this.video_content.cuepoints <> invalid and this.video_content.cuepoints.count() > 0
- this.cuepoints = this.video_content.cuepoints
- else
- ?"There are no cuepoints!"
- backtraces = []
- backtraces.Push("video_content.cuepoints: " + any_to_string(video_content.cuepoints))
- backtraces.Push("video_content.video_uuid: " + any_to_string(video_content.video_uuid))
- backtraces.Push("video_content: " + any_to_string(video_content))
- airbrake().add_error("no_cuepoints", "no cuepoints when trying to play ads", "/source/ads.brs", "set_video_content()", backtraces).send()
- end if
- this.consume_cuepoints = []
- for each cp in this.cuepoints
- this.consume_cuepoints.push(cp)
- end for
- if this.video_content.ovg_ads <> invalid and this.video_content.ovg_ads.vast_tag <> invalid
- this.vast_tag = this.video_content.ovg_ads.vast_tag
- else if this.video_content.ovg_ads <> invalid and this.video_content.ovg_ads.provider <> invalid
- this.vast_tag = this.video_content.ovg_ads.provider.vast_tag
- else
- ?"There was no vast tag!"
- backtraces = []
- if this.video_content.ovg_ads <> invalid
- backtraces.Push("this.video_content.ovg_ads.provider: " + any_to_string(this.video_content.ovg_ads.provider))
- backtraces.Push("video_content.ovg_ads.vast_tag: " + any_to_string(video_content.ovg_ads.vast_tag))
- end if
- backtraces.Push("video_content.video_uuid: " + any_to_string(video_content.video_uuid))
- backtraces.Push("video_content: " + any_to_string(video_content))
- airbrake().add_error("no_vast_tag", "no vast tag when trying to play ads", "/source/ads.brs", "set_video_content()", backtraces).send()
- end if
- if this.video_content.nielsen_genre <> invalid and len(this.video_content.nielsen_genre) > 0
- this.adIface.setNielsenGenre(this.video_content.nielsen_genre)
- end if
- if this.video_content.Categories <> invalid and this.video_content.Categories.count() > 0
- genres = this.video_content.Categories
- g_string = ""
- total_genres = genres.count()
- loop_i = 0
- for each genre in genres
- loop_i = loop_i + 1
- if g_string.instr(genre) = -1
- g_string = g_string + genre
- if loop_i <> total_genres
- g_string = g_string + ","
- end if
- end if
- end for
- this.adIface.setContentGenre(g_string)
- end if
- this.adIface.setNielsenProgramId(this.video_content.title)
- this.adIface.setContentLength(any_to_int(this.video_content.duration))
- if this.video_content.ovg_ads <> invalid
- if this.video_content.ovg_ads.n_midroll_ads <> invalid
- this.n_midroll_ads = this.video_content.ovg_ads.n_midroll_ads
- else if this.video_content.ovg_ads.n_ads <> invalid
- this.n_midroll_ads = this.video_content.ovg_ads.n_ads
- else
- ?"There was no n_midroll_ads!"
- backtraces = []
- backtraces.Push("this.video_content.ovg_ads.n_midroll_ads: " + any_to_string(this.video_content.ovg_ads.n_midroll_ads))
- backtraces.Push("this.video_content.ovg_ads.n_ads: " + any_to_string(this.video_content.ovg_ads.n_ads))
- backtraces.Push("video_content.video_uuid: " + any_to_string(video_content.video_uuid))
- backtraces.Push("video_content: " + any_to_string(video_content))
- airbrake().add_error("no_midroll_ads", "no n_midroll_ads when trying to play ads", "/source/ads.brs", "set_video_content()", backtraces).send()
- end if
- else
- ?"There was no n_midroll_ads!"
- backtraces = []
- backtraces.Push("this.video_content.ovg_ads: " + any_to_string(this.video_content.ovg_ads))
- backtraces.Push("video_content.video_uuid: " + any_to_string(video_content.video_uuid))
- backtraces.Push("video_content: " + any_to_string(video_content))
- airbrake().add_error("no_ovg_ads", "no ovg_ads when trying to play ads", "/source/ads.brs", "set_video_content()", backtraces).send()
- end if
- if this.video_content.ovg_ads <> invalid and this.video_content.ovg_ads.n_preroll_ads <> invalid
- this.n_preroll_ads = this.video_content.ovg_ads.n_preroll_ads
- else if this.video_content.ovg_ads <> invalid and this.video_content.ovg_ads.n_ads <> invalid
- this.n_preroll_ads = this.video_content.ovg_ads.n_ads
- else
- ?"There was no n_preroll_ads!"
- backtraces = []
- if this.video_content.ovg_ads <> invalid
- backtraces.Push("this.video_content.ovg_ads.n_preroll_ads: " + any_to_string(this.video_content.ovg_ads.n_preroll_ads))
- backtraces.Push("this.video_content.ovg_ads.n_ads: " + any_to_string(this.video_content.ovg_ads.n_ads))
- end if
- backtraces.Push("video_content.video_uuid: " + any_to_string(video_content.video_uuid))
- backtraces.Push("video_content: " + any_to_string(video_content))
- airbrake().add_error("no_preroll_ads", "no n_preroll_ads when trying to play ads", "/source/ads.brs", "set_video_content()", backtraces).send()
- end if
- this.ad_received = false
- if this.video_content.ContentType = 4
- this.ga_label = this.video_content.TitleSeason + " | " + this.video_content.Title + " | " + this.video_content.ShortDescriptionLine2
- else
- this.ga_label = this.video_content.Title
- end if
- return this
- end function
- function ads_to_play(position)
- this = m
- if this.video_content <> invalid
- i = 0
- play_ad = false
- for each cuepoint in this.consume_cuepoints
- if position = cuepoint
- play_ad = true
- ' detete this to prevent users from seeing the same ad break if they rewind
- ' the Roku will only resume at a segment boundary, so you can't seek into a segment.
- ' if the segment starts at 19 seconds and is 10 seconds long, if you seek to anything between 19 and 29 seconds, it will resume at 19.
- ' to fix this we need to delete the cue point that we are about to play so it doesn't play again
- ' http://forums.roku.com/viewtopic.php?f=34&t=93694&p=525516&hilit=seek#p525516
- this.consume_cuepoints.delete(i)
- exit for
- end if
- i = i + 1
- end for
- if play_ad
- 'check the queue points
- if position = 0
- 'pre roll
- 'if we have preroll ads
- if this.n_preroll_ads <> invalid and this.n_preroll_ads > 0
- return this.n_preroll_ads
- end if
- else
- 'mid/post roll
- 'if we have midroll ads
- if this.n_midroll_ads <> invalid and this.n_midroll_ads > 0
- return this.n_midroll_ads
- end if
- end if
- end if
- end if
- return invalid
- end function
- function play_ads(total_ads_in_pod)
- 'Request the ad
- this = m
- facade = CreateObject("roScreen")
- for ad_number = 0 to total_ads_in_pod-1
- updated_vast = vast_updateParams(this.vast_tag)
- this.adIface.setAdUrl(updated_vast)
- ' Analytics = Ad Requested
- ga_track_event("Ads", "Ad Requested", this.ga_label)
- adPods = this.adIface.getAds()
- if adPods <> invalid and adPods.count() > 0
- ' Analytics = Ad Recieved
- ga_track_event("Ads", "Ad Received - All Providers", this.ga_label)
- ad = adPods[0].ads[0]
- 'Fix the ad count overlay just add invalid ads to the beginning of the pod
- for i=0 to total_ads_in_pod-1
- if i = ad_number
- adPods[0].ads[i] = ad
- else
- adPods[0].ads[i] = invalid
- end if
- end for
- ad_completed = this.adIface.showAds(adPods)
- if ad_completed
- ' Analytics = Ad Played To Completion
- ga_track_event("Ads", "Ad Played to Completion - All Providers", this.ga_label)
- 'track ad plays by site
- ga_track_event("Ads by Site", this.site_uuid, this.ga_label)
- else
- ' the user backed out of the ad so hide the player and return false
- ' Analytics = User Exited Ad
- ga_track_event("Ads", "Ad Exited by User", this.ga_label)
- 'We want to be able to skip ads in dev env
- facade = invalid
- if this.G.ENV = "development"
- return true
- else
- return false
- end if
- end if
- else
- 'We didn't get any ads so just continue
- ' Analytics = Didn't get any Ads
- ga_track_event("Ads", "Ad NOT Received - All Providers", this.ga_label)
- end if
- end for
- 'if we made it here, the user didn't back out of the ads so lets play the video
- facade = invalid
- return true
- end function
- function vast_updateParams(url as string) as string
- print "=== Updating VAST Parameters..." url
- 'Update VAST Parameters
- vast_parameters = url.Tokenize("&")
- updated_vast = ""
- roUrlTransfer_http = createobject("roUrlTransfer")
- for each param in vast_parameters
- print "param: "param
- if instr(1, param, "description_url=[description_url]")
- param = "description_url=" + roUrlTransfer_http.escape("http://www.ovguide.com")
- else if instr(1, param, "refUrl=[Ref_Url]")
- param = "refUrl=" + roUrlTransfer_http.escape("http://www.ovguide.com")
- else if 0 < instr(1, param, "url=[referrer_url]")
- param = "url=" + roUrlTransfer_http.escape("http://www.ovguide.com")
- else if 0 < instr(1, param, "correlator=")
- now = createobject("rodatetime")
- param = "correlator=" + any_to_string(now.asseconds() + rnd(1000))
- print "*** CORRELATOR: " + param
- end if
- if 0 < instr(1, param, "[")
- param = strReplace(param, "[", "%5b")
- else if 0 < instr(1, param, "]")
- param = strReplace(param, "]", "%5d")
- end if
- if 1 = instr(1, left(param, 7), "http://")
- updated_vast = param
- else if 1 = instr(1, left(param, 8), "https://")
- updated_vast = param
- else
- updated_vast = updated_vast + "&" + param
- end if
- next
- if 0 < instr(1, updated_vast, ";cb=[timestamp]")
- now = createobject("rodatetime")
- updatedParam = ";cb=" + any_to_string(now.asseconds())
- updated_vast = strreplace(updated_vast, ";cb=[timestamp]", updatedParam)
- end if
- sambaPlatFormIdRegEx = CreateObject("roRegex", "SAMBA_PLATFORM_ID", "")
- updated_vast = sambaPlatFormIdRegEx.ReplaceAll(updated_vast, "roku")
- print "=== UPDATED VAST "updated_vast
- return updated_vast
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement