recover ptGen

This commit is contained in:
xiaomlove
2025-05-16 02:43:45 +07:00
parent 47f453335d
commit d123e8a849
19 changed files with 140 additions and 41 deletions

1
.gitignore vendored
View File

@@ -24,6 +24,7 @@ yarn-error.log
/imdb/cache /imdb/cache
/imdb/images /imdb/images
/resources/geoip /resources/geoip
/resources/upload
.DS_Store .DS_Store
/plugins /plugins
auth.json auth.json

View File

@@ -7,11 +7,13 @@ use App\Models\ExamUser;
use App\Models\Language; use App\Models\Language;
use App\Models\PersonalAccessToken; use App\Models\PersonalAccessToken;
use App\Models\Torrent; use App\Models\Torrent;
use App\Models\TorrentExtra;
use App\Models\User; use App\Models\User;
use App\Repositories\ExamRepository; use App\Repositories\ExamRepository;
use App\Repositories\SeedBoxRepository; use App\Repositories\SeedBoxRepository;
use App\Repositories\UploadRepository; use App\Repositories\UploadRepository;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Nexus\PTGen\PTGen;
use NexusPlugin\Menu\Filament\MenuItemResource\Pages\ManageMenuItems; use NexusPlugin\Menu\Filament\MenuItemResource\Pages\ManageMenuItems;
use NexusPlugin\Menu\MenuRepository; use NexusPlugin\Menu\MenuRepository;
use NexusPlugin\Menu\Models\MenuItem; use NexusPlugin\Menu\Models\MenuItem;
@@ -56,7 +58,7 @@ class Test extends Command
*/ */
public function handle() public function handle()
{ {
Language::updateTransStatus();
} }
} }

View File

@@ -29,7 +29,7 @@ class MigrateTorrentsTableTextColumn extends Command
public function handle() public function handle()
{ {
if (Schema::hasTable("torrent_extras") && Schema::hasColumn("torrents", "descr")) { if (Schema::hasTable("torrent_extras") && Schema::hasColumn("torrents", "descr")) {
NexusDB::statement("insert into torrent_extras (torrent_id, descr, media_info, nfo, created_at) select id, descr, technical_info, nfo, now() from torrents on duplicate key update torrent_id = values(torrent_id)"); NexusDB::statement("insert into torrent_extras (torrent_id, descr, media_info, nfo, pt_gen, created_at) select id, descr, technical_info, nfo, pt_gen, now() from torrents on duplicate key update torrent_id = values(torrent_id)");
} }
$columns = ["ori_descr", "descr", "nfo", "technical_info", "pt_gen"]; $columns = ["ori_descr", "descr", "nfo", "technical_info", "pt_gen"];
$sql = "alter table torrents "; $sql = "alter table torrents ";

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Listeners;
use App\Models\Setting;
use App\Models\Torrent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Nexus\PTGen\PTGen;
class FetchTorrentPTGen implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(object $event): void
{
$logPrefix = "FetchTorrentPTGen";
if (!Setting::getIsPTGenEnabled()) {
do_log("$logPrefix, PTGen is disabled");
return;
}
$torrent = $event->model;
if (!$torrent instanceof Torrent) {
do_log("$logPrefix, not Torrent: " . Torrent::class);
return;
}
$torrentId = $torrent->id ?? 0;
if (empty($torrentId)) {
do_log("$logPrefix, no torrent_id");
return;
}
$torrentTool = new PTGen();
$torrentTool->updateTorrentPtGen($torrentId);
do_log("FetchTorrentPTGen for torrent: $torrentId done!");
}
}

View File

@@ -19,7 +19,7 @@ class NexusFormatter
$id = nexus()->getRequestId(); $id = nexus()->getRequestId();
} }
$format = "[%datetime%] [" . $id . "] %channel%.%level_name%: %message% %context% %extra%\n"; $format = "[%datetime%] [" . $id . "] %channel%.%level_name%: %message% %context% %extra%\n";
return tap(new LineFormatter($format, 'Y-m-d H:i:s', true, true), function ($formatter) { return tap(new LineFormatter($format, "Y-m-d\TH:i:s.vP", true, true), function ($formatter) {
$formatter->includeStacktraces(); $formatter->includeStacktraces();
}); });
} }

View File

