Returns embed URL for a Youtube video, from its link
@param string $videoUrl Video URL on Youtube website
484890
public static function getYoutubeEmbedUrl( $videoUrl )
    {
        $embedLink = '';
        $embedINI = eZINI::instance( 'embedtag.ini' );

        preg_match( self::YOUTUBE_VIDEOID_REGEXP, $videoUrl, $matches );
        if ( isset( $matches['videoId'] ) )
        {
            $embedLink = str_replace( '$$$VIDEO$$$', $matches['videoId'], $embedINI->variable( 'YoutubeSettings', 'EmbedLinkPattern' ) );
        }

        return array( 'result' => $embedLink );
    }
1255383
static function getDownloadUrl($videoUrl) {
		$toplevelDomain = parse_url($videoUrl);
		$toplevelDomain = $toplevelDomain['host'];
		
		if (!is_dir(__DIR__ . DIRECTORY_SEPARATOR . 'ProviderHandler' . DIRECTORY_SEPARATOR . $toplevelDomain)) {
			throw new \Exception('There is no special implementation for the provider ' . $toplevelDomain . '!');
		}
		
		require_once __DIR__ . DIRECTORY_SEPARATOR . 'ProviderHandler' . DIRECTORY_SEPARATOR . $toplevelDomain . DIRECTORY_SEPARATOR . 'Provider.php';
		$provider = new \Provider($videoUrl);
		return $provider->getDownloadUrl();
	}
790140
public static function getFromUrl($url)
    {
        // check is valid url
        if (!filter_var($url, FILTER_VALIDATE_URL) || !function_exists('curl_init')) {
            return null;
        }

        // initialize curl & set required options and target url
        $curl = \curl_init();
        \curl_setopt($curl, CURLOPT_URL, $url);
        if (Str::startsWith('https', $url)) {
            \curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
            \curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        }
        \curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        \curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
        \curl_setopt($curl, CURLOPT_HEADER, 0);
        \curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
        \curl_setopt($curl, CURLOPT_FAILONERROR, true);
        \curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        \curl_setopt($curl, CURLOPT_AUTOREFERER, true);
        \curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        $content = \curl_exec($curl);
        \curl_close($curl);

        return $content;
    }
20386
public function getEmbedUrl($url, $params = [])
    {
        return Template::raw(VideoEmbedder::$plugin->service->getEmbedUrl($url, $params));
    }
700467
public static function getRobotsTxtURL($url)
  {
    $url_parts = PHPCrawlerUtils::splitURL($url); 
    $robots_txt_url = $url_parts["protocol"].$url_parts["host"].":".$url_parts["port"] . "/robots.txt";
    
    return $robots_txt_url;
  }
799390
public function getEmbedUrl($noCookie = false)
    {
        $embedUrl = 'https://'.self::COOKIE_EMBED_HOST."/embed/%s%s";
        
        if ($noCookie) {
            $embedUrl = 'https://'.self::NO_COOKIE_EMBED_HOST."/embed/%s%s";
        }
        
        $embedParams = $this->embed->getNonNullProperties();
        
        $query = '';
        if ($embedParams) {
            $query = '?'.http_build_query($embedParams);
        }
        
        return sprintf($embedUrl, $this->id, $query);
    }
430965
public function isolateVimeoVideoCode($link)
    {
        try {
            if (preg_match("/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/", $link, $output_array)) {
                return $output_array[5];
            }
        } catch (\Exception $e) {
            throw new VideoException("can't match vimeo code in given url", $e);
        }
    }
50830
public function getVideoInfo($url)
    {
        if (!empty($url)) {
            if (strpos($url, 'youtube')) {
                preg_match('/(?<=v(\=|\/))([-a-zA-Z0-9_]+)|(?<=youtu\.be\/)([-a-zA-Z0-9_]+)/', $url, $v);
                $provider = 'youtube';
                $url_data = sprintf($this->_youtubeVideoApi, $v[0]);
            } elseif (strpos($url, 'vimeo')) {
                preg_match('(\d+)', $url, $id);
                $provider = 'vimeo';
                $url_data = sprintf($this->_vimeoVideoApi, $id[0]);
            }

            switch ($provider) {
                case 'youtube':
                    $ch = curl_init($url_data);  
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/json')); 
                    $result = json_decode(curl_exec($ch), true);
                    curl_close($ch);

                    return array(
                        'title'       => $result['entry']['title']['$t'],
                        'description' => $result['entry']['media$group']['media$description']['$t'],
                        'thumbnail'   => $result['entry']['media$group']['media$thumbnail'][0]['url'],
                        'duration'    => $result['entry']['media$group']['media$content'][0]['duration'],
                        'upload_date' => $result['entry']['media$group']['yt$uploaded']['$t'],
                    );
                    break;

                case 'vimeo':
                    $ch = curl_init($url_data);  
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/json')); 
                    $result = json_decode(curl_exec($ch), true);
                    curl_close($ch);

                    return array(
                        'title'       => $result[0]['title'],
                        'description' => $result[0]['description'],
                        'thumbnail'   => $result[0]['thumbnail_small'],
                        'duration'    => $result[0]['duration'],
                        'upload_date' => $result[0]['upload_date']
                    );
                    break;
                
                default:
                    return false;
                    break;
            }
        }
        return false;
    }
