add command event:fire + fetch imdb when torrent created

This commit is contained in:
xiaomlove
2024-02-23 02:38:42 +08:00
parent 5c6a2b13f9
commit 9efa5b2ae5
12 changed files with 227 additions and 24 deletions

View File

@@ -34,8 +34,8 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Nexus\Database\NexusDB;
use Nexus\Imdb\Imdb;
use Rhilip\Bencode\Bencode;
use function Sodium\compare;
class TorrentRepository extends BaseRepository
{
@@ -862,4 +862,33 @@ HTML;
return compact('total', 'success');
}
public function fetchImdb(int $torrentId): void
{
$torrent = Torrent::query()->findOrFail($torrentId, ["id", "url", "cache_stamp"]);
$imdb_id = parse_imdb_id($torrent->url);
$log = sprintf("fetchImdb torrentId: %s", $torrentId);
if (!$imdb_id) {
do_log("$log, no imdb_id");
return;
}
$thenumbers = $imdb_id;
$imdb = new Imdb();
$torrent->cache_stamp = time();
$torrent->save();
$imdb->purgeSingle($imdb_id);
try {
$imdb->updateCache($imdb_id);
NexusDB::cache_del('imdb_id_'.$thenumbers.'_movie_name');
NexusDB::cache_del('imdb_id_'.$thenumbers.'_large', true);
NexusDB::cache_del('imdb_id_'.$thenumbers.'_median', true);
NexusDB::cache_del('imdb_id_'.$thenumbers.'_minor', true);
do_log("$log, done");
} catch (\Exception $e) {
$log .= ", error: " . $e->getMessage() . ", trace: " . $e->getTraceAsString();
do_log($log, 'error');
}
}
}