@@ -120,6 +120,11 @@ class Setting extends NexusModel
return self::get("main.defaultlang"); return self::get("main.defaultlang");
} }
public static function getIsPTGenEnabled(): bool
{
return self::get("main.enable_pt_gen_system") == "yes";
}
public static function getIsUseChallengeResponseAuthentication(): bool public static function getIsUseChallengeResponseAuthentication(): bool
{ {
return self::get("security.use_challenge_response_authentication") == "yes"; return self::get("security.use_challenge_response_authentication") == "yes";

View File

@@ -9,7 +9,11 @@ class TorrentExtra extends NexusModel
{ {
public $timestamps = true; public $timestamps = true;
protected $fillable = ['torrent_id', 'descr', 'ori_descr', 'media_info', 'nfo']; protected $fillable = ['torrent_id', 'descr', 'ori_descr', 'media_info', 'nfo', 'pt_gen'];
protected $casts = [
'pt_gen' => 'array',
];
public function torrent() public function torrent()
{ {

View File

@@ -10,6 +10,7 @@ use App\Events\UserDeleted;
use App\Events\UserDisabled; use App\Events\UserDisabled;
use App\Listeners\DeductUserBonusWhenTorrentDeleted; use App\Listeners\DeductUserBonusWhenTorrentDeleted;
use App\Listeners\FetchTorrentImdb; use App\Listeners\FetchTorrentImdb;
use App\Listeners\FetchTorrentPTGen;
use App\Listeners\RemoveOauthTokens; use App\Listeners\RemoveOauthTokens;
use App\Listeners\RemoveSeedBoxRecordCache; use App\Listeners\RemoveSeedBoxRecordCache;
use App\Listeners\SendEmailNotificationWhenTorrentCreated; use App\Listeners\SendEmailNotificationWhenTorrentCreated;
@@ -41,6 +42,7 @@ class EventServiceProvider extends ServiceProvider
], ],
TorrentCreated::class => [ TorrentCreated::class => [
FetchTorrentImdb::class, FetchTorrentImdb::class,
FetchTorrentPTGen::class,
SyncTorrentToElasticsearch::class, SyncTorrentToElasticsearch::class,
SyncTorrentToMeilisearch::class, SyncTorrentToMeilisearch::class,
SendEmailNotificationWhenTorrentCreated::class, SendEmailNotificationWhenTorrentCreated::class,

View File

@@ -128,7 +128,7 @@ class ClaimRepository extends BaseRepository
{ {
$startOfThisMonth = Carbon::now()->startOfMonth(); $startOfThisMonth = Carbon::now()->startOfMonth();
$query = Claim::query() $query = Claim::query()
->selectRaw("uid, count(*) as count)") ->selectRaw("uid, count(*) as count")
->where("created_at", "<", $startOfThisMonth) ->where("created_at", "<", $startOfThisMonth)
->where(function (Builder $query) use ($startOfThisMonth) { ->where(function (Builder $query) use ($startOfThisMonth) {
$query->where('last_settle_at', '<', $startOfThisMonth)->orWhereNull('last_settle_at'); $query->where('last_settle_at', '<', $startOfThisMonth)->orWhereNull('last_settle_at');

View File

@@ -17,6 +17,7 @@ return new class extends Migration
$table->mediumText('descr'); $table->mediumText('descr');
$table->text('media_info')->nullable(); $table->text('media_info')->nullable();
$table->binary('nfo')->nullable(); $table->binary('nfo')->nullable();
$table->mediumText('pt_gen')->nullable();
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('torrent_extras', function (Blueprint $table) {
if (!Schema::hasColumn('torrent_extras', 'pt_gen')) {
$table->mediumText('pt_gen')->nullable()->after('nfo');
}
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('torrent_extras', function (Blueprint $table) {
//
});
}
};

View File

@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.0'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-05-13'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-05-16');
defined('IN_TRACKER') || define('IN_TRACKER', false); defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -1,7 +1,7 @@
<?php <?php
use App\Models\SearchBox; use App\Models\SearchBox;
use Carbon\CarbonInterface; use App\Models\TorrentExtra;
use Illuminate\Support\HtmlString; use Illuminate\Support\HtmlString;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@@ -3386,6 +3386,7 @@ function torrenttable($rows, $variant = "torrent", $searchBoxId = 0) {
$enablePtGen = get_setting('main.enable_pt_gen_systemyes') == 'yes'; $enablePtGen = get_setting('main.enable_pt_gen_systemyes') == 'yes';
$torrentSeedingLeechingStatus = $torrent->listLeechingSeedingStatus($CURUSER['id'], $torrentIdArr); $torrentSeedingLeechingStatus = $torrent->listLeechingSeedingStatus($CURUSER['id'], $torrentIdArr);
$ptGenInfo = TorrentExtra::query()->whereIn('torrent_id', $torrentIdArr)->pluck('pt_gen', 'torrent_id')->toArray();
$tagRep = new \App\Repositories\TagRepository(); $tagRep = new \App\Repositories\TagRepository();
$torrentTagCollection = \App\Models\TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->get(); $torrentTagCollection = \App\Models\TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->get();
$torrentTagResult = $torrentTagCollection->groupBy('torrent_id'); $torrentTagResult = $torrentTagCollection->groupBy('torrent_id');
@@ -3664,7 +3665,7 @@ foreach ($rows as $row)
print("</td>"); print("</td>");
if ($enableImdb || $enablePtGen) { if ($enableImdb || $enablePtGen) {
echo $torrent->renderTorrentsPageAverageRating($row); echo $torrent->renderTorrentsPageAverageRating($row, $ptGenInfo[$row['id']] ?? []);
} }
$act = ""; $act = "";
if ($CURUSER["dlicon"] != 'no' && $CURUSER["downloadpos"] != "no") if ($CURUSER["dlicon"] != 'no' && $CURUSER["downloadpos"] != "no")

View File

@@ -9,10 +9,12 @@
namespace Nexus\PTGen; namespace Nexus\PTGen;
use App\Models\Torrent; use App\Models\Torrent;
use App\Models\TorrentExtra;
use Carbon\Carbon; use Carbon\Carbon;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Nexus\Database\NexusDB;
use Nexus\Imdb\Imdb; use Nexus\Imdb\Imdb;
class PTGen class PTGen
@@ -163,12 +165,11 @@ HTML;
private function request(string $url, bool $withoutCache = false): array private function request(string $url, bool $withoutCache = false): array
{ {
global $Cache;
$begin = microtime(true); $begin = microtime(true);
$logPrefix = "url: $url"; $logPrefix = "url: $url";
$cacheKey = $this->getApiPointResultCacheKey($url); $cacheKey = $this->getApiPointResultCacheKey($url);
if (!$withoutCache) { if (!$withoutCache) {
$cache = $Cache->get_value($cacheKey); $cache = NexusDB::cache_get($cacheKey);
if ($cache) { if ($cache) {
do_log("$logPrefix, from cache"); do_log("$logPrefix, from cache");
return $cache; return $cache;
@@ -196,7 +197,7 @@ HTML;
throw new PTGenException($msg); throw new PTGenException($msg);
} }
if ($this->isRawPTGen($bodyArr) || $this->isIyuu($bodyArr)) { if ($this->isRawPTGen($bodyArr) || $this->isIyuu($bodyArr)) {
$Cache->cache_value($cacheKey, $bodyArr, 24 * 3600); NexusDB::cache_put($cacheKey, $bodyArr, 24 * 3600);
do_log("$logPrefix, success get from api point, use time: " . (microtime(true) - $begin)); do_log("$logPrefix, success get from api point, use time: " . (microtime(true) - $begin));
$bodyArr['__updated_at'] = now()->toDateTimeString(); $bodyArr['__updated_at'] = now()->toDateTimeString();
return $bodyArr; return $bodyArr;
@@ -209,8 +210,7 @@ HTML;
public function deleteApiPointResultCache($url) public function deleteApiPointResultCache($url)
{ {
global $Cache; NexusDB::cache_del($this->getApiPointResultCacheKey($url));
$Cache->delete_value($this->getApiPointResultCacheKey($url));
} }
private function getApiPointResultCacheKey($url) private function getApiPointResultCacheKey($url)
@@ -413,11 +413,17 @@ HTML;
return $results; return $results;
} }
public function updateTorrentPtGen(array $torrentInfo): bool|array public function updateTorrentPtGen(int $id): bool|array
{ {
$now = Carbon::now(); $now = Carbon::now();
$log = "torrent: " . $torrentInfo['id']; $log = "updateTorrentPtGen, torrent: " . $id;
$arr = json_decode($torrentInfo['pt_gen'], true); $torrent = Torrent::query()->find($id);
if (empty($torrent)) {
do_log("$log, Torrent not found");
return false;
}
$extra = $torrent->extra;
$arr = $extra->pt_gen;
if (is_array($arr)) { if (is_array($arr)) {
if (!empty($arr['__updated_at'])) { if (!empty($arr['__updated_at'])) {
$log .= ", updated_at: " . $arr['__updated_at']; $log .= ", updated_at: " . $arr['__updated_at'];
@@ -431,7 +437,7 @@ HTML;
} }
$link = $this->getLink($arr); $link = $this->getLink($arr);
} else { } else {
$link = $torrentInfo['pt_gen']; $link = $arr;
} }
if (empty($link)) { if (empty($link)) {
do_log("$log, no link..."); do_log("$log, no link...");
@@ -449,13 +455,13 @@ HTML;
do_log("$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']); $siteIdAndRating = $this->listRatings($ptGenInfo, $torrent->url, $extra->descr);
foreach ($siteIdAndRating as $key => $value) { foreach ($siteIdAndRating as $key => $value) {
$ptGenInfo[$key]['data']["__rating"] = $value; $ptGenInfo[$key]['data']["__rating"] = $value;
} }
$ptGenInfo['__link'] = $link; $ptGenInfo['__link'] = $link;
$ptGenInfo['__updated_at'] = $now->toDateTimeString(); $ptGenInfo['__updated_at'] = $now->toDateTimeString();
Torrent::query()->where('id', $torrentInfo['id'])->update(['pt_gen' => $ptGenInfo]); TorrentExtra::query()->where('torrent_id', $id)->update(['pt_gen' => $ptGenInfo]);
do_log("$log, success update"); do_log("$log, success update");
return $ptGenInfo; return $ptGenInfo;
} }

View File

@@ -3,6 +3,7 @@
namespace Nexus\Torrent; namespace Nexus\Torrent;
use App\Models\Setting; use App\Models\Setting;
use App\Models\TorrentExtra;
use Nexus\Database\NexusDB; use Nexus\Database\NexusDB;
use Nexus\Imdb\Imdb; use Nexus\Imdb\Imdb;
use Nexus\PTGen\PTGen; use Nexus\PTGen\PTGen;
@@ -55,6 +56,12 @@ class Torrent
return $snatchedList; return $snatchedList;
} }
public function listPTGenInfo(array $torrentIdArr)
{
$list = TorrentExtra::query()->whereIn('torrent_id', $torrentIdArr)->get(['torrent_id', 'pt_gen']);
}
public function renderProgressBar($activeStatus, $progress): string public function renderProgressBar($activeStatus, $progress): string
{ {
$color = '#aaa'; $color = '#aaa';
@@ -71,21 +78,15 @@ class Torrent
return $result; return $result;
} }
public function renderTorrentsPageAverageRating(array $torrentInfo): string public function renderTorrentsPageAverageRating(array $torrentInfo, array|string $ptGenInfo): string
{ {
static $ptGen; static $ptGen;
if (is_null($ptGen)) { if (is_null($ptGen)) {
$ptGen = new PTGen(); $ptGen = new PTGen();
} }
// $ptGenInfo = $torrentInfo['pt_gen'];
// if (!is_array($torrentInfo['pt_gen']) && is_string($torrentInfo['pt_gen'])) {
// $ptGenInfo = json_decode($ptGenInfo, true);
// }
$log = "torrent: " . $torrentInfo['id']; $log = "torrent: " . $torrentInfo['id'];
// $siteIdAndRating = $ptGen->listRatings($ptGenInfo ?? [], $torrentInfo['url']); $siteIdAndRating = $ptGen->listRatings(is_array($ptGenInfo) && count($ptGenInfo) ? $ptGenInfo : [], $torrentInfo['url']);
$siteIdAndRating = $ptGen->listRatings([], $torrentInfo['url']); $log .= ", siteIdAndRating: " . json_encode($siteIdAndRating);
$log .= "siteIdAndRating: " . json_encode($siteIdAndRating);
do_log($log); do_log($log);
return $ptGen->buildRatingSpan($siteIdAndRating); return $ptGen->buildRatingSpan($siteIdAndRating);
} }

View File

@@ -8,7 +8,7 @@ $id = intval($_GET['id'] ?? 0);
if (!$id) if (!$id)
die(); die();
$res = sql_query("SELECT torrents.*, categories.mode as cat_mode, torrent_extras.media_info as technical_info, torrent_extras.descr FROM torrents LEFT JOIN categories ON category = categories.id left join torrent_extras on torrents.id = torrent_extras.torrent_id WHERE torrents.id = $id"); $res = sql_query("SELECT torrents.*, categories.mode as cat_mode, torrent_extras.media_info as technical_info, torrent_extras.descr, torrent_extras.pt_gen FROM torrents LEFT JOIN categories ON category = categories.id left join torrent_extras on torrents.id = torrent_extras.torrent_id WHERE torrents.id = $id");
$row = mysql_fetch_assoc($res); $row = mysql_fetch_assoc($res);
if (!$row) die(); if (!$row) die();

View File

@@ -51,7 +51,7 @@ switch ($siteid)
{ {
$ptGen = new \Nexus\PTGen\PTGen(); $ptGen = new \Nexus\PTGen\PTGen();
try { try {
$ptGen->updateTorrentPtGen($row, $siteid); $ptGen->updateTorrentPtGen($id);
} catch (\Exception $e) { } catch (\Exception $e) {
$log = $e->getMessage() . ", trace: " . $e->getTraceAsString(); $log = $e->getMessage() . ", trace: " . $e->getTraceAsString();
do_log($log, 'error'); do_log($log, 'error');

View File

@@ -47,19 +47,19 @@ $url = parse_imdb_id($_POST['url'] ?? '');
* add PT-Gen * add PT-Gen
* @since 1.6 * @since 1.6
* *
* @deprecated
* @since 1.9
*/ */
//if (!empty($_POST['pt_gen'])) { if (!empty($_POST['pt_gen'])) {
// $postPtGen = $_POST['pt_gen']; $postPtGen = $_POST['pt_gen'];
// $existsPtGenInfo = json_decode($row['pt_gen'], true) ?? []; $existsPtGenInfo = json_decode($row['pt_gen'], true) ?? [];
// $ptGen = new \Nexus\PTGen\PTGen(); $ptGen = new \Nexus\PTGen\PTGen();
// if ($postPtGen != $ptGen->getLink($existsPtGenInfo)) { if ($postPtGen != $ptGen->getLink($existsPtGenInfo)) {
// $updateset[] = "pt_gen = " . sqlesc($postPtGen); // $updateset[] = "pt_gen = " . sqlesc($postPtGen);
// } $extraUpdate["pt_gen"] = $postPtGen;
//} else { }
} else {
// $updateset[] = "pt_gen = ''"; // $updateset[] = "pt_gen = ''";
//} $extraUpdate["pt_gen"] = "";
}
//$updateset[] = "technical_info = " . sqlesc($_POST['technical_info'] ?? ''); //$updateset[] = "technical_info = " . sqlesc($_POST['technical_info'] ?? '');
$extraUpdate["media_info"] = $_POST['technical_info'] ?? ''; $extraUpdate["media_info"] = $_POST['technical_info'] ?? '';

View File

@@ -353,13 +353,14 @@ $insert = [
'cache_stamp' => time(), 'cache_stamp' => time(),
]; ];
/** /**
* migrate to extra table and remove pt_gen field * migrate to extra table
* @since 1.9 * @since 1.9
*/ */
$extra = [ $extra = [
'descr' => $descr, 'descr' => $descr,
'media_info' => $_POST['technical_info'] ?? '', 'media_info' => $_POST['technical_info'] ?? '',
'nfo' => $nfo, 'nfo' => $nfo,
'pt_gen' => $_POST['pt_gen'] ?? '',
]; ];
if (isset($_POST['hr'][$catmod]) && isset(\App\Models\Torrent::$hrStatus[$_POST['hr'][$catmod]]) && user_can('torrent_hr')) { if (isset($_POST['hr'][$catmod]) && isset(\App\Models\Torrent::$hrStatus[$_POST['hr'][$catmod]]) && user_can('torrent_hr')) {
$insert['hr'] = $_POST['hr'][$catmod]; $insert['hr'] = $_POST['hr'][$catmod];