Parse video link

@param  Null
@return Array|Null
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;
    }
891053
public function parseResultMovieItem($fallbackUrl = null)
    {
        $resultItem = $this->parseResultItem($this->crawler, 'mid', '.info', $fallbackUrl);

        if ($resultItem == null) {
            return null;
        }

        $movie = new Movie($resultItem);

        return $movie;
    }
499451
public function parse( $string ) {
        $data = parse_url( $string );
        
        //helper function gets $a[$k], checks if exists
        function get( $a, $k ) {
            if( array_key_exists( $k, $a ) ) {
                return empty( $a[$k] ) ? null : $a[$k];
            }
            
            return null;
        }
        
        if( $data === null ) {
            return null;
        }
        
        $uri = new Uri;
        
        $uri->setProtocol( get( $data, 'scheme' ) );
        $uri->setUsername( get( $data, 'user' ) );
        $uri->setPassword( get( $data, 'pass' ) );
        $uri->setHost( get( $data, 'host' ) );
        $uri->setPort( get( $data, 'port' ) );
        $uri->setPath( get( $data, 'path' ) );
        $uri->setQuery( get( $data, 'query' ) );
        $uri->setAnchor( get( $data, 'anchor' ) );
        
        return $uri;
    }
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;
    }
464132
protected function matchVideo()
    {
        return ReplyRuleKeyword::find()
            ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_VIDEO, ReplyRuleKeyword::TYPE_SHORT_VIDEO]])
            ->wechatRule($this->getWechat()->id)
            ->limitTime(TIMESTAMP)
            ->all();
    }
30432
public function getReplyFormat() {
		if($this->type != 2) {
			return null;
		}

		$reply = [
			'ToUserName' => $this->to_user_name,
			'FromUserName' => $this->from_user_name,
			'CreateTime' => $this->created_at,
			'MsgType' => $this->msg_type,
		];
		switch($this->msg_type) {
			case 'text':
				$reply['Content'] = $this->content;
				break;
			case 'image':
				$reply['Image']['MediaId'] = $this->media_id;
				break;
			case 'voice':
				$reply['Voice']['MediaId'] = $this->media_id;
				break;
			case 'video':
				$reply['Video'] = [
					'MediaId' => $this->media_id,
					'Title' => $this->title,
					'Description' => $this->description,
				];
				break;
			case 'music':
				$reply['Music'] = [
					'Title' => $this->title,
					'Description' => $this->description,
					'MusicUrl' => $this->music_url,
					'HQMusicUrl' => $this->hq_music_url,
					'ThumbMediaId' => $this->thumb_media_id,
				];
				break;
			case 'news':
				$articles = $this->articleList;
				$reply['ArticleCount'] = count($articles);
				$reply['Articles'] = [];
				foreach($articles as $article) {
					$reply['Articles'][] = [
						'Title' => $article['title'],
						'Description' => $article['description'],
						'PicUrl' => $article['pic_url'],
						'Url' => $article['url'],
					];
				}
				break;
			default:
				return null;
				break;
		}

		return $reply;
	}
1052190
public function getParams($key = null) {
		if (!empty($this->_stub['iframe-player']) && $this->config['prefer'] === 'iframe') {
			if ($key === null) {
				return $this->_iframeParams;
			}
			if (!isset($this->_iframeParams[$key])) {
				return null;
			}
			return $this->_iframeParams[$key];
		}

		if ($key === null) {
			return $this->_objectParams;
		}
		if (!isset($this->_objectParams[$key])) {
			return null;
		}
		return $this->_objectParams[$key];
	}
515799
public function getFileType()
    {
        if (!$this->isFile()) {
            return null;
        }

        if (!self::$imageExtensions) {
            self::$imageExtensions = array_map('strtolower', Config::get('cms.storage.media.imageExtensions', FileDefinitions::get('imageExtensions')));
            self::$videoExtensions = array_map('strtolower', Config::get('cms.storage.media.videoExtensions', FileDefinitions::get('videoExtensions')));
            self::$audioExtensions = array_map('strtolower', Config::get('cms.storage.media.audioExtensions', FileDefinitions::get('audioExtensions')));
        }

        $extension = strtolower(pathinfo($this->path, PATHINFO_EXTENSION));
        if (!strlen($extension)) {
            return self::FILE_TYPE_DOCUMENT;
        }

        if (in_array($extension, self::$imageExtensions)) {
            return self::FILE_TYPE_IMAGE;
        }

        if (in_array($extension, self::$videoExtensions)) {
            return self::FILE_TYPE_VIDEO;
        }

        if (in_array($extension, self::$audioExtensions)) {
            return self::FILE_TYPE_AUDIO;
        }

        return self::FILE_TYPE_DOCUMENT;
    }
274165
private function getEpisode()
    {
        $episode = [];
        $episode_area = $this->_parser->find('.episode-video', 0);
        if ($episode_area) {
            foreach ($episode_area->find('.video-list-outer') as $v) {
                $temp = [];

                $link_area = $v->find('a', 0);
                $temp['episode'] = $this->getEpisodeTitle($link_area, 0);
                $temp['title'] = $this->getEpisodeTitle($link_area, 1);
                $temp['link'] = $link_area->href;

                $episode[] = $temp;
            }
        }

        return $episode;
    }
