in app/model/commands/AddAssetCommand.scala [66:115]
private def getYouTubeChannel(asset: Asset, atom: ThriftMediaAtom, atomId: String): Option[String] = {
val existingChannel = atom.metadata.flatMap(_.channelId)
def ensureIsGuardianChannel(videoChannel: String) = {
if (youTube.channels.exists(_.id == videoChannel)) Some(videoChannel) else IncorrectYouTubeChannel
}
if (youTube.cannotReachYoutube) {
log.info(s"Config says cannot reach Youtube")
None
}
else {
try {
val maybeVideo = youTube.getVideo(asset.id, List("snippet"))
(existingChannel, maybeVideo) match {
case (_, None) =>
Some(YouTubeVideoDoesNotExist(asset.id))
case (None, Some(video)) => {
val videoChannel = video.getSnippet.getChannelId
atom.category match {
// only GLabs atoms can have third party videos
case ThriftCategory.Hosted | ThriftCategory.Paid => Some(videoChannel)
case _ => {
log.info(s"Atom $atomId does not have a channel, so falling back to channel provided by video ${asset.id}")
ensureIsGuardianChannel(videoChannel)
}
}
}
case (Some(channel), Some(video)) => {
val videoChannel = video.getSnippet.getChannelId
if (channel != videoChannel) {
log.info(s"Atom channel updating. New asset ${asset.id} on channel $videoChannel, atom on channel $channel")
}
// new asset must be on a Guardian channel
ensureIsGuardianChannel(videoChannel)
}
}
} catch {
case NonFatal(e) =>
MAMLogger.error("Unable to lookup YouTube channel", atomId, asset.id, e)
existingChannel
}
}
}