mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-26 13:27:22 +08:00
handle PT-Gen and imdb update fail
This commit is contained in:
+30
-14
@@ -11,7 +11,7 @@ class Imdb
|
||||
|
||||
private $movie;
|
||||
|
||||
private $pages = array('Title', 'Credits', 'Amazon', 'Goofs', 'Plot', 'Comments', 'Quotes', 'Taglines', 'Plotoutline', 'Trivia', 'Directed');
|
||||
private $pages = array('Title', 'Credits', 'ReleaseInfo', );
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -47,16 +47,16 @@ class Imdb
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getCachedAt(int $id, string $page)
|
||||
public function getCachedAt(int $id)
|
||||
{
|
||||
$id = parse_imdb_id($id);
|
||||
$log = "id: $id, page: $page";
|
||||
$cacheFile = $this->getCacheFilePath($id, $page);
|
||||
$log = "id: $id";
|
||||
$cacheFile = $this->getCacheFilePath($id);
|
||||
if (!file_exists($cacheFile)) {
|
||||
$log .= ", file: $cacheFile not exits";
|
||||
}
|
||||
$result = filemtime($cacheFile);
|
||||
$log .= ", cache at: $result";
|
||||
$log .= ", file: $cacheFile cache at: $result";
|
||||
do_log($log);
|
||||
return $result;
|
||||
}
|
||||
@@ -64,15 +64,13 @@ class Imdb
|
||||
/**
|
||||
* @date 2021/1/18
|
||||
* @param int $id
|
||||
* @param string $page Title, Credits, etc...
|
||||
* @return int state (0-not complete, 1-cache complete)
|
||||
*/
|
||||
public function getCacheStatus(int $id, string $page)
|
||||
public function getCacheStatus(int $id)
|
||||
{
|
||||
return 1;
|
||||
$id = parse_imdb_id($id);
|
||||
$log = "id: $id, page: $page";
|
||||
$cacheFile = $this->getCacheFilePath($id, $page);
|
||||
$log = "id: $id";
|
||||
$cacheFile = $this->getCacheFilePath($id);
|
||||
if (!file_exists($cacheFile)) {
|
||||
$log .= ", file: $cacheFile not exits";
|
||||
do_log($log);
|
||||
@@ -88,9 +86,10 @@ class Imdb
|
||||
|
||||
public function purgeSingle($id)
|
||||
{
|
||||
foreach ($this->pages as $page) {
|
||||
$file = $this->getCacheFilePath($id, $page);
|
||||
$mainCacheFile = $this->getCacheFilePath($id);
|
||||
foreach (glob("$mainCacheFile*") as $file) {
|
||||
if (file_exists($file)) {
|
||||
do_log("unlink: $file");
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
@@ -105,9 +104,26 @@ class Imdb
|
||||
return $this->movie;
|
||||
}
|
||||
|
||||
private function getCacheFilePath($id, $page)
|
||||
private function getCacheFilePath($id, $suffix = '')
|
||||
{
|
||||
return sprintf('%s%s.%s', $this->config->cachedir, $id, $page);
|
||||
$id = parse_imdb_id($id);
|
||||
$result = sprintf('%stitle.tt%s', $this->config->cachedir, $id);
|
||||
if ($suffix) {
|
||||
$result .= ".$suffix";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function updateCache($id)
|
||||
{
|
||||
$id = parse_imdb_id($id);
|
||||
$movie = $this->getMovie($id);
|
||||
//because getPate() is protected, so...
|
||||
$movie->title();
|
||||
$movie->photo_localurl();
|
||||
$movie->releaseInfo();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function renderDetailsPageDescription($torrentId, $imdbId)
|
||||
|
||||
+21
-7
@@ -77,12 +77,16 @@ class PTGen
|
||||
{
|
||||
global $lang_details;
|
||||
$ptGenFormatted = $ptGenArr['format'];
|
||||
$prefix = sprintf("[img]%s[/img]\n", $ptGenArr['poster']);
|
||||
$ptGenFormatted = mb_substr($ptGenFormatted, mb_strlen($prefix, 'utf-8') + 1);
|
||||
$poster = '';
|
||||
if (!empty($ptGenArr['poster'])) {
|
||||
$poster = $ptGenArr['poster'];
|
||||
$prefix = sprintf("[img]%s[/img]\n", $poster);
|
||||
$ptGenFormatted = mb_substr($ptGenFormatted, mb_strlen($prefix, 'utf-8') + 1);
|
||||
}
|
||||
$ptGenFormatted = format_comment($ptGenFormatted);
|
||||
$ptGenFormatted .= sprintf(
|
||||
'%s%s%s<a href="retriver.php?id=%s&type=1&siteid=%s">%s</a>',
|
||||
$lang_details['text_information_updated_at'], date('Y-m-d H:i:s', intval($ptGenArr['generate_at'] / 1000)), $lang_details['text_might_be_outdated'],
|
||||
$lang_details['text_information_updated_at'], !empty($ptGenArr['generate_at']) ? date('Y-m-d H:i:s', intval($ptGenArr['generate_at'] / 1000)) : '', $lang_details['text_might_be_outdated'],
|
||||
$torrentId, $site, $lang_details['text_here_to_update']
|
||||
);
|
||||
$titleShowOrHide = $lang_details['title_show_or_hide'] ?? '';
|
||||
@@ -97,7 +101,7 @@ class PTGen
|
||||
</span>
|
||||
</a>
|
||||
<div id="poster{$id}">
|
||||
<img src="{$ptGenArr['poster']}" width="105" onclick="Preview(this);" alt="poster" />
|
||||
<img src="{$poster}" width="105" onclick="Preview(this);" alt="poster" />
|
||||
</div>
|
||||
</td>
|
||||
<td class="rowfollow" align="left">
|
||||
@@ -113,6 +117,7 @@ HTML;
|
||||
private function request(string $url, bool $withoutCache = false): array
|
||||
{
|
||||
global $Cache;
|
||||
$begin = microtime(true);
|
||||
$logPrefix = "url: $url";
|
||||
$cacheKey = $this->getApiPointResultCacheKey($url);
|
||||
if (!$withoutCache) {
|
||||
@@ -123,7 +128,7 @@ HTML;
|
||||
}
|
||||
}
|
||||
$http = new Client();
|
||||
$response = $http->get($url, ['timeout' => 10]);
|
||||
$response = $http->get($url, ['timeout' => 5]);
|
||||
$statusCode = $response->getStatusCode();
|
||||
if ($statusCode != 200) {
|
||||
$msg = "api point response http status code: $statusCode";
|
||||
@@ -148,7 +153,7 @@ HTML;
|
||||
throw new PTGenException($msg);
|
||||
}
|
||||
$Cache->cache_value($cacheKey, $bodyArr, 24 * 3600);
|
||||
do_log("$logPrefix, success get from api point");
|
||||
do_log("$logPrefix, success get from api point, use time: " . (microtime(true) - $begin));
|
||||
return $bodyArr;
|
||||
}
|
||||
|
||||
@@ -195,7 +200,16 @@ HTML;
|
||||
];
|
||||
$html .= $this->buildDetailsPageTableRow($torrentId, $data, $site);
|
||||
} else {
|
||||
$ptGenArr = $this->generate($torrentPtGenArr[$site]['link']);
|
||||
try {
|
||||
$ptGenArr = $this->generate($torrentPtGenArr[$site]['link']);
|
||||
} catch (\Exception $e) {
|
||||
$log = $e->getMessage() . ", trace: " . $e->getTraceAsString();
|
||||
do_log($log,'error');
|
||||
$ptGenArr = [
|
||||
'format' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
|
||||
$jsonArr[$site] = [
|
||||
'link' => $link,
|
||||
'data' => $ptGenArr,
|
||||
|
||||
Reference in New Issue
Block a user