402924
public function isolateYoutubeVideoCode($link)
    {
        try {
            if (preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $link, $matches)) {
                return $matches[0];
            }
        } catch (\Exception $e) {
            throw new VideoException("can't match youtube code in given url", $e);
        }
    }
342702
public function getVideo()
    {
        // This function is based on code by Wouter Sioen released under the MIT license
        // see woutersioen/sir-trevor-php
        // Regexps from http://stackoverflow.com/questions/10488943/easy-way-to-get-vimeo-id-from-a-vimeo-url
        // and http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url
        if (preg_match('/.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/', $this->getVideoUrl(), $matches)) {
            $data = array(
                'source' => 'youtube',
                'remote_id' => $matches[1]
            );
        } elseif (preg_match('/(?:https?:\/\/)?(?:www\.)?(?:player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/', $this->getVideoUrl(), $matches)) {
            $data = array(
                'source' => 'vimeo',
                'remote_id' => $matches[2]
            );
        } else {
            throw new \FelixOnline\Exceptions\InternalException('The specified video URL is not valid');
        }

        if ($data['source'] == 'youtube') {
            $html = '<iframe src="//www.youtube.com/embed/' . $data['remote_id'] . '?rel=0" ';
            $html .= 'frameborder="0" allowfullscreen></iframe>' . "\n";
        } else {
            $html = '<iframe src="//player.vimeo.com/video/' . $data['remote_id'];
            $html .= '?title=0&amp;byline=0" frameborder="0"></iframe>' . "\n";
        }

        return $html;
    }
888303
public function embed( $url, $params = [] ) : string
    {
        $code = $this->getInfo($url)->code;

        // check if theree are any parameters passed along
        if (!empty($params)) {
            
            // looks like there are, now let's only do this for YouTube and Vimeo
            if($this->getInfo($url)->type == 'video' && ($this->isYouTube($url) || $this->isVimeo($url)))
            {

                // for videos add autoplay check if the embed gets the code

                // create an easy html parser to verify the iframe and add autoplay for video types
                $dom = new DOMDocument;

                // set error level so that the html parser doesn't raise exceptions on warnings
                $internalErrors = libxml_use_internal_errors(true);

                $dom->loadHTML($code);

                // Restore error level
                libxml_use_internal_errors($internalErrors);

                // get the iframe
                $frame = $dom->getElementsByTagName('iframe')->item(0);

                //get the src from iframe
                $src = $frame->getAttribute('src');


                // check if url has any other parameters to properly add the parameter
                if (strpos($src,'?') !== false) {
                    $src .= "&";
                } else {
                    $src .= "?";
                }
                
                $parameters = '';
                foreach ($params as $k=>$v) {
                    if ($parameters !== null) {
                        $parameters .= '&';
                    }
                    $parameters .= "{$k}={$v}";
                }

                $src .= $parameters;

                // set the new src with all the parameters
                $frame->setAttribute('src', $src);

                // replace old iframe html with new one
                return htmlspecialchars_decode($dom->saveHTML($frame));
            }
            else
            {
                if (!empty($code)) {
                    // Not YouTube or Vimeo, just output the code
                    return $code;
                }
                else
                {
                    return '';
                }
            }
        }
        else
        {
            if (!empty($code)) {
                // No parameters passed, just output the code
                return $code;
            }
            else
            {
                return '';
            }
        }

    }
438649
private function parseLink()
    {
        $value = $this->RAW();

        if (!$value) {
            return false;
        }

        $output = false;

        if (preg_match(
            '/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/i',
            $value,
            $matches
        )) {
            foreach ($matches as $match) {
                if (preg_match('/^[0-9]{6,12}$/', $match)) {
                    $output = [
                        'VideoID'      => $match,
                        'VideoService' => 'Vimeo',
                    ];
                }
            }
        } elseif (preg_match('/https?:\/\/youtu\.be\/([a-z0-9\_\-]+)/i', $value, $matches)) {
            $output = [
                'VideoID'      => $matches[1],
                'VideoService' => 'YouTube',
            ];
        } elseif (preg_match('/youtu\.?be/i', $value)) {
            $query_string = [];
            parse_str(parse_url($value, PHP_URL_QUERY), $query_string);
            if (!empty($query_string['v'])) {
                $output = [
                    'VideoID'      => $query_string['v'],
                    'VideoService' => 'YouTube',
                ];
            }
        }

        return ($output) ? $output : false;
    }
