Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/app/model/Formats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ object PressedContentFormat {
implicit val imageMediaFormat: OFormat[ImageMedia] = Json.format[ImageMedia]
implicit val videoMediaFormat: OFormat[VideoMedia] = Json.format[VideoMedia]
implicit val videoElementFormat: OFormat[VideoElement] = Json.format[VideoElement]
implicit val assetDimensionsFormat: OFormat[AssetDimensions] = Json.format[AssetDimensions]
implicit val mediaAssetFormat: OFormat[MediaAsset] = Json.format[MediaAsset]
implicit val mediaAtomFormat: OFormat[MediaAtom] = Json.format[MediaAtom]
implicit val mediaTypeFormat: MediaTypeFormat.type = MediaTypeFormat
Expand Down
50 changes: 48 additions & 2 deletions common/app/model/content/Atom.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package model.content

import com.gu.contentatom.thrift.atom.media.{Asset => AtomApiMediaAsset, MediaAtom => AtomApiMediaAtom}
import com.gu.contentatom.thrift.atom.media.{
Asset => AtomApiMediaAsset,
MediaAtom => AtomApiMediaAtom,
VideoPlayerFormat => AtomApiVideoPlayerFormat,
}
import com.gu.contentatom.thrift.AtomDataAliases.{MediaAlias => MediaAtomData}
import com.gu.contentatom.thrift.atom.timeline.{TimelineItem => TimelineApiItem}
import com.gu.contentatom.thrift.{
Expand All @@ -16,7 +20,7 @@ import model.{ImageAsset, ImageMedia, ShareLinkMeta}
import org.apache.commons.lang3.time.DurationFormatUtils
import org.joda.time.format.DateTimeFormat
import org.joda.time.{DateTime, DateTimeZone, Duration}
import play.api.libs.json.{JsError, JsSuccess, Json, OFormat}
import play.api.libs.json.{JsError, JsSuccess, Json, OFormat, Writes}
import quiz._
import views.support.GoogleStructuredData

Expand Down Expand Up @@ -168,6 +172,7 @@ final case class MediaAtom(
activeVersion: Option[Long],
channelId: Option[String],
trailImage: Option[ImageMedia],
videoPlayerFormat: Option[VideoPlayerFormat],
) extends Atom {

def activeAssets: Seq[MediaAsset] =
Expand All @@ -190,14 +195,35 @@ final case class MediaAtom(
}
}

object AssetDimensions {
implicit val assetDimensionsWrites: Writes[AssetDimensions] =
Json.writes[AssetDimensions]
}
final case class AssetDimensions(
width: Int,
height: Int,
)

final case class MediaAsset(
id: String,
version: Long,
platform: MediaAssetPlatform,
mimeType: Option[String],
assetType: MediaAssetType,
dimensions: Option[AssetDimensions],
aspectRatio: Option[String],
)

sealed trait VideoPlayerFormat extends EnumEntry

object VideoPlayerFormat extends Enum[VideoPlayerFormat] with PlayJsonEnum[VideoPlayerFormat] {
val values = findValues

case object Default extends VideoPlayerFormat
case object Loop extends VideoPlayerFormat
case object Cinemagraph extends VideoPlayerFormat
}

sealed trait MediaAssetType extends EnumEntry

object MediaAssetType extends Enum[MediaAssetType] with PlayJsonEnum[MediaAssetType] {
Expand Down Expand Up @@ -233,6 +259,15 @@ object MediaAtom extends common.GuLogging {
activeVersion = mediaAtom.activeVersion,
channelId = mediaAtom.metadata.flatMap(_.channelId),
trailImage = mediaAtom.trailImage.map(imageMediaMake(_, mediaAtom.title)),
videoPlayerFormat = VideoPlayerFormat.withNameOption(
mediaAtom.metadata
.flatMap(_.selfHost)
.flatMap(_.videoPlayerFormat)
.getOrElse(
AtomApiVideoPlayerFormat.Default,
)
.name,
),
)
}

Expand All @@ -254,6 +289,15 @@ object MediaAtom extends common.GuLogging {
activeVersion = mediaAtom.activeVersion,
channelId = mediaAtom.metadata.flatMap(_.channelId),
trailImage = mediaAtom.trailImage.map(imageMediaMake(_, mediaAtom.title)),
videoPlayerFormat = VideoPlayerFormat.withNameOption(
mediaAtom.metadata
.flatMap(_.selfHost)
.flatMap(_.videoPlayerFormat)
.getOrElse(
AtomApiVideoPlayerFormat.Default,
)
.name,
),
)
}

Expand All @@ -268,6 +312,8 @@ object MediaAtom extends common.GuLogging {
platform = MediaAssetPlatform.withName(mediaAsset.platform.name),
mimeType = mediaAsset.mimeType,
assetType = MediaAssetType.withName(mediaAsset.assetType.name),
dimensions = mediaAsset.dimensions.map(dim => AssetDimensions(dim.width, dim.height)),
aspectRatio = mediaAsset.aspectRatio,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,14 @@ object MapBlockElement {
case class MediaAtomBlockElementMediaAsset(
url: String,
mimeType: Option[String],
dimensions: Option[AssetDimensions],
aspectRatio: Option[String],
)
object MediaAtomBlockElementMediaAsset {
implicit val MediaAtomBlockElementMediaAssetWrites: Writes[MediaAtomBlockElementMediaAsset] =
Json.writes[MediaAtomBlockElementMediaAsset]
def fromMediaAsset(asset: MediaAsset): MediaAtomBlockElementMediaAsset = {
MediaAtomBlockElementMediaAsset(asset.id, asset.mimeType)
MediaAtomBlockElementMediaAsset(asset.id, asset.mimeType, asset.dimensions, asset.aspectRatio)
}
}
case class MediaAtomBlockElement(
Expand All @@ -452,6 +454,7 @@ case class MediaAtomBlockElement(
expired: Option[Boolean],
activeVersion: Option[Long],
channelId: Option[String],
videoPlayerFormat: Option[VideoPlayerFormat],
) extends PageElement
object MediaAtomBlockElement {
implicit val MediaAtomBlockElementWrites: Writes[MediaAtomBlockElement] = Json.writes[MediaAtomBlockElement]
Expand Down Expand Up @@ -1313,6 +1316,7 @@ object PageElement {
mediaAtom.expired,
mediaAtom.activeVersion,
mediaAtom.channelId,
mediaAtom.videoPlayerFormat,
),
)
}
Expand Down
7 changes: 4 additions & 3 deletions common/test/model/ContentTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,10 @@ class ContentTest
val contentNoByline = content("video", Nil).content
val contentWithByline = content("video", Nil, byline).content

val mediaAtomWithSource = Some(MediaAtom("", "", Nil, "", None, atomSource, None, None, None, None, None))
val mediaAtomWithNoSource = Some(MediaAtom("", "", Nil, "", None, None, None, None, None, None, None))
val mediaAtomWithEmptySource = Some(MediaAtom("", "", Nil, "", None, emptySource, None, None, None, None, None))
val mediaAtomWithSource = Some(MediaAtom("", "", Nil, "", None, atomSource, None, None, None, None, None, None))
val mediaAtomWithNoSource = Some(MediaAtom("", "", Nil, "", None, None, None, None, None, None, None, None))
val mediaAtomWithEmptySource =
Some(MediaAtom("", "", Nil, "", None, emptySource, None, None, None, None, None, None))

Video(contentNoByline, None, None).bylineWithSource should be(None)
Video(contentNoByline, videoSource, None).bylineWithSource should be(videoSource.map(s => s"Source: $s"))
Expand Down
3 changes: 3 additions & 0 deletions common/test/views/fragments/atoms/YoutubeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class YoutubeSpec extends MixedPlaySpec {
platform = Youtube,
mimeType = None,
assetType = Video,
dimensions = None,
aspectRatio = None,
),
),
title = "",
Expand All @@ -31,6 +33,7 @@ class YoutubeSpec extends MixedPlaySpec {
activeVersion = None,
channelId = None,
trailImage = None,
videoPlayerFormat = None,
)
val displayCaption = false
val view = views.html.fragments.atoms
Expand Down
3 changes: 3 additions & 0 deletions common/test/views/support/cleaner/AtomCleanerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class AtomCleanerTest extends AnyFlatSpec with Matchers with WithTestApplication
platform = MediaAssetPlatform.Youtube,
mimeType = None,
assetType = Video,
dimensions = None,
aspectRatio = None,
)

val youTubeAtom = Some(
Expand All @@ -53,6 +55,7 @@ class AtomCleanerTest extends AnyFlatSpec with Matchers with WithTestApplication
activeVersion = None,
channelId = None,
trailImage = Some(image),
videoPlayerFormat = None,
),
),
interactives = Nil,
Expand Down
Loading