-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbilibilifollow.php
311 lines (284 loc) · 14.9 KB
/
bilibilifollow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
/**
* B站追番列表
*
* @version:2.5.0
* @author AyagawaSeirin
* https://github.com/AyagawaSeirin/BilibiliFollowPage
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$bilibiliUser = $this->fields->BilibiliUid;
$cacheTime = $this->fields->CacheTime;
$amout = $this->fields->Amout;
$hideMedia = $this->fields->HideMedia;
$lazyload = $this->fields->lazyload;
$cdnurl = $this->fields->cdnurl;
error_reporting(E_ALL ^ E_NOTICE);
if ($bilibiliUser == "" || $bilibiliUser == null) {
$bilibiliUser = '174471710';
}
if ($cacheTime == "" || $cacheTime == null) $cacheTime = 86400;
if ($amout == "" || $amout == null || $amout > 100) $amout = 100;
/**
* 作为异步接口时的操作
*/
if (isset($_POST['post']) == true && $_POST['post'] == '1') {
$dirPath = __DIR__ . '/assets/cache/BilibiliFollow';
$filePath = $dirPath . '/BilibiliFollow.json';
//检测缓存目录是否存在,不存在则创建
if (is_dir($dirPath) == false) {
mkdir($dirPath, 0777, true);
$update = true;
}
//检测缓存文件是否存在,不存在则创建
if (file_exists($filePath) == false) {
fopen($filePath, "w");
$update = true;
}
//若初步检查就要更新文件,则直接返回更新程序返回的缓存内容
if ($update == true) {
echo updateDate($bilibiliUser, $cacheTime, $amout,$hideMedia);
return;
}
//读取缓存文件
$fileCache = fopen($filePath, "r");
$contents = fread($fileCache, filesize($filePath));
fclose($fileCache);
$data = json_decode($contents, true);
if (time() - $data['time'] > $cacheTime || $data['BilibiliUid'] != $bilibiliUser || $data['amout'] != $amout) {
//缓存过期或B站UID更新或输出数量更新
echo updateDate($bilibiliUser, $cacheTime, $amout,$hideMedia);
return;
}
echo $contents;
return;
}
/**
* 更新缓存数据
* @param $userID
* @param $cacheTime
* @param $amout
* @return mixed
*/
function updateDate($userID, $cacheTime, $amout,$hideMedia)
{
$dirPath = __DIR__ . '/assets/cache/BilibiliFollow';
$filePath = $dirPath . '/BilibiliFollow.json';
//执行更新程序的前提是缓存数据文件都已经存在了
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.bilibili.com/x/space/bangumi/follow/list?type=1&follow_status=0&pn=1&ps=" . $amout . "&ts=" . rand(9999999, 99999999) . "&vmid=" . $userID);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Origin: https://space.bilibili.com","Referer: https://space.bilibili.com/".$userID."/bangumi"));
$output = curl_exec($ch);
curl_close($ch);
$hideMedia = explode(",",$hideMedia);
$data = json_decode($output, true);
$i = 0;
//开始苦逼的缓存图片
foreach ($data['data']['list'] as $value) {
$imgUrl = $value['cover'];
$imgPath = $dirPath.'/'.$value['media_id'].'.jpg';
if (file_exists($imgPath) == false) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_URL,$imgUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Origin: https://space.bilibili.com","Referer: https://space.bilibili.com/".$userID."/bangumi"));
$file_content = curl_exec($ch);
curl_close($ch);
$img_file = fopen($imgPath, 'w');
fwrite($img_file, $file_content);
fclose($img_file);
}
if(in_array($value['media_id'],$hideMedia)){
$display = '0';
} else {
$display = '1';
}
$data['data']['list'][$i]['display'] = $display;
$i++;
}
$data['time'] = time();
$data['BilibiliUid'] = $userID;
$data['amout'] = $amout;
$data = json_encode($data);
$file = fopen($filePath, "w");
fwrite($file, $data);
fclose($file);
return $data;
}
?>
<?php $this->need('component/header.php'); ?>
<?php if($lazyload == "1"):?>
<script src="https://cdn.bootcss.com/lazyloadjs/3.2.2/lazyload.min.js"></script>
<?php endif; ?>
<!-- aside -->
<?php $this->need('component/aside.php'); ?>
<!-- / aside -->
<!-- <div id="content" class="app-content"> -->
<a class="off-screen-toggle hide"></a>
<main class="app-content-body <?php Content::returnPageAnimateClass($this); ?>">
<div class="hbox hbox-auto-xs hbox-auto-sm">
<!--文章-->
<div class="col center-part">
<div class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3"><i class="iconfont icon-fork i-sm m-r-sm"></i><?php _me("追番列表") ?></h1>
<div class="entry-meta text-muted m-b-none small post-head-icon"><?php echo $this->fields->intro; ?></div>
</div>
<div class="wrapper-md" id="post-panel">
<!--博客文章样式 begin with .blog-post-->
<div id="postpage" class="blog-post">
<article class="panel">
<!--文章页面的头图-->
<?php echo Content::exportHeaderImg($this); ?>
<!--文章内容-->
<div id="post-content" class="wrapper-lg">
<div class="seirin-bilibili-follow-panel-all">
<style>
.wrapper-lg {
padding: 10px !important;
}
.seirin-bilibili-follow-panel {
padding: 0 !important;
}
.seirin-bilibili-follow-img {
width: 95%;
max-width: 140px !important;
margin: 0 !important;
padding: 0 !important;
}
.seirin-bilibili-follow-img-dad{
max-width: 145px !important;
}
.seirin-bilibili-follow-title {
font-weight: 400;
line-height: 24px;
font-size: 22px;
margin-bottom: 5px !important;
margin-top: 2px !important;
}
.seirin-bilibili-follow-text {
margin-bottom: 10px !important;
}
.seirin-bilibili-follow-info {
font-size: 12px;
margin-bottom: 0 !important;
}
.seirin-bilibili-follow-content{
padding-top:15px;
padding-right: 20px;
padding-left:10px;
padding-bottom:15px;
}
.seirin-bilibili-follow-panel-big{
margin-bottom: 10px;
}
@media screen and (max-width:991px) {
.seirin-bilibili-follow-content{
padding-left:25px!important;
}
.seirin-bilibili-follow-img {
display:none;
}
.seirin-bilibili-follow-content {
padding-top:10px;
}
}
</style>
<!--
B站追番列表
@version:2.5.0
@author AyagawaSeirin
https://github.com/AyagawaSeirin/BilibiliFollowPage
https://qwq.best/dev/84.html
-->
<div class="seirin-bilibili-page">
<nav class="loading-nav text-center m-t-lg m-b-lg">
<p class="infinite-scroll-request"><i class="animate-spin fontello
fontello-refresh"></i><?php _me("正在加载,请稍后") ?></p>
</nav>
<nav class="error-nav hide text-center m-t-lg m-b-lg">
<p class="infinite-scroll-request"><i class="glyphicon
glyphicon-refresh"></i>加载失败!请刷新再试~</p>
</nav>
</div>
<script type="text/javascript">
console.log("\n %c BilibiliFollowPage v2.5.0 %c by AyagawaSeirin | qwq.best ","color:#444;background:#eee;padding:5px 0;","color:#F8F8FF;background:#F4A7B9;padding:5px 0;");
console.log(" BilibiliFollowPage : https://qwq.best/dev/84.html\n\n");
var bilibiliItemTemple = '<div class="panel panel-default seirin-bilibili-follow-panel-big">'+
'<div class="panel-body seirin-bilibili-follow-panel">'+
' <div class="row">'+
' <div class="col-md-3 seirin-bilibili-follow-img-dad" style="padding-right:2px;">'+
' <img id="img" <?=($lazyload == "1") ? 'data-original' : 'src';?>="<?=($cdnurl == null) ? '//'.$_SERVER['SERVER_NAME'].'/usr/themes/handsome/assets/cache/BilibiliFollow' : $cdnurl;?>/{media_id}.jpg" alt="{title}" class="seirin-bilibili-follow-img<?=($lazyload == "1") ? ' lazy' : null;?>">'+
' </div>'+
' <a href="https://www.bilibili.com/bangumi/media/md{media_id}" target="_blank"><div class="col-md-9 seirin-bilibili-follow-content">'+
' <p class="seirin-bilibili-follow-title">{title}</p>'+
' <p class="seirin-bilibili-follow-text">{evaluate}</p>'+
' <p class="seirin-bilibili-follow-info">{season_type_name} | {areas_0_name} | {new_ep_index_show}</p>'+
' </div></a>'+
' </div>'+
'</div>'+
'</div>';
var open = function(){
var devContainer = $('.seirin-bilibili-page');
var loadingContainer = devContainer.find(".loading-nav");
var errorContainer = devContainer.find(".error-nav");
$.ajax({
url: "<?=$_SERVER['REQUEST_URI']?>",
async: true,
type: 'POST',
data: 'post=1',
dataType: 'json',
success: function (data) {
loadingContainer.addClass("hide");
var list = data['data']['list'];
for(var i in list){
var now = list[i];
if(now['display'] == '1') {
//匹配替换
var item = bilibiliItemTemple.replace("{title}", now['title']).replace("{title}", now['title'])
.replace("{media_id}", now['media_id'])
.replace("{media_id}", now['media_id'])
.replace("{evaluate}", now['evaluate'])
.replace("{season_type_name}", now['season_type_name'])
.replace("{areas_0_name}", now['areas'][0]['name'])
.replace("{new_ep_index_show}", now['new_ep']['index_show']);
devContainer.append(item);
}
}
},
error:function () {
loadingContainer.addClass("hide");
errorContainer.removeClass("hide");
}
});
};
open();
</script>
<?php if($lazyload == "1"):?>
<script type="text/javascript" charset="utf-8">
$(function() {
$("img.lazy").lazyload({ threshold :180});
});
</script>
<?php endif; ?>
<?php echo Content::postContent($this, $this->user->hasLogin()); ?>
</div>
</div>
</article>
</div>
<!--评论-->
<?php $this->need('component/comments.php') ?>
</div>
</div>
<!--文章右侧边栏开始-->
<?php $this->need('component/sidebar.php'); ?>
<!--文章右侧边栏结束-->
</div>
</main>
<!-- footer -->
<?php $this->need('component/footer.php'); ?>
<!-- / footer -->