validatePlaylistId static method

bool validatePlaylistId(
  1. String playlistId
)

Returns true if the given playlistId is valid.

Implementation

static bool validatePlaylistId(String playlistId) {
  playlistId = playlistId.toUpperCase();

  if (playlistId.isNullOrWhiteSpace) {
    return false;
  }

  // Watch later
  if (playlistId == 'WL') {
    return true;
  }

  // My mix playlist
  if (playlistId == 'RDMM') {
    return true;
  }

  if (!playlistId.startsWith('PL') &&
      !playlistId.startsWith('RD') &&
      !playlistId.startsWith('UL') &&
      !playlistId.startsWith('UU') &&
      !playlistId.startsWith('PU') &&
      !playlistId.startsWith('OL') &&
      !playlistId.startsWith('LL') &&
      !playlistId.startsWith('FL')) {
    return false;
  }

  if (playlistId.length < 13) {
    return false;
  }

  return !RegExp(r'[^0-9a-zA-Z_\-]').hasMatch(playlistId);
}