mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
handle PT-Gen and imdb update fail
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -139,7 +139,7 @@ else {
|
||||
{
|
||||
$thenumbers = $imdb_id;
|
||||
if (!$moviename = $Cache->get_value('imdb_id_'.$thenumbers.'_movie_name')){
|
||||
switch ($imdb->getCacheStatus($imdb_id, 'Title')){
|
||||
switch ($imdb->getCacheStatus($imdb_id)){
|
||||
case "1":{
|
||||
$moviename = $movie->title (); break;
|
||||
$Cache->cache_value('imdb_id_'.$thenumbers.'_movie_name', $moviename, 1296000);
|
||||
@@ -172,7 +172,7 @@ else {
|
||||
|
||||
$Cache->new_page('imdb_id_'.$thenumbers.'_large', 1296000, true);
|
||||
if (!$Cache->get_page()){
|
||||
switch ($imdb->getCacheStatus($imdb_id, 'Title'))
|
||||
switch ($imdb->getCacheStatus($imdb_id))
|
||||
{
|
||||
case "0" : //cache is not ready, try to
|
||||
{
|
||||
@@ -191,7 +191,7 @@ else {
|
||||
$smallth = "<img src=\"pic/nophoto.gif\" alt=\"no poster\" />";
|
||||
|
||||
$autodata = $imdb->renderDetailsPageDescription($row['id'], $imdb_id);
|
||||
$cache_time = $imdb->getCachedAt($imdb_id, 'Title');
|
||||
$cache_time = $imdb->getCachedAt($imdb_id);
|
||||
$Cache->add_whole_row();
|
||||
print("<tr>");
|
||||
print("<td class=\"rowhead\"><a href=\"javascript: klappe_ext('imdb')\"><span class=\"nowrap\"><img class=\"minus\" src=\"pic/trans.gif\" alt=\"Show/Hide\" id=\"picimdb\" title=\"".$lang_details['title_show_or_hide']."\" /> ".$lang_details['text_imdb'] . $lang_details['row_info'] ."</span></a><div id=\"posterimdb\">". $smallth."</div></td>");
|
||||
|
||||
@@ -27,15 +27,20 @@ switch ($siteid)
|
||||
{
|
||||
$thenumbers = $imdb_id;
|
||||
$imdb = new \Nexus\Imdb\Imdb();
|
||||
$movie = $imdb->getMovie($imdb_id);
|
||||
$movieid = $thenumbers;
|
||||
$target = array('Title', 'Credits', 'Plot');
|
||||
($type == 2 ? $imdb->purgeSingle($imdb_id) : "");
|
||||
set_cachetimestamp($id,"cache_stamp");
|
||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_movie_name');
|
||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_large', true);
|
||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_median', true);
|
||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_minor', true);
|
||||
|
||||
$imdb->purgeSingle($imdb_id);
|
||||
|
||||
try {
|
||||
$imdb->updateCache($imdb_id);
|
||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_movie_name');
|
||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_large', true);
|
||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_median', true);
|
||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_minor', true);
|
||||
} catch (\Exception $e) {
|
||||
$log = $e->getMessage() . ", trace: " . $e->getTraceAsString();
|
||||
do_log($log, 'error');
|
||||
}
|
||||
header("Location: " . get_protocol_prefix() . "$BASEURL/details.php?id=".htmlspecialchars($id));
|
||||
}
|
||||
break;
|
||||
@@ -47,9 +52,14 @@ switch ($siteid)
|
||||
$ptGenInfo = json_decode($row['pt_gen'], true);
|
||||
$link = $ptGenInfo[$siteid]['link'];
|
||||
$ptGen = new \Nexus\PTGen\PTGen();
|
||||
$result = $ptGen->generate($link, true);
|
||||
$ptGenInfo[$siteid]['data'] = $result;
|
||||
sql_query(sprintf("update torrents set pt_gen = %s where id = %s", sqlesc(json_encode($ptGenInfo)), $id)) or sqlerr(__FILE__, __LINE__);
|
||||
try {
|
||||
$result = $ptGen->generate($link, true);
|
||||
$ptGenInfo[$siteid]['data'] = $result;
|
||||
sql_query(sprintf("update torrents set pt_gen = %s where id = %s", sqlesc(json_encode($ptGenInfo)), $id)) or sqlerr(__FILE__, __LINE__);
|
||||
} catch (\Exception $e) {
|
||||
$log = $e->getMessage() . ", trace: " . $e->getTraceAsString();
|
||||
do_log($log, 'error');
|
||||
}
|
||||
header("Location: " . get_protocol_prefix() . "$BASEURL/details.php?id=".htmlspecialchars($id));
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user