2020-04-21

DZ 移动端解析优酷B站腾讯视频代码

主要代码如下:

function parsemedia_for_mobile($url){
	$_url = parse_url($url);
	$type = explode(".", $_url['host'])[1];
	$return_url = '<iframe allowfullscreen="true" class="showcase-iframe" frameborder="0" height="200" src="';
	switch ($type) {
		case 'youku':
			if (substr($url, -10) == 'html/v.swf') {
				$_url = parse_url($url);
				$tmp = explode('/', $_url['path']);
				$tmp = explode('.', $tmp[3]);
				$return_url .= '//player.youku.com/embed/'.$tmp[0];
			} else {
				if (substr($url, -3) == 'swf') {
					$tmp = explode('sid/', $url);
					$tmp = explode('/', $tmp[1]);
					$vid = $tmp[0];
					$return_url .= '//player.youku.com/embed/'.$vid;
				} elseif (!stristr($url, 'embed')) {
					if (stristr($url, 'player')) {
						$vid = array_pop(array_pop(explode('/', $url)));
					}else{
						$vid = explode('.',explode("id_", $url)[1])[0];
						$vid = explode('_',$vid)[0];
					}
					$return_url .= '//player.youku.com/embed/'.$vid;
				} else {
					$return_url .= str_replace("http://", '//', $url);
				}
			}
			break;
		case 'bilibili':
			$arr = parse_url($url);
			if($arr['path'] == '/player.html'){
                $return_url .= "//player.bilibili.com/player.html?aid=" . str_replace('aid=', '', $arr['query']);
			} else {
                $return_url .= "//player.bilibili.com/player.html?aid=" . str_replace(array('/video/av','/'), '', $arr['path']);
			}
			break;
		case 'qq':
			if (!stristr($url, 'iframe')) {
				$parse = parse_url($url);
				if (stristr($url, 'static.video')) {
					$vid = explode('&', explode('=', $parse['query'])[1])[0];
				}else{
					if (stripos($url, 'iframe/player') === false) {
						if(preg_match("/^http:\/\/v.qq.com\/cover\/(\w+)\/([^\/]+)\/?vid=([^\/]+)/i", $url, $matches)) {
							$vid = $matches['3'];
						}else if(preg_match("/^https:\/\/v.qq.com\/cover\/(\w+)\/([^\/]+)\/?vid=([^\/]+)/i", $url, $matches)) {
							$vid = $matches['3'];
						}else if (preg_match("/^http:\/\/v.qq.com\/([\w\/]+)\/([^\/]+).html/i",$url,$matches)) {
							$vid = $matches['2'];
						}else if (preg_match("/^https:\/\/v.qq.com\/([\w\/]+)\/([^\/]+).html/i",$url,$matches)) {
							$vid = $matches['2'];
						}
					}else{
						if (preg_match("/^http:\/\/v.qq.com\/iframe\/player.html\?vid=([^\/&]+)&?/i", $url,$matches)) {
							$vid = $matches['1'];
						}
						if (preg_match("/^https:\/\/v.qq.com\/iframe\/player.html\?vid=([^\/&]+)&?/i", $url,$matches)) {
							$vid = $matches['1'];
						}
					}
				}
				$return_url .= '//v.qq.com/iframe/player.html?vid='.$vid.'&tiny=0&auto=0';
			}else{
				$return_url .= str_replace('http://', '//', $url);
			}
			break;
		default:
			return $url;
			break;
	}
	$return_url .= '" width="100%"></iframe>';
	return $return_url;
}

发表回复

Your email address will not be published. Required fields are marked *