7011
public function getTitle($url) {
        return Template::raw(VideoEmbedder::$plugin->service->getInfo($url)->title);
    }
171439
public static function getId($url)
    {
        if (strpos($url, 'youtube.com') !== false) {
            $url = parse_url($url);

            if (empty($url['query'])) {
                return false;
            }

            parse_str($url['query'], $url);

            return empty($url['v']) ? false : $url['v'];
        }

        if (preg_match('/youtu\.be\/([^?]+)/', $url, $matches)) {
            return $matches[1];
        }

        return false;
    }
1041793
protected function normalizeUrl()
    {
        if (preg_match('~dailymotion\.com/(?:embed/)?(?:video|live)/([^/]+)/?~i', $this->url, $matches)) {
            $this->url = new \Embera\Url('http://www.dailymotion.com/video/' . $matches['1']);
        } else if (preg_match('~dai\.ly/([^/]+)/?~i', $this->url, $matches)) {
            $this->url = new \Embera\Url('http://www.dailymotion.com/video/' . $matches['1']);
        }
    }
303708
public function api_get($url, $params)
    {
        //set the youtube key
        $params['key'] = $this->youtube_key;

        //boilerplates for CURL
        $tuCurl = curl_init();
        if ($this->sslPath !== null) {
            curl_setopt($tuCurl, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt($tuCurl, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($tuCurl, CURLOPT_CAINFO, __DIR__ . '/cert/cacert.pem');
            curl_setopt($tuCurl, CURLOPT_CAPATH, __DIR__ . '/cert/cacert.pem');
        }
        curl_setopt($tuCurl, CURLOPT_URL, $url . (strpos($url, '?') === false ? '?' : '') . http_build_query($params));
        if ($this->referer !== null) {
            curl_setopt($tuCurl, CURLOPT_REFERER, $this->referer);
        }
        curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
        $tuData = curl_exec($tuCurl);
        if (curl_errno($tuCurl)) {
            throw new \Exception('Curl Error : ' . curl_error($tuCurl), curl_errno($tuCurl));
        }
        return $tuData;
    }
1322774
public function getHash($url)
    {
        switch (parse_url($url)['host']) {
            case 'www.youtube.com':
                // https://www.youtube.com/watch?v=Vhx_wC1pve8
                parse_str(parse_url($url)['query'], $result);

                return $result['v'];
                break;
            case 'dai.ly':
            case 'vimeo.com':
            case 'youtu.be':
                // https://dai.ly/x97qvv
                // https://vimeo.com/8914294
                // https://youtu.be/Vhx_wC1pve8
                return ltrim(parse_url($url)['path'], '/');
                break;
            case 'www.dailymotion.com':
                // https://www.dailymotion.com/playlist/xpsn5_giorgiopao_tango-argentino/1#video=x5uvup
                if (strpos(parse_url($url)['path'], 'playlist') !== false) {
                    parse_str(parse_url($url)['fragment'], $result);

                    return $result['video'];
                }

                // https://www.dailymotion.com/video/x5232zo_jaguar-i-pace-concept-2016_auto
                // https://www.dailymotion.com/video/x5s849a
                $temp = ltrim(strrchr(parse_url($url)['path'], '/'), '/');
                if (stripos($temp, '_')) {
                    return strstr($temp, '_', true);
                }

                return $temp;
                break;
            case 'giphy.com':
                // https://giphy.com/gifs/030tango-tango-argentine-uGrH3htu5xFW8
                $result = ltrim(strrchr(parse_url($url)['path'], '/'), '/');
                if (strpos($result, '-') !== false) {
                    return ltrim(strrchr($result, '-'), '-');
                }

                return $result;
                break;
            case 'gist.github.com':
            case 'twitter.com':
            case 'www.argus360.fr':
                // https://gist.github.com/vovadocent/7b4a58d7d9e8abb3c68dd82607c2bbf0
                // https://twitter.com/TangoZoneOrg/status/858612556533051392
                // https://www.argus360.fr/viewer/share/3e7802c1cd69f08f2a3bae389816ece6?res=1920x1080&vdp=off
                return ltrim(strrchr(parse_url($url)['path'], '/'), '/');
                break;
            case 'www.car360app.com':
                // https://www.car360app.com/viewer/portable.php?spin=7a8fb5ac7ba0eee31a9e86eff6682bf2&ZoomButtons=off&ZoomScroll=off&TagsList=off&FullscreenButton=off&res=640x360
                parse_str(parse_url($url)['query'], $result);

                return $result['spin'];
                break;
            default:
                return null;
        }
    }