diff --git a/Cinema/Common.php b/Cinema/Common.php index 1c77e03..5d743c0 100644 --- a/Cinema/Common.php +++ b/Cinema/Common.php @@ -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 = "
© Copyright lifanko 2017 December
"; - public static $QQGroup = "点击加入【意见建议】&【问题反馈】&【爬虫技术】交流群:567051081
"; + + public static $footer = "Copyright © lifanko 2017-2018 豫ICP备16040860号-1
"; } \ No newline at end of file diff --git a/Cinema/Spider.php b/Cinema/Spider.php index c385bd9..05c1813 100644 --- a/Cinema/Spider.php +++ b/Cinema/Spider.php @@ -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); @@ -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); //解析为数组格式 @@ -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 = "点击左上方“立即播放”即可播放影片(如果播放不了可以试下不同的解析器)
+ +广告:科学上网工具
+ +加速度:速度较慢但查资料足够,科学上网15天仅需¥2(推荐)
+电影请点击左上方“立即播放”、电视剧选集后即可播放
(播放不了请尝试切换下方的解析器)