code: protected function getVideoId($url)
      {
          $logger = $this->getLogger();
          $parsed = parse_url($url);
          $logger->debug('getVideoId', array('url' => $url, 'parsed' => $parsed));
          switch ($parsed['host']) {
              case 'youtu.be':
                  return ltrim($parsed['path'], '/');
              case 'www.youtube.com':
              case 'youtube.com':
                  if (!empty($parsed['query'])) {
                      parse_str($parsed['query'], $query);
                      $logger->debug('getVideoId', array('url' => $url, 'query' => $query));
                      if (!empty($query['v'])) {
                          return $query['v'];
                      }
                  } elseif (isset($parsed['path']) && substr($parsed['path'], 0, 7) == '/embed/') {
                      $logger->debug('getVideoId', array('url' => $url, 'path' => $parsed['path']));
                      $vId = substr($parsed['path'], 7);
                      if (!empty($vId)) {
                          return $vId;
                      }
                  }
          }
          return null;
      }
docs: Extracts a video identifier from a YouTube URL.
  
  @param string $url
  @return string|null Identifier or null if none is found