Skip to content

Commit

Permalink
Merge pull request #151 from liruqi/master
Browse files Browse the repository at this point in the history
Cache category list and filter empty categories
  • Loading branch information
You2php authored May 9, 2018
2 parents 91022b6 + 1609b4f commit b16bf1e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ajax/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<ul class="list-group pt-3">
<li class="list-group-item font-weight-bold"></i>YOUTUBE 精选</li>
';
foreach($vica['items'] as $v){
foreach($vica as $v){
echo '<li class="list-group-item"><a href="./content.php?cont=category&sortid='.$v['id'].'" class="text-dark">'.$v['snippet']['title'].'</a></li>';
}
echo '</ul>';
Expand Down Expand Up @@ -349,4 +349,4 @@
break;
}

?>
?>
20 changes: 17 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,22 @@ function get_channel_video($cid,$pageToken='',$apikey,$regionCode='VN'){

//获取视频类别内容
function videoCategories($apikey,$regionCode='HK'){
$apilink='https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&regionCode='.$regionCode.'&hl=zh-CN&key='.$apikey;
return json_decode(get_data($apilink),true);
$apicache = '/tmp/ytb_videoCategories_'.$regionCode;
$json = file_get_contents($apicache);
if (empty($json)) {
$apilink='https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&regionCode='.$regionCode.'&hl=zh-CN&key='.$apikey;
$json = get_data($apilink);
file_put_contents($apicache,$json);
file_put_contents($apicache.".ts","REQUEST_TIME: " . $_SERVER['REQUEST_TIME']);
}
$ret = json_decode($json,true);
$items = $ret['items'];
if (strtolower($regionCode) == 'tw') {
return array_filter($items, function($v){
return array_search($v['id'], ['18','33','41','42']) === FALSE;
});
}
return $items;
}


Expand Down Expand Up @@ -506,4 +520,4 @@ function Root_part(){
$domain=$_SERVER['SERVER_NAME'];
return "$http"."$domain"."$part";
}
?>
?>

0 comments on commit b16bf1e

Please sign in to comment.