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;
  }

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

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

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

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