Skip to content

Commit 6e3fd71

Browse files
committed
Remove hard code categories
1 parent e2e8e82 commit 6e3fd71

File tree

2 files changed

+14
-41
lines changed

2 files changed

+14
-41
lines changed

ajax/ajax.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
}
151151
break;
152152
case 'menu':
153-
$vica=videoCategories(APIKEY,GJ_CODE);
153+
$vica=videoCategories();
154154

155155
echo '<ul class="list-group text-dark">
156156
<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>

lib.php

+13-40
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function get_channel_video($cid,$pageToken='',$apikey,$regionCode='VN'){
5959
}
6060

6161
//获取视频类别内容
62-
function videoCategories($apikey,$regionCode='HK'){
62+
function videoCategories($apikey=APIKEY,$regionCode=GJ_CODE){
6363
$apicache = '/tmp/ytb_videoCategories_'.$regionCode;
6464
$json = file_get_contents($apicache);
6565
if (empty($json)) {
@@ -78,47 +78,20 @@ function videoCategories($apikey,$regionCode='HK'){
7878
return $items;
7979
}
8080

81-
8281
function categorieslist($id){
83-
$data=array(
84-
'1' => '电影和动画',
85-
'2' => '汽车',
86-
'10' => '音乐',
87-
'15' => '宠物和动物',
88-
'17' => '体育',
89-
'18' => '短片',
90-
'19' => '旅游和活动',
91-
'20' => '游戏',
92-
'21' => '视频博客',
93-
'22' => '人物和博客',
94-
'23' => '喜剧',
95-
'24' => '娱乐',
96-
'25' => '新闻和政治',
97-
'26' => 'DIY 和生活百科',
98-
'27' => '教育',
99-
'28' => '科学和技术',
100-
'30' => '电影',
101-
'31' => '动漫/动画',
102-
'32' => '动作/冒险',
103-
'33' => '经典',
104-
'34' => '喜剧',
105-
'35' => '纪录片',
106-
'36' => '剧情片',
107-
'37' => '家庭片',
108-
'38' => '外国',
109-
'39' => '恐怖片',
110-
'40' => '科幻/幻想',
111-
'41' => '惊悚片',
112-
'42' => '短片',
113-
'43' => '节目',
114-
'44' => '预告片'
115-
);
116-
if($id=='all'){
117-
return $data;
118-
}else{
119-
return $data[$id];
120-
}
82+
$categories = videoCategories();
83+
$data = array();
84+
foreach ($categories as $k => $v) {
85+
$data[$v['id']] = $v['snippet']['title'];
86+
}
87+
88+
if($id=='all'){
89+
return $data;
90+
}else{
91+
return $data[$id];
92+
}
12193
}
94+
12295
//获取视频类别内容
12396
function Categories($id,$apikey,$pageToken='',$order='relevance',$regionCode='VN'){
12497
$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;

0 commit comments

Comments
 (0)