mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 22:01:33 +00:00
188 lines
7.2 KiB
PHP
188 lines
7.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\DnzbFailure;
|
|
use App\Models\Predb;
|
|
use App\Models\Release;
|
|
use App\Models\ReleaseComment;
|
|
use App\Models\ReleaseFile;
|
|
use App\Models\ReleaseNfo;
|
|
use App\Models\ReleaseRegex;
|
|
use App\Models\ReleaseReport;
|
|
use App\Models\Settings;
|
|
use App\Models\UserDownload;
|
|
use App\Models\Video;
|
|
use App\Services\AnidbService;
|
|
use App\Services\BookService;
|
|
use App\Services\ConsoleService;
|
|
use App\Services\GamesService;
|
|
use App\Services\MovieService;
|
|
use App\Services\MusicService;
|
|
use App\Services\PopulateAniListService;
|
|
use App\Services\ReleaseExtraService;
|
|
use App\Services\Releases\ReleaseSearchService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DetailsController extends BasePageController
|
|
{
|
|
private ReleaseSearchService $releaseSearchService;
|
|
|
|
private MovieService $movieService;
|
|
|
|
private ReleaseExtraService $releaseExtraService;
|
|
|
|
public function __construct(
|
|
ReleaseSearchService $releaseSearchService,
|
|
MovieService $movieService,
|
|
ReleaseExtraService $releaseExtraService
|
|
) {
|
|
parent::__construct();
|
|
$this->releaseSearchService = $releaseSearchService;
|
|
$this->movieService = $movieService;
|
|
$this->releaseExtraService = $releaseExtraService;
|
|
}
|
|
|
|
public function show(Request $request, string $guid): mixed
|
|
{
|
|
$data = Release::getByGuid($guid);
|
|
$releaseRegex = '';
|
|
if (! empty($data)) {
|
|
$releaseRegex = ReleaseRegex::query()->where('releases_id', '=', $data['id'])->first();
|
|
}
|
|
|
|
if (! $data) {
|
|
return redirect()->back();
|
|
}
|
|
|
|
if ($this->isPostBack($request)) {
|
|
ReleaseComment::addComment($data['id'], $data['gid'], $request->input('txtAddComment'), $this->userdata->id, $request->ip());
|
|
|
|
return redirect()->route('details', ['guid' => $guid])->with('success', 'Comment posted successfully!');
|
|
}
|
|
|
|
$nfoData = ReleaseNfo::getReleaseNfo($data['id']);
|
|
/** @var ReleaseNfo|null $nfoData */
|
|
$nfo = $nfoData ? $nfoData->nfo : null;
|
|
$reVideo = $this->releaseExtraService->getVideo($data['id']);
|
|
$reAudio = $this->releaseExtraService->getAudio($data['id']);
|
|
$reSubs = $this->releaseExtraService->getSubs($data['id']);
|
|
$comments = ReleaseComment::getComments($data['id']);
|
|
$similars = $this->releaseSearchService->searchSimilar($data['id'], $data['searchname'], (array) $this->userdata->categoryexclusions);
|
|
$failed = DnzbFailure::getFailedCount($data['id']);
|
|
$reportData = ReleaseReport::where('releases_id', $data['id'])
|
|
->whereIn('status', ['pending', 'reviewed', 'resolved'])
|
|
->get();
|
|
$reportCount = $reportData->count();
|
|
$reportReasons = ReleaseReport::reasonKeysToLabels($reportData->pluck('reason')->unique()->implode(', '));
|
|
$downloadedBy = UserDownload::query()->with('user')->where('releases_id', $data['id'])->get(['users_id']);
|
|
|
|
$showInfo = '';
|
|
if ($data['videos_id'] > 0) {
|
|
$showInfo = Video::getByVideoID($data['videos_id']);
|
|
}
|
|
|
|
$mov = '';
|
|
if ($data['imdbid'] !== '' && $data['imdbid'] !== 0000000) {
|
|
$mov = $this->movieService->getMovieInfo($data['imdbid']);
|
|
if (! empty($mov['title'])) {
|
|
$mov['title'] = str_replace(['/', '\\'], '', $mov['title']);
|
|
if (! empty($mov['actors'])) {
|
|
$mov['actors'] = makeFieldLinks($mov, 'actors', 'movies');
|
|
}
|
|
if (! empty($mov['genre'])) {
|
|
$mov['genre'] = makeFieldLinks($mov, 'genre', 'movies');
|
|
}
|
|
if (! empty($mov['director'])) {
|
|
$mov['director'] = makeFieldLinks($mov, 'director', 'movies');
|
|
}
|
|
if (Settings::settingValue('trailers_display')) {
|
|
$trailer = empty($mov['trailer']) ? $this->movieService->getTrailer($data['imdbid']) : $mov['trailer'];
|
|
if ($trailer) {
|
|
$mov['trailer'] = sprintf('<iframe width="%d" height="%d" src="%s"></iframe>', Settings::settingValue('trailers_size_x'), Settings::settingValue('trailers_size_y'), $trailer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$game = '';
|
|
if (! empty($data['gamesinfo_id'])) {
|
|
$game = (new GamesService)->getGamesInfoById($data['gamesinfo_id']);
|
|
}
|
|
|
|
$mus = '';
|
|
if (! empty($data['musicinfo_id'])) {
|
|
$mus = (new MusicService)->getMusicInfo($data['musicinfo_id']);
|
|
}
|
|
|
|
$book = '';
|
|
if (! empty($data['bookinfo_id'])) {
|
|
$book = (new BookService)->getBookInfo($data['bookinfo_id']);
|
|
}
|
|
|
|
$con = '';
|
|
if (! empty($data['consoleinfo_id'])) {
|
|
$con = (new ConsoleService)->getConsoleInfo($data['consoleinfo_id']);
|
|
}
|
|
|
|
$AniDBAPIArray = '';
|
|
if ($data['anidbid'] > 0) {
|
|
$AniDBAPIArray = (new AnidbService)->getAnimeInfo($data['anidbid']);
|
|
|
|
// If we have anilist_id but missing details, fetch from AniList
|
|
if ($AniDBAPIArray && ! empty($AniDBAPIArray->anilist_id)) {
|
|
$anilistId = $AniDBAPIArray->anilist_id;
|
|
if (empty($AniDBAPIArray->country) && empty($AniDBAPIArray->media_type)) {
|
|
// Fetch fresh data from AniList if country/media_type is missing
|
|
try {
|
|
$palist = new PopulateAniListService;
|
|
$palist->populateTable('info', $anilistId);
|
|
// Refresh the data
|
|
$AniDBAPIArray = (new AnidbService)->getAnimeInfo($data['anidbid']);
|
|
} catch (\Exception $e) {
|
|
// Silently fail, use existing data
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$pre = Predb::getForRelease($data['predb_id']);
|
|
|
|
$releasefiles = ReleaseFile::getReleaseFiles($data['id']);
|
|
|
|
$this->viewData = array_merge($this->viewData, [
|
|
'releasefiles' => $releasefiles,
|
|
'release' => $data,
|
|
'reVideo' => $reVideo,
|
|
'reAudio' => $reAudio,
|
|
'reSubs' => $reSubs,
|
|
'nfo' => $nfo,
|
|
'show' => $showInfo,
|
|
'movie' => $mov,
|
|
'anidb' => $AniDBAPIArray,
|
|
'music' => $mus,
|
|
'con' => $con,
|
|
'game' => $game,
|
|
'book' => $book,
|
|
'predb' => $pre,
|
|
'comments' => $comments,
|
|
'files' => $releasefiles,
|
|
'searchname' => getSimilarName($data['searchname']),
|
|
'similars' => $similars !== false ? $similars : [],
|
|
'privateprofiles' => config('nntmux_settings.private_profiles'),
|
|
'failed' => $failed,
|
|
'reportCount' => $reportCount,
|
|
'reportReasons' => $reportReasons,
|
|
'regex' => $releaseRegex,
|
|
'downloadedby' => $downloadedBy,
|
|
'meta_title' => 'View NZB',
|
|
'meta_keywords' => 'view,nzb,description,details',
|
|
'meta_description' => 'View NZB for '.$data['searchname'],
|
|
]);
|
|
|
|
return view('details.index', $this->viewData);
|
|
}
|
|
}
|