validateYlExternalSubtitles function

void validateYlExternalSubtitles(
  1. List<YlExternalSubtitle> subtitles
)

Implementation

void validateYlExternalSubtitles(List<YlExternalSubtitle> subtitles) {
  if (subtitles.length > 32) {
    throw ArgumentError('Too many external subtitles.');
  }
  final ids = <String>{};
  for (final subtitle in subtitles) {
    _metadata(
      id: subtitle.id,
      label: subtitle.label,
      language: subtitle.language,
      role: subtitle.role,
      contentId: subtitle.contentId,
    );
    if (!ids.add(subtitle.id)) {
      throw ArgumentError('Duplicate external subtitle identity.');
    }
    _source(subtitle.source);
    if ((subtitle.format == YlSubtitleFormat.vobsub) !=
        (subtitle.companionSource != null)) {
      throw ArgumentError(
        'Subtitle companion resource does not match the format.',
      );
    }
    if (subtitle.companionSource case final source?) _source(source);
  }
}