parseChannelHandle static method

String? parseChannelHandle(
  1. String handleOrUrl
)

Parses a ChannelHandle from a url.

Implementation

static String? parseChannelHandle(String handleOrUrl) {
  if (handleOrUrl.isEmpty) {
    return null;
  }

  if (validateChannelHandle(handleOrUrl)) {
    return handleOrUrl;
  }

  final regMatch = RegExp(r'youtube\..+?/(@.*?)(?:\?|&|/|$)')
      .firstMatch(handleOrUrl)
      ?.group(1);
  if (!regMatch.isNullOrWhiteSpace && validateChannelHandle(regMatch!)) {
    return regMatch;
  }
  return null;
}