Skip to content

Commit

Permalink
Merge pull request #152 from liruqi/master
Browse files Browse the repository at this point in the history
 Remove hard code categories
  • Loading branch information
You2php authored May 17, 2018
2 parents 3b7b2a2 + 6e3fd71 commit a64774b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 42 deletions.
2 changes: 1 addition & 1 deletion ajax/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
}
break;
case 'menu':
$vica=videoCategories(APIKEY,GJ_CODE);
$vica=videoCategories();

echo '<ul class="list-group text-dark">
<li class="list-group-item font-weight-bold"><i class="fa fa-home fa-fw pr-4"></i><a href="./" class="text-dark">首页</a></li>
Expand Down
55 changes: 14 additions & 41 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function get_channel_video($cid,$pageToken='',$apikey,$regionCode='VN'){
}

//获取视频类别内容
function videoCategories($apikey,$regionCode='HK'){
function videoCategories($apikey=APIKEY,$regionCode=GJ_CODE){
$apicache = '/tmp/ytb_videoCategories_'.$regionCode;
$json = file_get_contents($apicache);
if (empty($json)) {
Expand All @@ -72,53 +72,26 @@ function videoCategories($apikey,$regionCode='HK'){
$items = $ret['items'];
if (strtolower($regionCode) == 'tw') {
return array_filter($items, function($v){
return array_search($v['id'], ['18','33','41','42']) === FALSE;
return array_search($v['id'], ['18','33','37','38','41','42']) === FALSE;
});
}
return $items;
}


function categorieslist($id){
$data=array(
'1' => '电影和动画',
'2' => '汽车',
'10' => '音乐',
'15' => '宠物和动物',
'17' => '体育',
'18' => '短片',
'19' => '旅游和活动',
'20' => '游戏',
'21' => '视频博客',
'22' => '人物和博客',
'23' => '喜剧',
'24' => '娱乐',
'25' => '新闻和政治',
'26' => 'DIY 和生活百科',
'27' => '教育',
'28' => '科学和技术',
'30' => '电影',
'31' => '动漫/动画',
'32' => '动作/冒险',
'33' => '经典',
'34' => '喜剧',
'35' => '纪录片',
'36' => '剧情片',
'37' => '家庭片',
'38' => '外国',
'39' => '恐怖片',
'40' => '科幻/幻想',
'41' => '惊悚片',
'42' => '短片',
'43' => '节目',
'44' => '预告片'
);
if($id=='all'){
return $data;
}else{
return $data[$id];
}
$categories = videoCategories();
$data = array();
foreach ($categories as $k => $v) {
$data[$v['id']] = $v['snippet']['title'];
}

if($id=='all'){
return $data;
}else{
return $data[$id];
}
}

//获取视频类别内容
function Categories($id,$apikey,$pageToken='',$order='relevance',$regionCode='VN'){
$apilink='https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&&regionCode='.$regionCode.'&hl=zh-ZH&maxResults=48&videoCategoryId='.$id.'&key='.$apikey.'&order='.$order.'&pageToken='.$pageToken;
Expand Down

0 comments on commit a64774b

Please sign in to comment.