def uploadPart()

in common/src/main/scala/com/gu/media/youtube/YouTubeUploader.scala [57:83]


  def uploadPart(upload: Upload, part: UploadPart, uploadUri: String): Upload = {
    log.info(s"Uploading ${part.key} [${part.start} - ${part.end}]")

    val UploadPart(key, start, end) = part
    val total = upload.parts.last.end

    val input = s3.getObject(upload.metadata.bucket, key).getObjectContent

    uploadChunk(uploadUri, input, start, end, total) match {
      case VideoFullyUploaded(videoId) =>
        upload.copy(
          progress = upload.progress.copy(chunksInYouTube = upload.progress.chunksInYouTube + 1),
          metadata = upload.metadata.copy(asset = Some(YouTubeAsset(videoId)))
        )

      case MoveToNextChunk if part == upload.parts.last =>
        throw new IllegalStateException("YouTube did not provide a video id. The asset cannot be added")

      case MoveToNextChunk =>
        upload.copy(progress = upload.progress.copy(
          chunksInYouTube = upload.progress.chunksInYouTube + 1
        ))

      case UploadError(error) =>
        throw new IllegalStateException(error)
    }
  }