dataFromVideoDeliveryUrl static method

Map<String, dynamic> dataFromVideoDeliveryUrl(
  1. String url
)

Implementation

static Map<String, dynamic> dataFromVideoDeliveryUrl(String url) {
  String cleanUrl = url
      .replaceAll('$uploadVideoDeliveryUrl/', '')
      .replaceAll('$watchVideoDeliveryUrl/', '')
      .replaceAll('$videoDeliveryUrl/', '')
      .replaceAll('$videoCloudflareUrl/', '');
  String? videoId;
  String? customAccountSubdomainCode;

  final specificAccountSubdomainMatch =
      specificCloudflareAccountSubdomainRegExp.firstMatch(cleanUrl);
  if (specificAccountSubdomainMatch != null) {
    if (specificAccountSubdomainMatch.groupCount > 0) {
      cleanUrl = specificAccountSubdomainMatch.group(1) ?? cleanUrl;
      final codeMatch =
          specificCloudflareAccountSubdomainCodeRegExp.firstMatch(url);
      if (codeMatch != null && codeMatch.groupCount > 0) {
        customAccountSubdomainCode = codeMatch.group(1);
      }
    }
  }

  final split = cleanUrl.split('/');
  videoId = split.isNotEmpty ? split[0] : null;

  if (videoId == null) {
    // throw Exception('Invalid Cloudflare video from url');
    return {};
  }
  return {
    Params.id: videoId,
    Params.subdomainAccountCode: customAccountSubdomainCode,
  };
}