in common/src/main/scala/com/gu/media/youtube/YouTubePartnerApi.scala [181:206]
private def updateTheVideoAdvertisingOptions(videoId: String, atomId: String, enableMidroll: Boolean): Either[VideoUpdateError, String] = {
// All possible formats can be found on YouTube developer docs: https://developers.google.com/youtube/partner/docs/v1/videoAdvertisingOptions#properties
val formats = Seq("standard_instream","trueview_instream","display")
// see https://developers.google.com/youtube/partner/docs/v1/videoAdvertisingOptions#breakPosition[]
val breakPositions = Seq("preroll") ++ Option.when(enableMidroll)("midroll")
val advertisingOption: VideoAdvertisingOption =
new VideoAdvertisingOption()
.setAdFormats(formats.asJava)
.setAutoGeneratedBreaks(true)
.setBreakPosition(breakPositions.asJava)
try {
MAMLogger.info(s"About to update video advertising options for ${videoId}",atomId,videoId)
val request = partnerClient.videoAdvertisingOptions().update(videoId, advertisingOption).setOnBehalfOfContentOwner(contentOwner)
YoutubeRequestLogger.logRequest(YoutubeApiType.PartnerApi, YoutubeRequestType.UpdateVideoAdvertisingOptions)
request.execute()
MAMLogger.info(s"Updated video advertising options for ${videoId}",atomId, videoId)
Right(s"Updated advertising options on video $videoId")
} catch {
case e: GoogleJsonResponseException =>
val error: GoogleJsonError = e.getDetails
Left(VideoUpdateError(s"Error in updating the advertising options on video $videoId, ${error.toString}", Some(error.getMessage)))
}
}