ptgen not show individual fields on details page

This commit is contained in:
xiaomlove
2022-04-15 03:09:12 +08:00
parent 609c549755
commit 534287a237
18 changed files with 154 additions and 65 deletions

View File

@@ -30,3 +30,7 @@ Complete PT website building solution. Based on NexusPHP + Laravel Framework + E
Blog[https://nexusphp.org](https://nexusphp.org/)
Documentation[https://doc.nexusphp.org](https://doc.nexusphp.org/en/)
Telegram: [https://t.me/nexusphp](https://t.me/nexusphp)
## Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/xiaomlove/nexusphp)

View File

@@ -35,3 +35,6 @@ B站: [xiaomlove](https://space.bilibili.com/1319303059)
微信公众号:
![扫码关注](https://nexusphp.org/wp-content/uploads/2022/03/wechat_official_account.png)
## Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/xiaomlove/nexusphp)

View File

@@ -126,10 +126,8 @@ class Test extends Command
// $r = $rep->getContinuousDays($attendance);
// $r = $rep->getContinuousPoints(11);
$url = 'https://www.imdb.com/title/tt4574334/?ref_=vp_vi_tt';
$imdb = new Imdb();
$rating = $imdb->getRating($url);
dd($rating);
$r = json_decode('http://www.imdb.com/title/tt0468569', true);
dd($r);
}

View File

@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.2');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-04-14');
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.3');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-04-15');
defined('IN_TRACKER') || define('IN_TRACKER', true);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -1157,7 +1157,7 @@ function get_external_tr($imdb_url = "")
}
$ptGen = new Nexus\PTGen\PTGen();
$imdbNumber = parse_imdb_id($imdb_url);
$y = $ptGen->buildInput("url", $imdbNumber ? "http://www.imdb.com/title/tt".parse_imdb_id($imdb_url) : "", $lang_functions['text_imdb_url_note'], $lang_functions['pt_gen_get_description']);
$y = $ptGen->buildInput("url", $imdbNumber ? "http://www.imdb.com/title/tt".parse_imdb_id($imdb_url) : "", $lang_functions['text_imdb_url_note'], nexus_trans('ptgen.btn_get_desc'));
return tr($lang_functions['row_imdb_url'], $y, 1);
// ($showextinfo['imdb'] == 'yes' ? tr($lang_functions['row_imdb_url'], "<input type=\"text\" style=\"width: 99%;\" name=\"url\" value=\"".($imdbNumber ? "http://www.imdb.com/title/tt".parse_imdb_id($imdb_url) : "")."\" /><br /><font class=\"medium\">".$lang_functions['text_imdb_url_note']."</font>", 1) : "");

View File

@@ -297,12 +297,6 @@ $lang_functions = array
'text_inactive_account_be_deleted' => "内做些下载。没有流量的用户会被删除账号。",
'text_attendance' => '签到得魔力',
'text_attended' => '(签到已得%u, 补签卡:%d)',
'row_pt_gen_douban_url' => "PT-Gen douban 链接",
'text_pt_gen_douban_url_note' => "(来自 <strong><a href=\"https://www.douban.com/\">douban</a></strong> 的链接。如电影 <b>Transformers</b> 的链接是<b> https://movie.douban.com/subject/1794171/</b>)",
'row_pt_gen_imdb_url' => "PT-Gen imdb 链接",
'text_pt_gen_imdb_url_note' => "(来自 <strong><a href=\"https://www.imdb.com//\">imdb</a></strong> 的链接。如电影 <b>Transformers</b> 的链接是<b> https://www.imdb.com/title/tt0418279/</b>)",
'row_pt_gen_bangumi_url' => "PT-Gen bangumi 链接",
'text_pt_gen_bangumi_url_note' => "(来自 <strong><a href=\"https://bangumi.tv/\">bangumi</a></strong> 的链接。如动画 <b>星际牛仔</b> 的链接是<b> https://bangumi.tv/subject/253/</b>)",
'imdb_cache_dir_can_not_create' => 'imdb 缓存目录无法创建',
'imdb_cache_dir_is_not_writeable' => 'imdb 缓存目录不可写',
'imdb_photo_dir_can_not_create' => 'imdb 图片目录无法创建',
@@ -322,7 +316,6 @@ $lang_functions = array
'text_seed_points' => '做种积分',
'spoiler_expand_collapse' => '点击展开/收缩',
'spoiler_default_title' => '折叠内容',
'pt_gen_get_description' => '获取简介',
);
?>

