mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
refactor default imdb
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Nexus\Imdb;
|
||||
|
||||
use Imdb\Config;
|
||||
use Imdb\Title;
|
||||
|
||||
class Imdb
|
||||
{
|
||||
private $config;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$config = new Config();
|
||||
$config->cachedir = ROOT_PATH . 'imdb/cache';
|
||||
$config->photodir = ROOT_PATH . 'imdb/pic_imdb';
|
||||
$config->photoroot = 'pic_imdb';
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function renderDetailsPageDescription($torrentId, $imdbId)
|
||||
{
|
||||
$movie = new Title($imdbId, $this->config);
|
||||
$country = $movie->country ();
|
||||
$director = $movie->director();
|
||||
$creator = $movie->creator(); // For TV series
|
||||
$write = $movie->writing();
|
||||
$produce = $movie->producer();
|
||||
$cast = $movie->cast();
|
||||
// $plot = $movie->plot ();
|
||||
$plot_outline = $movie->plotoutline();
|
||||
$compose = $movie->composer();
|
||||
$gen = $movie->genres();
|
||||
//$comment = $movie->comment();
|
||||
$similiar_movies = $movie->similiar_movies();
|
||||
|
||||
if (($photo_url = $movie->photo_localurl() ) != FALSE)
|
||||
$smallth = "<img src=\"".$photo_url. "\" width=\"105\" onclick=\"Preview(this);\" alt=\"poster\" />";
|
||||
else
|
||||
$smallth = "<img src=\"pic/imdb_pic/nophoto.gif\" alt=\"no poster\" />";
|
||||
|
||||
$autodata = '<a href="https://www.imdb.com/title/tt'.$thenumbers.'">https://www.imdb.com/title/tt'.$thenumbers."</a><br /><strong><font color=\"navy\">------------------------------------------------------------------------------------------------------------------------------------</font><br />\n";
|
||||
$autodata .= "<font color=\"darkred\" size=\"3\">".$lang_details['text_information']."</font><br />\n";
|
||||
$autodata .= "<font color=\"navy\">------------------------------------------------------------------------------------------------------------------------------------</font></strong><br />\n";
|
||||
$autodata .= "<strong><font color=\"DarkRed\">". $lang_details['text_title']."</font></strong>" . "".$movie->title ()."<br />\n";
|
||||
$autodata .= "<strong><font color=\"DarkRed\">".$lang_details['text_also_known_as']."</font></strong>";
|
||||
|
||||
$temp = "";
|
||||
foreach ($movie->alsoknow() as $ak)
|
||||
{
|
||||
// $temp .= $ak["title"].$ak["year"]. ($ak["country"] != "" ? " (".$ak["country"].")" : "") . ($ak["comment"] != "" ? " (" . $ak["comment"] . ")" : "") . ", ";
|
||||
$temp .= $ak["title"] . ", ";
|
||||
}
|
||||
$autodata .= rtrim(trim($temp), ",");
|
||||
$runtimes = str_replace(" min",$lang_details['text_mins'], $movie->runtime_all());
|
||||
$autodata .= "<br />\n<strong><font color=\"DarkRed\">".$lang_details['text_year']."</font></strong>" . "".$movie->year ()."<br />\n";
|
||||
$autodata .= "<strong><font color=\"DarkRed\">".$lang_details['text_runtime']."</font></strong>".$runtimes."<br />\n";
|
||||
$autodata .= "<strong><font color=\"DarkRed\">".$lang_details['text_votes']."</font></strong>" . "".$movie->votes ()."<br />\n";
|
||||
$autodata .= "<strong><font color=\"DarkRed\">".$lang_details['text_rating']."</font></strong>" . "".$movie->rating ()."<br />\n";
|
||||
$autodata .= "<strong><font color=\"DarkRed\">".$lang_details['text_language']."</font></strong>" . "".$movie->language ()."<br />\n";
|
||||
$autodata .= "<strong><font color=\"DarkRed\">".$lang_details['text_country']."</font></strong>";
|
||||
|
||||
$temp = "";
|
||||
for ($i = 0; $i < count ($country); $i++)
|
||||
{
|
||||
$temp .="$country[$i], ";
|
||||
}
|
||||
$autodata .= rtrim(trim($temp), ",");
|
||||
|
||||
$autodata .= "<br />\n<strong><font color=\"DarkRed\">".$lang_details['text_all_genres']."</font></strong>";
|
||||
$temp = "";
|
||||
for ($i = 0; $i < count($gen); $i++)
|
||||
{
|
||||
$temp .= "$gen[$i], ";
|
||||
}
|
||||
$autodata .= rtrim(trim($temp), ",");
|
||||
|
||||
$autodata .= "<br />\n<strong><font color=\"DarkRed\">".$lang_details['text_tagline']."</font></strong>" . "".$movie->tagline ()."<br />\n";
|
||||
if ($director){
|
||||
$autodata .= "<strong><font color=\"DarkRed\">".$lang_details['text_director']."</font></strong>";
|
||||
$temp = "";
|
||||
for ($i = 0; $i < count ($director); $i++)
|
||||
{
|
||||
$temp .= "<a target=\"_blank\" href=\"https://www.imdb.com/" . "".$director[$i]["imdb"]."" ."\">" . $director[$i]["name"] . "</a>, ";
|
||||
}
|
||||
$autodata .= rtrim(trim($temp), ",");
|
||||
}
|
||||
elseif ($creator)
|
||||
$autodata .= "<strong><font color=\"DarkRed\">".$lang_details['text_creator']."</font></strong>".$creator;
|
||||
|
||||
$autodata .= "<br />\n<strong><font color=\"DarkRed\">".$lang_details['text_written_by']."</font></strong>";
|
||||
$temp = "";
|
||||
for ($i = 0; $i < count ($write); $i++)
|
||||
{
|
||||
$temp .= "<a target=\"_blank\" href=\"https://www.imdb.com/" . "".$write[$i]["imdb"]."" ."\">" . "".$write[$i]["name"]."" . "</a>, ";
|
||||
}
|
||||
$autodata .= rtrim(trim($temp), ",");
|
||||
|
||||
$autodata .= "<br />\n<strong><font color=\"DarkRed\">".$lang_details['text_produced_by']."</font></strong>";
|
||||
$temp = "";
|
||||
for ($i = 0; $i < count ($produce); $i++)
|
||||
{
|
||||
$temp .= "<a target=\"_blank\" href=\"https://www.imdb.com/" . "".$produce[$i]["imdb"]."" ." \">" . "".$produce[$i]["name"]."" . "</a>, ";
|
||||
}
|
||||
$autodata .= rtrim(trim($temp), ",");
|
||||
|
||||
$autodata .= "<br />\n<strong><font color=\"DarkRed\">".$lang_details['text_music']."</font></strong>";
|
||||
$temp = "";
|
||||
for ($i = 0; $i < count($compose); $i++)
|
||||
{
|
||||
$temp .= "<a target=\"_blank\" href=\"https://www.imdb.com/" . "".$compose[$i]["imdb"]."" ." \">" . "".$compose[$i]["name"]."" . "</a>, ";
|
||||
}
|
||||
$autodata .= rtrim(trim($temp), ",");
|
||||
|
||||
$autodata .= "<br /><br />\n\n<strong><font color=\"navy\">------------------------------------------------------------------------------------------------------------------------------------</font><br />\n";
|
||||
$autodata .= "<font color=\"darkred\" size=\"3\">".$lang_details['text_plot_outline']."</font><br />\n";
|
||||
$autodata .= "<font color=\"navy\">------------------------------------------------------------------------------------------------------------------------------------</font></strong>";
|
||||
|
||||
// if(count($plot) == 0)
|
||||
// {
|
||||
// $autodata .= "<br />\n".$plot_outline;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// for ($i = 0; $i < count ($plot); $i++)
|
||||
// {
|
||||
// $autodata .= "<br />\n<font color=\"DarkRed\">.</font> ";
|
||||
// $autodata .= $plot[$i];
|
||||
// }
|
||||
// }
|
||||
if (!empty($plot_outline)) {
|
||||
$autodata .= "<br />\n".$plot_outline;
|
||||
}
|
||||
|
||||
|
||||
$autodata .= "<br /><br />\n\n<strong><font color=\"navy\">------------------------------------------------------------------------------------------------------------------------------------</font><br />\n";
|
||||
$autodata .= "<font color=\"darkred\" size=\"3\">".$lang_details['text_cast']."</font><br />\n";
|
||||
$autodata .= "<font color=\"navy\">------------------------------------------------------------------------------------------------------------------------------------</font></strong><br />\n";
|
||||
|
||||
for ($i = 0; $i < count ($cast); $i++)
|
||||
{
|
||||
// if ($i > 9)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
$autodata .= "<font color=\"DarkRed\">.</font> " . "<a target=\"_blank\" href=\"https://www.imdb.com/" . "".$cast[$i]["imdb"]."" ."\">" . $cast[$i]["name"] . "</a> " .$lang_details['text_as']."<strong><font color=\"DarkRed\">" . "".$cast[$i]["role"]."" . " </font></strong><br />\n";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+42
-21
@@ -14,14 +14,6 @@ class PTGen
|
||||
{
|
||||
private $apiPoint;
|
||||
|
||||
const FORMAT_HTML = 1;
|
||||
const FORMAT_JSON = 2;
|
||||
|
||||
private static $formatText = [
|
||||
self::FORMAT_HTML => 'HTML',
|
||||
self::FORMAT_JSON => 'json',
|
||||
];
|
||||
|
||||
const SITE_DOUBAN = 'douban';
|
||||
const SITE_IMDB = 'imdb';
|
||||
const SITE_BANGUMI = 'bangumi';
|
||||
@@ -57,24 +49,39 @@ class PTGen
|
||||
$this->apiPoint = $apiPoint;
|
||||
}
|
||||
|
||||
public function generate(string $url): array
|
||||
public function generate(string $url, bool $withoutCache = false): array
|
||||
{
|
||||
$parsed = $this->parse($url);
|
||||
$targetUrl = sprintf('%s/?site=%s&sid=%s', trim($this->apiPoint, '/'), $parsed['site'] , $parsed['id']);
|
||||
return $this->request($targetUrl, $withoutCache);
|
||||
}
|
||||
|
||||
public function parse(string $url): array
|
||||
{
|
||||
foreach (self::$validSites as $site => $info) {
|
||||
if (preg_match($info['url_pattern'], $url, $matches)) {
|
||||
$targetUrl = sprintf('%s/?site=%s&sid=%s', trim($this->apiPoint, '/'), $site , $matches[1]);
|
||||
return $this->request($targetUrl);
|
||||
return [
|
||||
'site' => $site,
|
||||
'url' => $matches[0],
|
||||
'id' => $matches[1]
|
||||
];
|
||||
}
|
||||
}
|
||||
throw new PTGenException("invalid url: $url");
|
||||
}
|
||||
|
||||
private function buildDetailsPageTableRow($ptGenArr, $site)
|
||||
private function buildDetailsPageTableRow($torrentId, $ptGenArr, $site)
|
||||
{
|
||||
global $lang_details;
|
||||
$ptGenFormatted = $ptGenArr['format'];
|
||||
$prefix = sprintf("[img]%s[/img]\n", $ptGenArr['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'],
|
||||
$torrentId, $site, $lang_details['text_here_to_update']
|
||||
);
|
||||
$titleShowOrHide = $lang_details['title_show_or_hide'] ?? '';
|
||||
$id = 'pt-gen-' . $site;
|
||||
$html = <<<HTML
|
||||
@@ -100,15 +107,17 @@ HTML;
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function request(string $url): array
|
||||
private function request(string $url, bool $withoutCache = false): array
|
||||
{
|
||||
global $Cache;
|
||||
$logPrefix = "url: $url";
|
||||
$cacheKey = __METHOD__ . ":$url";
|
||||
$cache = $Cache->get_value($cacheKey);
|
||||
if ($cache) {
|
||||
do_log("$logPrefix, from cache");
|
||||
return $cache;
|
||||
$cacheKey = $this->getApiPointResultCacheKey($url);
|
||||
if (!$withoutCache) {
|
||||
$cache = $Cache->get_value($cacheKey);
|
||||
if ($cache) {
|
||||
do_log("$logPrefix, from cache");
|
||||
return $cache;
|
||||
}
|
||||
}
|
||||
$http = new Client();
|
||||
$response = $http->get($url, ['timeout' => 10]);
|
||||
@@ -136,9 +145,21 @@ HTML;
|
||||
throw new PTGenException($msg);
|
||||
}
|
||||
$Cache->cache_value($cacheKey, $bodyArr, 24 * 3600);
|
||||
do_log("$logPrefix, success get from api point");
|
||||
return $bodyArr;
|
||||
}
|
||||
|
||||
public function deleteApiPointResultCache($url)
|
||||
{
|
||||
global $Cache;
|
||||
$Cache->delete_value($this->getApiPointResultCacheKey($url));
|
||||
}
|
||||
|
||||
private function getApiPointResultCacheKey($url)
|
||||
{
|
||||
return __METHOD__ . "_$url";
|
||||
}
|
||||
|
||||
public function renderUploadPageFormInput($ptGen = '')
|
||||
{
|
||||
global $lang_functions;
|
||||
@@ -153,7 +174,7 @@ HTML;
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function renderDetailsPageDescription(array $torrentPtGenArr): array
|
||||
public function renderDetailsPageDescription($torrentId, array $torrentPtGenArr): array
|
||||
{
|
||||
$html = '';
|
||||
$jsonArr = [];
|
||||
@@ -169,14 +190,14 @@ HTML;
|
||||
'link' => $link,
|
||||
'data' => $data,
|
||||
];
|
||||
$html .= $this->buildDetailsPageTableRow($data, $site);
|
||||
$html .= $this->buildDetailsPageTableRow($torrentId, $data, $site);
|
||||
} else {
|
||||
$ptGenArr = $this->generate($torrentPtGenArr[$site]['link']);
|
||||
$jsonArr[$site] = [
|
||||
'link' => $link,
|
||||
'data' => $ptGenArr,
|
||||
];
|
||||
$html .= $this->buildDetailsPageTableRow($ptGenArr, $site);
|
||||
$html .= $this->buildDetailsPageTableRow($torrentId, $ptGenArr, $site);
|
||||
if (!$update) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user