Skip to content

Commit

Permalink
添加:影片点击量记录
Browse files Browse the repository at this point in the history
修改:载入界面尺寸
  • Loading branch information
lifankohome committed Feb 13, 2018
1 parent ddc4f08 commit 8abaa7a
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 47 deletions.
10 changes: 6 additions & 4 deletions Cinema/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* Date: 2017/12/6
* Time: 13:12
*/

namespace Cinema;

include_once('Spider.php');

class Common
{
public static function getHeader(){
$defaultSearch = Spider::searchHistory(1);
public static function getHeader()
{
$defaultSearch = Spider::getHistory(1);

return $header = "<ul>
<li><a href='http://hpu.lifanko.cn'>首页</a></li>
Expand All @@ -25,11 +27,11 @@ public static function getHeader(){
</ul>";
}

public static $footer = "<p style='font-size: 12px;color: #555'>&copy; Copyright lifanko 2017 December</p>";

public static $QQGroup = "<p style='text-align: center;font-size: 12px;background: #eee;padding: 6px 2px;border-radius: 2px;'>
<a style='color: black'
href='http://shang.qq.com/wpa/qunwpa?idkey=7d555df15dae8e5f29839bc474b172953f5ac15f3018f7e4607454dae583bd9d'
target='_blank'>点击加入【意见建议】&【问题反馈】&【爬虫技术】交流群:567051081</a>
</p>";

public static $footer = "<p style='font-size: 12px;color: #555'>Copyright &copy; <a href='http://hpu.lifanko.cn' style='font-size: 12px;color: #333'>lifanko</a> 2017-2018 豫ICP备16040860号-1</p>";
}
38 changes: 32 additions & 6 deletions Cinema/Spider.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,16 @@ public static function saveInfo($dir, $new = '')

if (file_exists($filePath)) {
if (empty($new)) { //$new为空时是读取状态,不为空时为写入状态
$fp = fopen($filePath, "r");
$str = fread($fp, filesize($filePath)); //指定读取大小,这里把整个文件内容读取出来
fclose($fp);
//文件不为空时返回文件内容,为空时返回json格式的空
if(filesize($filePath)){
$fp = fopen($filePath, "r");
$fJson = fread($fp, filesize($filePath)); //指定读取大小,这里把整个文件内容读取出来
fclose($fp);
}else{
$fJson = '{}';
}

return $str;
return $fJson;
} else {
$fp = fopen($filePath, "w");
flock($fp, LOCK_EX);
Expand All @@ -277,12 +282,13 @@ public static function saveInfo($dir, $new = '')
return true;
}
}

return false;
}

public static function searchHistory($max = 10)
public static function getHistory($max = 10, $dir = 'searchHistory')
{
$jsonHotSearch = self::saveInfo('searchHistory');
$jsonHotSearch = self::saveInfo($dir);

if (!empty($jsonHotSearch)) {
$arrHotSearch = json_decode($jsonHotSearch, true); //解析为数组格式
Expand Down Expand Up @@ -311,6 +317,26 @@ public static function searchHistory($max = 10)
return '';
}

public static function clickRec($dir, $name){
$jsonRes = self::saveInfo($dir);

if (!empty($jsonRes)) {
$arrRes = json_decode($jsonRes, true); //解析为数组格式
if (array_key_exists($name, $arrRes)) { //有记录则加一
$arrRes[$name] += 1;
} else { //无记录则在数组中创建
$arrRes[$name] = 1;
}

$jsonRes = json_encode($arrRes);
} else { //文件为空
$arrRes = [$name => 1];
$jsonRes = json_encode($arrRes);
}

self::saveInfo($dir, $jsonRes);
}

public static $parser = "<div id=\"parsers\">
<button onclick=\"vParser('http://api.wlzhan.com/sudu/?url=')\">解析器一</button>
<button onclick=\"vParser('https://api.47ks.com/webcloud/?v=')\">解析器二</button>
Expand Down
Empty file added Cinema/clickHistory.txt
Empty file.
1 change: 0 additions & 1 deletion Cinema/defaultSearch.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
[]
1 change: 0 additions & 1 deletion Cinema/searchHistory.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
{"\u7231\u60c5\u516c\u5bd3":4,"\u6b4c\u624b":2,"\u5929\u5929\u5411\u4e0a":6,"\u5feb\u4e50\u5927\u672c\u8425":2,"\u7f8e\u4e3d\u7684\u5927\u811a":2,"\u7231\u60c5":1,"\u7231\u60c5\u516c\u5bd34":2,"\u7f8e\u4e3d\u7684\u5927":1,"\u7f8e\u4e3d":6}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ http://ali.lifanko.cn/video/
+ Auto Crawling & Update
+ Play History Memory
+ No Register / No Sign In / No AD
+ Search recommend / Search History
+ Windows & Linus Server Auto Fit
+ Search recommend / Search History / Click History
+ Windows & Linus Server Auto Suit

### Server
PHP7 + Apache/2.4.6 (CentOS)
Expand Down
15 changes: 12 additions & 3 deletions hotSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function __autoload($class)
include_once('Cinema/Common.php');
}

if (empty($_GET['max'])) { //显示的关键词数量,默认最多显示99个
$max = 99;
if (empty($_GET['max'])) { //显示的关键词数量,默认最多显示50个
$max = 50;
}
?>
<!DOCTYPE html>
Expand Down Expand Up @@ -90,7 +90,16 @@ function __autoload($class)
<div class="list">
<ul style="list-style: decimal">
<?php
Spider::searchHistory($max);
Spider::getHistory($max);
?>
</ul>
</div>
<div style="clear: both"></div>
<h3>点击量排行榜:</h3>
<div class="list">
<ul style="list-style: decimal">
<?php
Spider::getHistory($max, 'clickHistory');
?>
</ul>
</div>
Expand Down
34 changes: 6 additions & 28 deletions loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,11 @@
</style>
</head>
<body>
<p><img src="img/logo.png" style="height: 200px"></p>
<h3>影视爬虫
<script type="text/javascript">
(function(){
var p = {
url:'http://ali.lifanko.cn/video/', /*获取URL,可加上来自分享到QQ标识,方便统计*/
desc:'', /*分享理由(风格应模拟用户对话),支持多分享语随机展现(使用|分隔)*/
title:'影视爬虫', /*分享标题(可选)*/
summary:'影视爬虫,VIP观影等您体验,走过路过,千万别错过', /*分享摘要(可选)*/
site:'影视爬虫,VIP观影等您体验', /*分享来源(可选) 如:QQ分享*/
style:'102',
width:63,
height:24
};
var s = [];
for(var i in p){
s.push(i + '=' + encodeURIComponent(p[i]||''));
}
document.write(['<a class="qcShareQQDiv" href="http://connect.qq.com/widget/shareqq/index.html?',s.join('&'),'" target="_blank">分享到QQ</a>'].join(''));
})();
</script>
<script src="http://connect.qq.com/widget/loader/loader.js" widget="shareqq" charset="utf-8"></script></p>
</h3>
<br>
赞赏:<a href="https://github.com/lifankohome/video-spider" target="_blank" style="color: #F40">在GitHub上送我一颗小星星</a>
<br><br>
木然云:<a href="https://www.s6z.net/aff.php?aff=59" target="_blank" style="color: #F40">科学上网超稳定</a>
<p style="margin-top: 18%">点击左上方“立即播放”即可播放影片(如果播放不了可以试下不同的解析器)</p>
<p style="margin: 0"><img src="img/logo.png" style="height: 200px"></p>
<h2 style="margin: 0 0 3pc 0">影视爬虫<span style="font-size: 12px">(v2.2)</span></h2>
<p>广告:科学上网工具</p>
<p>木然云:<a href="https://www.s6z.net/aff.php?aff=59" target="_blank" style="color: #F40">超快超稳定(略贵,用了一段时间用不起了)</a></p>
<p>加速度:<a href="http://jiasd.us/4297" target="_blank" style="color: #F40">速度较慢但查资料足够,科学上网15天仅需¥2(推荐)</a></p>
<p style="margin-top: 10%">电影请点击左上方“立即播放”、电视剧选集后即可播放<br>(播放不了请尝试切换下方的解析器)</p>
</body>
</html>
6 changes: 6 additions & 0 deletions play.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ function __autoload($class)
if(empty($sets)){
echo '' . $name . '》—— 暂无播放资源';
}else{
//如果有播放资源,则点击量加一
Spider::clickRec('clickHistory', $name);

echo '' . $name . '》—— 总' . count($sets[3]) . '集<ul>';
foreach ($sets[3] as $key => $val) {
if ($varietyEpisode) {
Expand All @@ -165,6 +168,9 @@ function __autoload($class)
}

} else {
//如果有播放资源,则点击量加一
Spider::clickRec('clickHistory', $name);

echo $name . "——<a class='videoA' href='$link' target='ajax'>立即播放</a>";
}
?></h3>
Expand Down
4 changes: 2 additions & 2 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function __autoload($class)
$search = json_decode(Spider::saveInfo('defaultSearch'), true);

if (empty($search)) {
$search = Spider::search('老男孩');
$search = Spider::search('老男孩'); //默认搜索

//历史为空为初始化记录操作
Spider::recordSearch('老男孩', json_encode($search));
Expand All @@ -40,7 +40,7 @@ function __autoload($class)
$kw = $_GET['kw'];
$search = Spider::search($kw);

//默认搜索不统计流量
//不统计无效关键字
Spider::recordSearch($kw, json_encode($search));
}

Expand Down

0 comments on commit 8abaa7a

Please sign in to comment.