mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
torrents list imdb rating
This commit is contained in:
+107
-17
@@ -9,18 +9,112 @@ class Imdb
|
||||
{
|
||||
private $config;
|
||||
|
||||
private $movie;
|
||||
|
||||
private $pages = array('Title', 'Credits', 'Amazon', 'Goofs', 'Plot', 'Comments', 'Quotes', 'Taglines', 'Plotoutline', 'Trivia', 'Directed');
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$config = new Config();
|
||||
$config->cachedir = ROOT_PATH . 'imdb/cache';
|
||||
$config->photodir = ROOT_PATH . 'imdb/pic_imdb';
|
||||
$config->photoroot = 'pic_imdb';
|
||||
$cacheDir = ROOT_PATH . 'imdb/cache/';
|
||||
$photoRoot = 'images/';
|
||||
$photoDir = ROOT_PATH . "imdb/$photoRoot";
|
||||
$this->checkDir($cacheDir, 'imdb_cache_dir');
|
||||
$this->checkDir($photoDir, 'imdb_photo_dir');
|
||||
|
||||
$config->cachedir = $cacheDir;
|
||||
$config->photodir = $photoDir;
|
||||
$config->photoroot = $photoRoot;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
private function checkDir($dir, $langKeyPrefix)
|
||||
{
|
||||
global $lang_functions;
|
||||
if (!is_dir($dir)) {
|
||||
$mkdirResult = mkdir($dir, 0777, true);
|
||||
if ($mkdirResult !== true) {
|
||||
$msg = $lang_functions["{$langKeyPrefix}_can_not_create"];
|
||||
do_log("$msg, dir: $dir");
|
||||
throw new ImdbException($msg);
|
||||
}
|
||||
}
|
||||
if (!is_writable($dir)) {
|
||||
$msg = $lang_functions["{$langKeyPrefix}_is_not_writeable"];
|
||||
do_log("$msg, dir: $dir");
|
||||
throw new ImdbException($msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getCachedAt(int $id, string $page)
|
||||
{
|
||||
$id = parse_imdb_id($id);
|
||||
$log = "id: $id, page: $page";
|
||||
$cacheFile = $this->getCacheFilePath($id, $page);
|
||||
if (!file_exists($cacheFile)) {
|
||||
$log .= ", file: $cacheFile not exits";
|
||||
}
|
||||
$result = filemtime($cacheFile);
|
||||
$log .= ", cache at: $result";
|
||||
do_log($log);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
return 1;
|
||||
$id = parse_imdb_id($id);
|
||||
$log = "id: $id, page: $page";
|
||||
$cacheFile = $this->getCacheFilePath($id, $page);
|
||||
if (!file_exists($cacheFile)) {
|
||||
$log .= ", file: $cacheFile not exits";
|
||||
do_log($log);
|
||||
return 0;
|
||||
}
|
||||
if (!fopen($cacheFile, 'r')) {
|
||||
$log .= ", file: $cacheFile can not open";
|
||||
do_log($log);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function purgeSingle($id)
|
||||
{
|
||||
foreach ($this->pages as $page) {
|
||||
$file = $this->getCacheFilePath($id, $page);
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getMovie($id)
|
||||
{
|
||||
if (!$this->movie) {
|
||||
$this->movie = new Title($id, $this->config);
|
||||
}
|
||||
return $this->movie;
|
||||
}
|
||||
|
||||
private function getCacheFilePath($id, $page)
|
||||
{
|
||||
return sprintf('%s%s.%s', $this->config->cachedir, $id, $page);
|
||||
}
|
||||
|
||||
public function renderDetailsPageDescription($torrentId, $imdbId)
|
||||
{
|
||||
$movie = new Title($imdbId, $this->config);
|
||||
global $lang_details;
|
||||
$movie = $this->getMovie($imdbId);
|
||||
$thenumbers = $imdbId;
|
||||
$country = $movie->country ();
|
||||
$director = $movie->director();
|
||||
$creator = $movie->creator(); // For TV series
|
||||
@@ -32,12 +126,7 @@ class Imdb
|
||||
$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\" />";
|
||||
// $similiar_movies = $movie->similiar_movies();
|
||||
|
||||
$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";
|
||||
@@ -48,11 +137,10 @@ class Imdb
|
||||
$temp = "";
|
||||
foreach ($movie->alsoknow() as $ak)
|
||||
{
|
||||
// $temp .= $ak["title"].$ak["year"]. ($ak["country"] != "" ? " (".$ak["country"].")" : "") . ($ak["comment"] != "" ? " (" . $ak["comment"] . ")" : "") . ", ";
|
||||
$temp .= $ak["title"] . ", ";
|
||||
$temp .= $ak["title"].$ak["year"]. ($ak["country"] != "" ? " (".$ak["country"].")" : "") . ($ak["comment"] != "" ? " (" . $ak["comment"] . ")" : "") . ", ";
|
||||
}
|
||||
$autodata .= rtrim(trim($temp), ",");
|
||||
$runtimes = str_replace(" min",$lang_details['text_mins'], $movie->runtime_all());
|
||||
$runtimes = str_replace(" min",$lang_details['text_mins'], $movie->runtime());
|
||||
$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";
|
||||
@@ -139,12 +227,14 @@ class Imdb
|
||||
|
||||
for ($i = 0; $i < count ($cast); $i++)
|
||||
{
|
||||
// if ($i > 9)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
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";
|
||||
}
|
||||
|
||||
return $autodata;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user