@param $link

@throws VideoException

@return mixed
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);
        }
    }
1044122
protected function _getVideo($url) {
        return $this->_useVimeoPro ? $this->_getProVideo($url) : $this->_getRegularVideo($url);
    }
903277
public function cleanLink($link)
	{
		$link = strtolower(preg_replace(
					array('#[\\s-]+#', '#[^A-Za-z0-9/ -]+#'),
					array('-', ''),
				    $this->cleanString(urldecode($link))
		));

		$link = preg_replace('/\/+/', '/', $link);
		$link = preg_replace('/-+/', '-', $link);
		
		return $link;
	}
369222
public static function href($link) {
        if(isset($link['uri']) || isset($link['fragment'])) {
            return ' href="'.URI::getHref($link).'"';
        }
        return false;
    }
522516
private function isLinkDecorable($link)
    {
        if (!is_object($link) || !property_exists($link, 'type')) {
            return false;
        }

        return $link->type == 'notes' || $link->type == 'exceptions';
    }
905688
public static function sendVideo($video , $title = '', $description = ''){
        self::initialize();
        $data = compact('title','description');
        try {
            $response = self::$fb->uploadVideo('me', $video,$data, self::$page_access_token);
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
            throw new \Exception('Graph returned an error: '.$e->getMessage());
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
            throw new \Exception('Facebook SDK returned an error: '.$e->getMessage());
        }
        $graphNode = $response->getGraphNode();

        return $graphNode['id'];
    }
995032
public function getFileInfo($link)
    {
        // get the media link from the resource
        $resource = $this->getResource(\tao_helpers_Uri::decode($link));
        if (!$resource->exists()) {
            throw new \tao_models_classes_FileNotFoundException($link);
        }

        $fileLink = $resource->getUniquePropertyValue($this->getProperty(MediaService::PROPERTY_LINK));
        $fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string)$fileLink;
        $file = null;
        $mime = (string) $resource->getUniquePropertyValue($this->getProperty(MediaService::PROPERTY_MIME_TYPE));

        // add the alt text to file array
        $altArray = $resource->getPropertyValues($this->getProperty(MediaService::PROPERTY_ALT_TEXT));
        $alt = $resource->getLabel();
        if (count($altArray) > 0) {
            $alt = $altArray[0];
        }

        $file = array(
            'name' => $resource->getLabel(),
            'uri' => self::SCHEME_NAME . \tao_helpers_Uri::encode($link),
            'mime' => $mime,
            'size' => $this->getFileManagement()->getFileSize($fileLink),
            'alt' => $alt,
            'link' => $fileLink
        );

        return $file;
    }
899017
public function click(Link $link)
    {
        if ($link instanceof Form) {
            return $this->submit($link);
        }

        return $this->request($link->getMethod(), $link->getUri());
    }
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;
    }
205657
public static function read(string $link = ''): string
    {
        $link = static::normalizePath($link);
        if (static::exists($link)) {
            return @\readlink($link);
        }
        return '';
    }
1035163
public function getDescription($url) {
        return Template::raw(VideoEmbedder::$plugin->service->getInfo($url)->description);
    }
590078
public function download($link)
    {
        $url = str_replace('\/', '/', $link);
        $fileName = \tao_helpers_File::createTempDir() . basename($link);

        common_Logger::d('Downloading ' . $url);
        helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::NO_TIMEOUT);
        $fp = fopen($fileName, 'w+');
        $curlHandler = curl_init();
        curl_setopt($curlHandler, CURLOPT_URL, $url);
        curl_setopt($curlHandler, CURLOPT_FILE, $fp);
        curl_setopt($curlHandler, CURLOPT_TIMEOUT, 50);
        curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, true);

        //if there is an http auth on the local domain, it's mandatory to auth with curl
        if (USE_HTTP_AUTH) {

            $addAuth = false;
            $domains = array('localhost', '127.0.0.1', ROOT_URL);

            foreach ($domains as $domain) {
                if (preg_match("/" . preg_quote($domain, '/') . "/", $url)) {
                    $addAuth = true;
                }
            }

            if ($addAuth) {
                curl_setopt($curlHandler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                curl_setopt($curlHandler, CURLOPT_USERPWD, USE_HTTP_USER . ":" . USE_HTTP_PASS);
            }
        }

        curl_exec($curlHandler);
        $httpCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
        $success = $httpCode == 200;
        curl_close($curlHandler);
        fclose($fp);
        helpers_TimeOutHelper::reset();

        return $fileName;
    }
660188
public function linkBuilder($link)
    {
        if (is_array($link)) {
            list($route, $params) = $link;

            return $this->generateLink($route, $params);
        } else {
            return $this->generateLink($link, null);
        }
    }
1122363
public function download($link)
    {
        $file = $this->getFile($link);

        $relPath = $this->getItemDirectory()->getRelPath($file);

        $tmpDir = rtrim(\tao_helpers_File::createTempDir(), '/');
        $tmpFile = $tmpDir . $relPath;
        if (! is_dir(dirname($tmpFile))) {
            mkdir(dirname($tmpFile), 0755, true);
        }

        if (($resource = fopen($tmpFile, 'w')) !== false) {
            stream_copy_to_stream($file->readStream(), $resource);
            fclose($resource);
            return $tmpFile;
        }

        throw new \common_Exception('Unable to write "' . $link . '" into tmp folder("' . $tmpFile . '").');
    }
338992
protected function composeListLink($link)
    {
        $query = $this->addIdToQuery();
        $query = $this->addPaginationToQuery($query);

        $link .= '?' . http_build_query($query);

        return $link;
    }
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);
        }
    }
867633
public static function get_video_embed_url( $url ) {
		if ( strpos( $url, 'youtube' ) !== false && strpos( $url, 'watch' ) !== false ) {
			$parts = wp_parse_url( $url );

			if ( is_array( $parts ) && isset( $parts['query'] ) ) {
				parse_str( $parts['query'] );
				if ( isset( $v ) ) {
					return 'https://www.youtube.com/embed/' . $v;
				}
			}
		}

		if ( strpos( $url, 'vimeo' ) !== false && strpos( $url, 'player' ) === false ) {
			$parts = wp_parse_url( $url );

			if ( is_array( $parts ) && isset( $parts['path'] ) ) {
				return 'https://player.vimeo.com/video' . $parts['path'];
			}
		}

		return $url;
	}