parsePlaylistId static method

String? parsePlaylistId(
  1. String url
)

Parses a playlist url returning its id. If the url is a valid it is returned itself.

Implementation

static String? parsePlaylistId(String url) {
  if (url.isNullOrWhiteSpace) {
    return null;
  }

  if (validatePlaylistId(url)) {
    return url;
  }

  final regMatch = _regMatchExp.firstMatch(url)?.group(1);
  if (!regMatch.isNullOrWhiteSpace && validatePlaylistId(regMatch!)) {
    return regMatch;
  }

  final compositeMatch = _compositeMatchExp.firstMatch(url)?.group(1);
  if (!compositeMatch.isNullOrWhiteSpace &&
      validatePlaylistId(compositeMatch!)) {
    return compositeMatch;
  }

  final shortCompositeMatch =
      _shortCompositeMatchExp.firstMatch(url)?.group(1);
  if (!shortCompositeMatch.isNullOrWhiteSpace &&
      validatePlaylistId(shortCompositeMatch!)) {
    return shortCompositeMatch;
  }

  final embedCompositeMatch =
      _embedCompositeMatchExp.firstMatch(url)?.group(1);
  if (!embedCompositeMatch.isNullOrWhiteSpace &&
      validatePlaylistId(embedCompositeMatch!)) {
    return embedCompositeMatch;
  }
  return null;
}