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)
{
$id = parse_imdb_id($id);
$log = "id: $id";
$cacheFile = $this->getCacheFilePath($id);
if (!file_exists($cacheFile)) {
$log .= ", file: $cacheFile not exits";
}
$result = filemtime($cacheFile);
$log .= ", file: $cacheFile cache at: $result";
do_log($log);
return $result;
}
/**
* @date 2021/1/18
* @param int $id
* @return int state (0-not complete, 1-cache complete)
*/
public function getCacheStatus(int $id)
{
$id = parse_imdb_id($id);
$log = "id: $id";
$cacheFile = $this->getCacheFilePath($id);
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)
{
$mainCacheFile = $this->getCacheFilePath($id);
foreach (glob("$mainCacheFile*") as $file) {
if (file_exists($file)) {
do_log("unlink: $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, $suffix = '')
{
$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)
{
global $lang_details;
$movie = $this->getMovie($imdbId);
$thenumbers = $imdbId;
$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();
$autodata = 'https://www.imdb.com/title/tt'.$thenumbers."
------------------------------------------------------------------------------------------------------------------------------------
\n";
$autodata .= "".$lang_details['text_information']."
\n";
$autodata .= "------------------------------------------------------------------------------------------------------------------------------------
\n";
$autodata .= "". $lang_details['text_title']."" . "".$movie->title ()."
\n";
$autodata .= "".$lang_details['text_also_known_as']."";
$temp = "";
foreach ($movie->alsoknow() as $ak)
{
$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());
$autodata .= "
\n".$lang_details['text_year']."" . "".$movie->year ()."
\n";
$autodata .= "".$lang_details['text_runtime']."".$runtimes."
\n";
$autodata .= "".$lang_details['text_votes']."" . "".$movie->votes ()."
\n";
$autodata .= "".$lang_details['text_rating']."" . "".$movie->rating ()."
\n";
$autodata .= "".$lang_details['text_language']."" . "".$movie->language ()."
\n";
$autodata .= "".$lang_details['text_country']."";
$temp = "";
for ($i = 0; $i < count ($country); $i++)
{
$temp .="$country[$i], ";
}
$autodata .= rtrim(trim($temp), ",");
$autodata .= "
\n".$lang_details['text_all_genres']."";
$temp = "";
for ($i = 0; $i < count($gen); $i++)
{
$temp .= "$gen[$i], ";
}
$autodata .= rtrim(trim($temp), ",");
$autodata .= "
\n".$lang_details['text_tagline']."" . "".$movie->tagline ()."
\n";
if ($director){
$autodata .= "".$lang_details['text_director']."";
$temp = "";
for ($i = 0; $i < count ($director); $i++)
{
$temp .= "" . $director[$i]["name"] . ", ";
}
$autodata .= rtrim(trim($temp), ",");
}
elseif ($creator)
$autodata .= "".$lang_details['text_creator']."".$creator;
$autodata .= "
\n".$lang_details['text_written_by']."";
$temp = "";
for ($i = 0; $i < count ($write); $i++)
{
$temp .= "" . "".$write[$i]["name"]."" . ", ";
}
$autodata .= rtrim(trim($temp), ",");
$autodata .= "
\n".$lang_details['text_produced_by']."";
$temp = "";
for ($i = 0; $i < count ($produce); $i++)
{
$temp .= "" . "".$produce[$i]["name"]."" . ", ";
}
$autodata .= rtrim(trim($temp), ",");
$autodata .= "
\n".$lang_details['text_music']."";
$temp = "";
for ($i = 0; $i < count($compose); $i++)
{
$temp .= "" . "".$compose[$i]["name"]."" . ", ";
}
$autodata .= rtrim(trim($temp), ",");
$autodata .= "
\n\n------------------------------------------------------------------------------------------------------------------------------------
\n";
$autodata .= "".$lang_details['text_plot_outline']."
\n";
$autodata .= "------------------------------------------------------------------------------------------------------------------------------------";
// if(count($plot) == 0)
// {
// $autodata .= "
\n".$plot_outline;
// }
// else
// {
// for ($i = 0; $i < count ($plot); $i++)
// {
// $autodata .= "
\n. ";
// $autodata .= $plot[$i];
// }
// }
if (!empty($plot_outline)) {
$autodata .= "
\n".$plot_outline;
}
$autodata .= "
\n\n------------------------------------------------------------------------------------------------------------------------------------
\n";
$autodata .= "".$lang_details['text_cast']."
\n";
$autodata .= "------------------------------------------------------------------------------------------------------------------------------------
\n";
for ($i = 0; $i < count ($cast); $i++)
{
if ($i > 9)
{
break;
}
$autodata .= ". " . "" . $cast[$i]["name"] . " " .$lang_details['text_as']."" . "".$cast[$i]["role"]."" . "
\n";
}
return $autodata;
}
public function renderTorrentsPageAverageRating(int $imdbId)
{
$imdbId = parse_imdb_id($imdbId);
if ($this->getCacheStatus($imdbId) != 1) {
return '';
}
$movie = $this->getMovie($imdbId);
$site = 'imdb';
$rating = $movie->rating();
$result = '