'. " ".'
logo
'; $footer=' '; switch (@$_SERVER['PATH_INFO']) { case '/watch': echo $header; echo '

不能观看请刷新,多试几次,若页面一直处于加载状态,可手动停止!

'; echo '
'; echo $footer; break; case '/searchdata': $data=''; $videodata=get_search_video(urlencode($_GET['q']),$key,'video','relevance','tw',$_GET['pid']); foreach ($videodata["items"] as $v) { $data.='

'.$v["snippet"]["title"].'

'; } if(!array_key_exists("nextPageToken",$videodata) && array_key_exists("prevPageToken",$videodata)){ $pid='null'; }else{ $pid=$videodata["nextPageToken"]; } $jsonData =["pid" => $pid, "content" => $data]; echo json_encode($jsonData); break; case '/search': if(isset($_GET['q'])){ if(stripos($_GET['q'],'youtu.be')!==false || stripos($_GET['q'],'watch?v=')!==false ){ preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $_GET['q'], $matches); $str='../index.php/watch?'.$matches[1]; header("Location:$str"); exit();}} echo $header; $q=urlencode($_GET['q']); echo '

'.$_GET['q'].' 搜索结果

'; echo ''; echo $footer; break; default: echo $header; echo '

#时下流行#

'; $home_data=get_trending($key,'25','','tw'); foreach ($home_data["items"] as $v) { echo '

'.$v["snippet"]["title"].'

'; } echo '
'; echo $footer; break; } //CURL function get_data($url){ if (!function_exists("curl_init")) { $f = file_get_contents($url); } else { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch, CURLOPT_REFERER, 'http://www.youtube.com/'); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.91 Safari/534.30"); $f = curl_exec($ch); curl_close($ch); } return $f; } //获取热门 function get_trending($apikey,$max,$pageToken='',$regionCode='vn'){ $apilink='https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&chart=mostPopular®ionCode='.$regionCode.'&maxResults='.$max.'&key='.$apikey.'&pageToken='.$pageToken; return json_decode(get_data($apilink),true); } function Root_part(){ $http=isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; $part=rtrim($_SERVER['SCRIPT_NAME'],basename($_SERVER['SCRIPT_NAME'])); $domain=$_SERVER['SERVER_NAME']; return "$http"."$domain"."$part"; } //获取搜索数据 function get_search_video($query,$apikey,$type='video',$order='relevance',$regionCode='VN',$pageToken=''){ $apilink='https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=15®ionCode='.$regionCode.'&order='.$order.'&type='.$type.'&q='.$query.'&key='.$apikey.'&pageToken='.$pageToken; return json_decode(get_data($apilink),true); } ?>