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;
    }
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;
    }
Extracts a video identifier from a YouTube URL.

@param string $url
@return string|null Identifier or null if none is found