torrents list imdb rating

This commit is contained in:
xiaomlove
2021-01-18 19:45:33 +08:00
parent 16df59db5b
commit 2f7e613549
12 changed files with 210 additions and 223 deletions
+107 -17
View File
@@ -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;
}
}
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace Nexus\Imdb;
class ImdbException extends \Exception
{
}
+26
View File
@@ -22,14 +22,17 @@ class PTGen
self::SITE_IMDB => [
'url_pattern' => '/(?:https?:\/\/)?(?:www\.)?imdb\.com\/title\/(tt\d+)\/?/',
'home_page' => 'https://www.imdb.com/',
'rating_average_img' => 'pic/imdb2.png',
],
self::SITE_DOUBAN => [
'url_pattern' => '/(?:https?:\/\/)?(?:(?:movie|www)\.)?douban\.com\/(?:subject|movie)\/(\d+)\/?/',
'home_page' => 'https://www.douban.com/',
'rating_average_img' => 'pic/douban2.png',
],
self::SITE_BANGUMI => [
'url_pattern' => '/(?:https?:\/\/)?(?:bgm\.tv|bangumi\.tv|chii\.in)\/subject\/(\d+)\/?/',
'home_page' => 'https://bangumi.tv/',
'rating_average_img' => 'pic/douban2.png',
],
];
@@ -205,4 +208,27 @@ HTML;
}
return ['json_arr' => $jsonArr, 'html' => $html, 'update' => $update];
}
public function renderTorrentsPageAverageRating(array $ptGenData)
{
$result = '<td class="embedded" style="text-align: right; width: 40px;padding-right: 5px"><div style="display: flex;flex-direction: column">';
$count = 1;
foreach (self::$validSites as $site => $info) {
$rating = $ptGenData[$site]['data']["{$site}_rating_average"] ?? '';
if (empty($rating)) {
continue;
}
if ($count > 2) {
//only show the first two
break;
}
$result .= sprintf(
'<div style="display: flex;align-content: center;justify-content: space-between;padding: 2px 0"><img src="%s" alt="%s" title="%s" style="max-width: 16px;max-height: 16px"/><span>%s</span></div>',
$info['rating_average_img'], $site, $site, $rating
);
$count++;
}
$result .= '</div></td>';
return $result;
}
}