View File

@@ -323,7 +323,6 @@ $lang_functions = array
'text_seed_points' => '做種積分',
'spoiler_expand_collapse' => '點擊展開/收縮',
'spoiler_default_title' => '折疊內容',
'pt_gen_get_description' => '獲取簡介',
);
?>

View File

@@ -324,7 +324,6 @@ $lang_functions = array
'text_seed_points' => 'Seed points',
'spoiler_expand_collapse' => 'Click to expand/collapse',
'spoiler_default_title' => 'Collapse content',
'pt_gen_get_description' => 'Get desc',
);
?>

View File

@@ -9,7 +9,9 @@
namespace Nexus\PTGen;
use App\Models\Torrent;
use Carbon\Carbon;
use GuzzleHttp\Client;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Nexus\Imdb\Imdb;
@@ -20,6 +22,9 @@ class PTGen
const SITE_DOUBAN = 'douban';
const SITE_IMDB = 'imdb';
const SITE_BANGUMI = 'bangumi';
const SITE_STEAM = 'steam';
const SITE_INDIENOVA = 'indienova';
const SITE_EPIC = 'epic';
public static array $validSites = [
self::SITE_IMDB => [
@@ -39,6 +44,23 @@ class PTGen
'home_page' => 'https://bangumi.tv/',
'rating_average_img' => 'pic/bangumi.jpg',
],
//Banned !
// self::SITE_STEAM => [
// 'url_pattern' => '/(?:https?:\/\/)?(?:store\.)?steam(?:powered|community)\.com\/app\/(\d+)\/?/',
// 'home_page' => 'https://store.steampowered.com/',
// 'rating_average_img' => 'pic/steam.svg',
// ],
self::SITE_INDIENOVA => [
'url_pattern' => '/(?:https?:\/\/)?indienova\.com\/game\/(\S+)/',
'home_page' => 'https://indienova.com/',
'rating_average_img' => 'pic/invienova.jpg',
],
//seems url_pattern has changed
// self::SITE_EPIC => [
// 'url_pattern' => '/(?:https?:\/\/)?www\.epicgames\.com\/store\/[a-zA-Z-]+\/product\/(\S+)\/\S?/',
// 'home_page' => 'https://store.epicgames.com/',
// 'rating_average_img' => 'pic/epic_game.png',
// ],
];
@@ -196,18 +218,21 @@ HTML;
return __METHOD__ . "_$url";
}
public function renderUploadPageFormInput($ptGen = '')
public function renderUploadPageFormInput($ptGen = ''): string
{
global $lang_functions;
$html = '';
$ptGen = (array)json_decode($ptGen, true);
foreach (self::$validSites as $site => $info) {
$value = $ptGen[$site]['link'] ?? '';
$x = $lang_functions["row_pt_gen_{$site}_url"];
$y = $this->buildInput("pt_gen[{$site}][link]", $value, $lang_functions["text_pt_gen_{$site}_url_note"], $lang_functions['pt_gen_get_description']);
$html .= tr($x, $y, 1);
$arr = json_decode($ptGen, true);
$link = is_array($arr) ? $arr['__link'] : $ptGen;
$y = $this->buildInput("pt_gen", $link, nexus_trans('ptgen.tooltip', ['sites' => $this->buildTooltip()]), nexus_trans('ptgen.btn_get_desc'));
return tr(nexus_trans('ptgen.label'), $y, 1, '', true);
}
return $html;
private function buildTooltip(): string
{
$results = [];
foreach (self::$validSites as $site => $info) {
$results[] = sprintf('<a href="%s" target="_blank" /><strong>%s</strong></a>', $info['home_page'], $site);
}
return implode(' / ', $results);
}
public function buildInput($name, $value, $note, $btnText): string
@@ -317,7 +342,9 @@ HTML;
public function isIyuu(array $bodyArr): bool
{
return isset($bodyArr['ret']) && $bodyArr['ret'] == 200;
return false;
//Not support, due to change frequently
// return isset($bodyArr['ret']) && $bodyArr['ret'] == 200;
}
public function listRatings(array $ptGenData, string $imdbLink, string $desc = ''): array
@@ -340,7 +367,7 @@ HTML;
// from original structure fetch
if ($this->isRawPTGen($data)) {
$log .= ", isRawPTGen";
$rating = $data["{$site}_rating_average"] ?? '';
$rating = $this->getRawPTGenRating($data, $site);
} elseif ($this->isIyuu($data)) {
$log .= ", isIyuu";
$pattern = $info['rating_pattern_in_desc'] ?? null;
@@ -361,7 +388,7 @@ HTML;
$imdb = new Imdb();
$imdbRating = $imdb->getRating($imdbLink);
$results[self::SITE_IMDB] = $imdbRating;
$log .= ", again 'imdb' from: $imdbLink} -> $imdbRating";
$log .= ", again 'imdb' from: $imdbLink -> $imdbRating";
}
//Otherwise, get from desc
if (!empty($desc)) {
@@ -386,31 +413,80 @@ HTML;
return $results;
}
public function updateTorrentPtGen(array $torrentInfo, $siteId = null)
public function updateTorrentPtGen(array $torrentInfo): bool|array
{
$ptGenInfo = json_decode($torrentInfo['pt_gen'], true);
foreach (self::$validSites as $site => $siteConfig) {
if ($siteId !== null && $siteId != $site) {
//If specific, only update it
continue;
$now = Carbon::now();
$log = "torrent: " . $torrentInfo['id'];
$arr = json_decode($torrentInfo['pt_gen'], true);
if (is_array($arr)) {
if (!empty($arr['__updated_at'])) {
$log .= ", updated_at: " . $arr['__updated_at'];
$updatedAt = Carbon::parse($arr['__updated_at']);
$diffInDays = $now->diffInDays($updatedAt);
$log .= ", diffInDays: $diffInDays";
if ($diffInDays < 30) {
do_log("$log, less 30 days, don't update");
return false;
}
if (empty($ptGenInfo[$site]['link'])) {
do_log("site: $site no link...");
}
$link = $this->getLink($arr);
} else {
$link = $torrentInfo['pt_gen'];
}
if (empty($link)) {
do_log("$log, no link...");
return false;
}
$ptGenInfo = [];
foreach (self::$validSites as $site => $siteConfig) {
if (!preg_match($siteConfig['url_pattern'], $link, $matches)) {
continue;
}
try {
$response = $this->generate($ptGenInfo[$site]['link'], true);
$response = $this->generate($matches[0], true);
$ptGenInfo[$site]['data'] = $response;
} catch (\Exception $exception) {
do_log("site: $site can not be updated: " . $exception->getMessage(), 'error');
do_log("$log, site: $site can not be updated: " . $exception->getMessage(), 'error');
}
}
$siteIdAndRating = $this->listRatings($ptGenInfo, $torrentInfo['url'], $torrentInfo['descr']);
foreach ($siteIdAndRating as $key => $value) {
$ptGenInfo[$key]['data']["__rating"] = $value;
}
$ptGenInfo['__link'] = $link;
$ptGenInfo['__updated_at'] = $now->toDateTimeString();
Torrent::query()->where('id', $torrentInfo['id'])->update(['pt_gen' => $ptGenInfo]);
do_log("$log, success update");
return $ptGenInfo;
}
public function getLink(array $ptGenInfo)
{
if (isset($ptGenInfo['__link'])) {
//new
return $ptGenInfo['__link'];
}
$result = '';
foreach ($ptGenInfo as $item) {
if (!empty($item['link'])) {
//old, use the last one
$result = $item['link'];
}
}
return $result;
}
private function getRawPTGenRating(array $ptGenInfo, $site)
{
$key = $site . "_rating_average";
if (isset($ptGenInfo[$key])) {
return $ptGenInfo[$key];
}
if ($site == self::SITE_INDIENOVA) {
$parts = preg_split('/[\s:]+/', $ptGenInfo['rate']);
return Arr::last($parts);
}
return '';
}
}

View File

@@ -277,11 +277,7 @@ if (!$row) {
if (get_setting('main.enable_pt_gen_system') == 'yes' && !empty($row['pt_gen'])) {
$ptGen = new \Nexus\PTGen\PTGen();
$ptGenResult = $ptGen->renderDetailsPageDescription($id, json_decode($row['pt_gen'], true));
if ($ptGenResult['update']) {
$torrentUpdate[] = 'pt_gen = ' . sqlesc(json_encode($ptGenResult['json_arr']));
}
echo $ptGenResult['html'];
$ptGen->updateTorrentPtGen($row);
}
if ($imdb_id)
{

BIN
public/pic/epic_game.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
public/pic/invienova.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

16
public/pic/steam.svg Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 233 233">
<defs>
<linearGradient id="a" x2="50%" x1="50%" y2="100%">
<stop stop-color="#111D2E" offset="0"/>
<stop stop-color="#051839" offset=".21248"/>
<stop stop-color="#0A1B48" offset=".40695"/>
<stop stop-color="#132E62" offset=".58110"/>
<stop stop-color="#144B7E" offset=".73760"/>
<stop stop-color="#136497" offset=".87279"/>
<stop stop-color="#1387B8" offset="1"/>
</linearGradient>
</defs>
<path fill="url(#a)" d="m4.8911 150.01c14.393 48.01 58.916 82.99 111.61 82.99 64.34 0 116.5-52.16 116.5-116.5 0-64.341-52.16-116.5-116.5-116.5-61.741 0-112.26 48.029-116.25 108.76 7.5391 12.66 10.481 20.49 4.6411 41.25z"/>
<path fill="#fff" d="m110.5 87.322c0 0.196 0 0.392 0.01 0.576l-28.508 41.412c-4.618-0.21-9.252 0.6-13.646 2.41-1.937 0.79-3.752 1.76-5.455 2.88l-62.599-25.77c0.00049 0-1.4485 23.83 4.588 41.59l44.254 18.26c2.222 9.93 9.034 18.64 19.084 22.83 16.443 6.87 35.402-0.96 42.242-17.41 1.78-4.3 2.61-8.81 2.49-13.31l40.79-29.15c0.33 0.01 0.67 0.02 1 0.02 24.41 0 44.25-19.9 44.25-44.338 0-24.44-19.84-44.322-44.25-44.322-24.4 0-44.25 19.882-44.25 44.322zm-6.84 83.918c-5.294 12.71-19.9 18.74-32.596 13.45-5.857-2.44-10.279-6.91-12.83-12.24l14.405 5.97c9.363 3.9 20.105-0.54 23.997-9.9 3.904-9.37-0.525-20.13-9.883-24.03l-14.891-6.17c5.746-2.18 12.278-2.26 18.381 0.28 6.153 2.56 10.927 7.38 13.457 13.54s2.52 12.96-0.04 19.1m51.09-54.38c-16.25 0-29.48-13.25-29.48-29.538 0-16.275 13.23-29.529 29.48-29.529 16.26 0 29.49 13.254 29.49 29.529 0 16.288-13.23 29.538-29.49 29.538m-22.09-29.583c0-12.253 9.92-22.191 22.14-22.191 12.23 0 22.15 9.938 22.15 22.191 0 12.254-9.92 22.183-22.15 22.183-12.22 0-22.14-9.929-22.14-22.183z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -19,7 +19,7 @@ if (!$id)
die();
$res = sql_query("SELECT category, owner, filename, save_as, anonymous, picktype, picktime, added FROM torrents WHERE id = ".mysql_real_escape_string($id));
$res = sql_query("SELECT category, owner, filename, save_as, anonymous, picktype, picktime, added, pt_gen FROM torrents WHERE id = ".mysql_real_escape_string($id));
$row = mysql_fetch_array($res);
$torrentAddedTimeString = $row['added'];
if (!$row)
@@ -28,7 +28,6 @@ if (!$row)
if ($CURUSER["id"] != $row["owner"] && get_user_class() < $torrentmanage_class)
bark($lang_takeedit['std_not_owner']);
$oldcatmode = get_single_value("categories","mode","WHERE id=".sqlesc($row['category']));
$updateset = array();
//$fname = $row["filename"];
@@ -42,15 +41,12 @@ $url = parse_imdb_id($_POST['url'] ?? '');
* @since 1.6
*/
if (!empty($_POST['pt_gen'])) {
//use PT-Gen imdb for url
$postPtGen = $_POST['pt_gen'];
$ptGenImdbLink = $postPtGen[\Nexus\PTGen\PTGen::SITE_IMDB]['link'] ?? '';
if (empty($url) && !empty($ptGenImdbLink)) {
$existsPtGenInfo = json_decode($row['pt_gen'], true) ?? [];
$ptGen = new \Nexus\PTGen\PTGen();
$ptGenImdbInfo = $ptGen->parse($ptGenImdbLink);
$url = str_replace('tt', '', $ptGenImdbInfo['id']);
if ($postPtGen != $ptGen->getLink($existsPtGenInfo)) {
$updateset[] = "pt_gen = " . sqlesc($postPtGen);
}
$updateset[] = "pt_gen = " . sqlesc(json_encode($postPtGen));
} else {
$updateset[] = "pt_gen = ''";
}

View File

@@ -293,18 +293,6 @@ foreach ($promotionrules_torrent as $rule)
}
}
$dateTimeStringNow = \Carbon\Carbon::now()->toDateTimeString();
/**
* add PT-Gen
* @since 1.6
*/
$postPtGen = $_POST['pt_gen'] ?? [];
$ptGenImdbLink = $postPtGen[\Nexus\PTGen\PTGen::SITE_IMDB]['link'] ?? '';
if (empty($url) && !empty($ptGenImdbLink)) {
//use PT-Gen imdb for url
$ptGen = new \Nexus\PTGen\PTGen();
$ptGenImdbInfo = $ptGen->parse($ptGenImdbLink);
$url = str_replace('tt', '', $ptGenImdbInfo['id']);
}
$torrentSavePath = getFullDirectory($torrent_dir);
if (!is_dir($torrentSavePath)) {
@@ -315,7 +303,7 @@ if (!is_writable($torrentSavePath)) {
}
$ret = sql_query("INSERT INTO torrents (filename, owner, visible, anonymous, name, size, numfiles, type, url, small_descr, descr, ori_descr, category, source, medium, codec, audiocodec, standard, processing, team, save_as, sp_state, added, last_action, nfo, info_hash, pt_gen, technical_info) VALUES (".sqlesc($fname).", ".sqlesc($CURUSER["id"]).", 'yes', ".sqlesc($anonymous).", ".sqlesc($torrent).", ".sqlesc($totallen).", ".count($filelist).", ".sqlesc($type).", ".sqlesc($url).", ".sqlesc($small_descr).", ".sqlesc($descr).", ".sqlesc($descr).", ".sqlesc($catid).", ".sqlesc($sourceid).", ".sqlesc($mediumid).", ".sqlesc($codecid).", ".sqlesc($audiocodecid).", ".sqlesc($standardid).", ".sqlesc($processingid).", ".sqlesc($teamid).", ".sqlesc($dname).", ".sqlesc($sp_state) .
", " . sqlesc(date("Y-m-d H:i:s")) . ", " . sqlesc(date("Y-m-d H:i:s")) . ", ".sqlesc($nfo).", " . sqlesc($infohash). ", " . sqlesc(json_encode($postPtGen)) . ", " . sqlesc($_POST['technical_info'] ?? '') . ")");
", " . sqlesc(date("Y-m-d H:i:s")) . ", " . sqlesc(date("Y-m-d H:i:s")) . ", ".sqlesc($nfo).", " . sqlesc($infohash). ", " . sqlesc($_POST['pt_gen']) . ", " . sqlesc($_POST['technical_info'] ?? '') . ")");
if (!$ret) {
if (mysql_errno() == 1062)
bark($lang_takeupload['std_torrent_existed']);

View File

@@ -0,0 +1,7 @@
<?php
return [
'label' => 'PT-Gen',
'tooltip' => 'Link comes from:sites ',
'btn_get_desc' => 'Get desc',
];

View File

@@ -0,0 +1,7 @@
<?php
return [
'label' => 'PT-Gen',
'tooltip' => '来自::sites 的链接',
'btn_get_desc' => '获取简介',
];

View File

@@ -0,0 +1,7 @@
<?php
return [
'label' => 'PT-Gen',
'tooltip' => '來自::sites 的鏈接',
'btn_get_desc' => '獲取簡介',
];