1014797
public function parseMovies($includeShowtimes = true)
    {
        $movieDivs = $this->crawler->filter('#movie_results .movie');

        $count = $movieDivs->count();

        if ($count == 0) {
            return null;
        }

        if ($count = 1) {
            $justOneMovieFound = true;
        }

        $movies = $movieDivs->each(function (Crawler $movieDiv, $i) use (
            $includeShowtimes,
            $justOneMovieFound
        ) {

            $resultItemParser = new ResultItemParser($movieDiv);

            if ($justOneMovieFound) {
                //extract url with mid from
                $firstLeftNavLink = $this->getFirstLeftNavLink();
                $fallbackUrl = $firstLeftNavLink->attr('href');
                $movie = $resultItemParser->parseResultMovieItem($fallbackUrl);
            } else {
                $movie = $resultItemParser->parseResultMovieItem();
            }

            if ($movie == null) {
                return null;
            }

            $movieInfoLinks = $movieDiv->filter('.info a');
            if (count($movieInfoLinks) > 0) {
                $imdbLink = $movieInfoLinks->last();
                if ($imdbLink != null) {
                    $movie->setImdbLink(ParseHelper::getParamFromLink($imdbLink->attr('href'), 'q'));
                }
            }

            if ($includeShowtimes) {
                $movie->setShowtimeInfo($this->parseShowtimeInfo($movieDiv));
            }

            return $movie;
        });

        return $movies;
    }
726959
public function parse()
    {
        $count = (int) $this->data;
        if ($count < 0) {
            return null;
        }

        $elements = [];
        for ($i=0; $i < $count; $i++) {
            $elements[$i] = call_user_func($this->receiver);
        }
        return $elements;
    }
570898
private function parseUrl($url)
    {
        if (preg_match('/(?:(vimeo)(?:.com\/(?:video\/)?)(\d+))|(?:(youtu\.?be)(?:\.com\/|\/)?(?:watch|embed)?(?:\?v=|\/)?([a-z0-9-_.]+))/i', $url, $data)) {
            $data = array_values(array_filter($data));

            array_shift($data);

            $this->videoType = str_replace('.', '', $data[0]);
            $this->videoId = $data[1];

            return true;
        }

        return false;
    }
651402
private function getVideos()
    {
        $video = $this->event->get('video') ?: $this->event->get('video_note');
        $response = $this->http->get($this->buildApiUrl('getFile'), [
            'file_id' => $video['file_id'],
        ]);

        $responseData = json_decode($response->getContent());

        if ($response->getStatusCode() !== 200) {
            throw new TelegramAttachmentException('Error retrieving file url: '.$responseData->description);
        }

        $url = $this->buildFileApiUrl($responseData->result->file_path);

        return [new Video($url, $video)];
    }
750109
public function getPreview($video_link = null, $video_id = null, $size = 'default') {
        $result = $this->checkVideo($video_link, $video_id, $part = 'snippet');
        return $result['items'][0]['snippet']['thumbnails'][$size];
    }
131101
private function checkVideo($video_link = null, $video_id = null, $part) {
        if (!$video_link && !$video_id) {
            throw new UserException(Yii::t('app', 'Не отправлено свойство video_link или video_id.'));
        }
        if ($video_link && !$video_id) {
            $array = explode('/', $video_link);
            $video_id = array_pop($array);
            $video_id = str_replace('watch?v=', '', $video_id);
        }

        $video_id = trim($video_id);
        
        $json_result = file_get_contents ("https://www.googleapis.com/youtube/v3/videos?part=$part&id=$video_id&key=$this->key");
        $result = Json::decode($json_result);

        if (!$result['items']) {
            throw new UserException(Yii::t('app', 'Видео не найдено.'));
        }

        return $result;
    }
1238123
public function build()
    {
        $video = [
            'originalContentUrl' => $this->originalContentUrl,
            'previewImageUrl' => $this->previewImageUrl,
            'area' => $this->areaBuilder->build()
        ];
        if ($this->externalLinkBuilder) {
            $video['externalLink'] = $this->externalLinkBuilder->build();
        }
        return $video;
    }
54113
function videoIntent(){
        $this->waitAnswer();

        $videoName = $this->getSlot('videoname');
        if($videoName){
            $video = $this->getDetailBy("video","title",$videoName);
            $directives = $this->getVideoPlay($video["id"]);
            if($directives){
                return [
                    'directives' => $directives
                ];
            }else{
                $speech = "没有找到你要播放的视频";
                $hint = new Hint('第一个','我想看告白气球');
                $template = $this->getVideoCard();
                return [
                    'outputSpeech' => $speech,
                    'directives' => [$hint,$template],
                ];
            }
        }
        $speech = '请选择您要播放的视频';
        $reprompt = '没有听懂，请告诉我想要播放的视频';
        $template = $this->getVideoCard();
        
        //定义hint指令
        $hint = new Hint('第一个','我想看告白气球');
        return [
            'outputSpeech' => $speech,
            'reprompt' => $reprompt,
            'directives' => [$hint,$template],
        ];
    }