mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 20:17:24 +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 $movie;
|
||||||
|
|
||||||
private $pages = array('Title', 'Credits', 'Amazon', 'Goofs', 'Plot', 'Comments', 'Quotes', 'Taglines', 'Plotoutline', 'Trivia', 'Directed');
|
private $pages = array('Title', 'Credits', 'ReleaseInfo', );
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -47,16 +47,16 @@ class Imdb
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCachedAt(int $id, string $page)
|
public function getCachedAt(int $id)
|
||||||
{
|
{
|
||||||
$id = parse_imdb_id($id);
|
$id = parse_imdb_id($id);
|
||||||
$log = "id: $id, page: $page";
|
$log = "id: $id";
|
||||||
$cacheFile = $this->getCacheFilePath($id, $page);
|
$cacheFile = $this->getCacheFilePath($id);
|
||||||
if (!file_exists($cacheFile)) {
|
if (!file_exists($cacheFile)) {
|
||||||
$log .= ", file: $cacheFile not exits";
|
$log .= ", file: $cacheFile not exits";
|
||||||
}
|
}
|
||||||
$result = filemtime($cacheFile);
|
$result = filemtime($cacheFile);
|
||||||
$log .= ", cache at: $result";
|
$log .= ", file: $cacheFile cache at: $result";
|
||||||
do_log($log);
|
do_log($log);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@@ -64,15 +64,13 @@ class Imdb
|
|||||||
/**
|
/**
|
||||||
* @date 2021/1/18
|
* @date 2021/1/18
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @param string $page Title, Credits, etc...
|
|
||||||
* @return int state (0-not complete, 1-cache complete)
|
* @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);
|
$id = parse_imdb_id($id);
|
||||||
$log = "id: $id, page: $page";
|
$log = "id: $id";
|
||||||
$cacheFile = $this->getCacheFilePath($id, $page);
|
$cacheFile = $this->getCacheFilePath($id);
|
||||||
if (!file_exists($cacheFile)) {
|
if (!file_exists($cacheFile)) {
|
||||||
$log .= ", file: $cacheFile not exits";
|
$log .= ", file: $cacheFile not exits";
|
||||||
do_log($log);
|
do_log($log);
|
||||||
@@ -88,9 +86,10 @@ class Imdb
|
|||||||
|
|
||||||
public function purgeSingle($id)
|
public function purgeSingle($id)
|
||||||
{
|
{
|
||||||
foreach ($this->pages as $page) {
|
$mainCacheFile = $this->getCacheFilePath($id);
|
||||||
$file = $this->getCacheFilePath($id, $page);
|
foreach (glob("$mainCacheFile*") as $file) {
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
|
do_log("unlink: $file");
|
||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,9 +104,26 @@ class Imdb
|
|||||||
return $this->movie;
|
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)
|
public function renderDetailsPageDescription($torrentId, $imdbId)
|
||||||
|
|||||||
+21
-7
@@ -77,12 +77,16 @@ class PTGen
|
|||||||
{
|
{
|
||||||
global $lang_details;
|
global $lang_details;
|
||||||
$ptGenFormatted = $ptGenArr['format'];
|
$ptGenFormatted = $ptGenArr['format'];
|
||||||
$prefix = sprintf("[img]%s[/img]\n", $ptGenArr['poster']);
|
$poster = '';
|
||||||
$ptGenFormatted = mb_substr($ptGenFormatted, mb_strlen($prefix, 'utf-8') + 1);
|
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 = format_comment($ptGenFormatted);
|
||||||
$ptGenFormatted .= sprintf(
|
$ptGenFormatted .= sprintf(
|
||||||
'%s%s%s<a href="retriver.php?id=%s&type=1&siteid=%s">%s</a>',
|
'%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']
|
$torrentId, $site, $lang_details['text_here_to_update']
|
||||||
);
|
);
|
||||||
$titleShowOrHide = $lang_details['title_show_or_hide'] ?? '';
|
$titleShowOrHide = $lang_details['title_show_or_hide'] ?? '';
|
||||||
@@ -97,7 +101,7 @@ class PTGen
|
|||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
<div id="poster{$id}">
|
<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>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="rowfollow" align="left">
|
<td class="rowfollow" align="left">
|
||||||
@@ -113,6 +117,7 @@ HTML;
|
|||||||
private function request(string $url, bool $withoutCache = false): array
|
private function request(string $url, bool $withoutCache = false): array
|
||||||
{
|
{
|
||||||
global $Cache;
|
global $Cache;
|
||||||
|
$begin = microtime(true);
|
||||||
$logPrefix = "url: $url";
|
$logPrefix = "url: $url";
|
||||||
$cacheKey = $this->getApiPointResultCacheKey($url);
|
$cacheKey = $this->getApiPointResultCacheKey($url);
|
||||||
if (!$withoutCache) {
|
if (!$withoutCache) {
|
||||||
@@ -123,7 +128,7 @@ HTML;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$http = new Client();
|
$http = new Client();
|
||||||
$response = $http->get($url, ['timeout' => 10]);
|
$response = $http->get($url, ['timeout' => 5]);
|
||||||
$statusCode = $response->getStatusCode();
|
$statusCode = $response->getStatusCode();
|
||||||
if ($statusCode != 200) {
|
if ($statusCode != 200) {
|
||||||
$msg = "api point response http status code: $statusCode";
|
$msg = "api point response http status code: $statusCode";
|
||||||
@@ -148,7 +153,7 @@ HTML;
|
|||||||
throw new PTGenException($msg);
|
throw new PTGenException($msg);
|
||||||
}
|
}
|
||||||
$Cache->cache_value($cacheKey, $bodyArr, 24 * 3600);
|
$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;
|
return $bodyArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +200,16 @@ HTML;
|
|||||||
];
|
];
|
||||||
$html .= $this->buildDetailsPageTableRow($torrentId, $data, $site);
|
$html .= $this->buildDetailsPageTableRow($torrentId, $data, $site);
|
||||||
} else {
|
} 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] = [
|
$jsonArr[$site] = [
|
||||||
'link' => $link,
|
'link' => $link,
|
||||||
'data' => $ptGenArr,
|
'data' => $ptGenArr,
|
||||||
|
|||||||
+3
-3
@@ -139,7 +139,7 @@ else {
|
|||||||
{
|
{
|
||||||
$thenumbers = $imdb_id;
|
$thenumbers = $imdb_id;
|
||||||
if (!$moviename = $Cache->get_value('imdb_id_'.$thenumbers.'_movie_name')){
|
if (!$moviename = $Cache->get_value('imdb_id_'.$thenumbers.'_movie_name')){
|
||||||
switch ($imdb->getCacheStatus($imdb_id, 'Title')){
|
switch ($imdb->getCacheStatus($imdb_id)){
|
||||||
case "1":{
|
case "1":{
|
||||||
$moviename = $movie->title (); break;
|
$moviename = $movie->title (); break;
|
||||||
$Cache->cache_value('imdb_id_'.$thenumbers.'_movie_name', $moviename, 1296000);
|
$Cache->cache_value('imdb_id_'.$thenumbers.'_movie_name', $moviename, 1296000);
|
||||||
@@ -172,7 +172,7 @@ else {
|
|||||||
|
|
||||||
$Cache->new_page('imdb_id_'.$thenumbers.'_large', 1296000, true);
|
$Cache->new_page('imdb_id_'.$thenumbers.'_large', 1296000, true);
|
||||||
if (!$Cache->get_page()){
|
if (!$Cache->get_page()){
|
||||||
switch ($imdb->getCacheStatus($imdb_id, 'Title'))
|
switch ($imdb->getCacheStatus($imdb_id))
|
||||||
{
|
{
|
||||||
case "0" : //cache is not ready, try to
|
case "0" : //cache is not ready, try to
|
||||||
{
|
{
|
||||||
@@ -191,7 +191,7 @@ else {
|
|||||||
$smallth = "<img src=\"pic/nophoto.gif\" alt=\"no poster\" />";
|
$smallth = "<img src=\"pic/nophoto.gif\" alt=\"no poster\" />";
|
||||||
|
|
||||||
$autodata = $imdb->renderDetailsPageDescription($row['id'], $imdb_id);
|
$autodata = $imdb->renderDetailsPageDescription($row['id'], $imdb_id);
|
||||||
$cache_time = $imdb->getCachedAt($imdb_id, 'Title');
|
$cache_time = $imdb->getCachedAt($imdb_id);
|
||||||
$Cache->add_whole_row();
|
$Cache->add_whole_row();
|
||||||
print("<tr>");
|
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>");
|
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>");
|
||||||
|
|||||||
+21
-11
@@ -27,15 +27,20 @@ switch ($siteid)
|
|||||||
{
|
{
|
||||||
$thenumbers = $imdb_id;
|
$thenumbers = $imdb_id;
|
||||||
$imdb = new \Nexus\Imdb\Imdb();
|
$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");
|
set_cachetimestamp($id,"cache_stamp");
|
||||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_movie_name');
|
|
||||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_large', true);
|
$imdb->purgeSingle($imdb_id);
|
||||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_median', true);
|
|
||||||
$Cache->delete_value('imdb_id_'.$thenumbers.'_minor', true);
|
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));
|
header("Location: " . get_protocol_prefix() . "$BASEURL/details.php?id=".htmlspecialchars($id));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -47,9 +52,14 @@ switch ($siteid)
|
|||||||
$ptGenInfo = json_decode($row['pt_gen'], true);
|
$ptGenInfo = json_decode($row['pt_gen'], true);
|
||||||
$link = $ptGenInfo[$siteid]['link'];
|
$link = $ptGenInfo[$siteid]['link'];
|
||||||
$ptGen = new \Nexus\PTGen\PTGen();
|
$ptGen = new \Nexus\PTGen\PTGen();
|
||||||
$result = $ptGen->generate($link, true);
|
try {
|
||||||
$ptGenInfo[$siteid]['data'] = $result;
|
$result = $ptGen->generate($link, true);
|
||||||
sql_query(sprintf("update torrents set pt_gen = %s where id = %s", sqlesc(json_encode($ptGenInfo)), $id)) or sqlerr(__FILE__, __LINE__);
|
$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));
|
header("Location: " . get_protocol_prefix() . "$BASEURL/details.php?id=".htmlspecialchars($id));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user