17
17
namespace App \Http \Controllers ;
18
18
19
19
use App \Models \Category ;
20
+ use App \Models \IgdbGame ;
20
21
use App \Models \Movie ;
21
22
use App \Models \Torrent ;
22
23
use App \Models \TorrentRequest ;
23
24
use App \Models \Tv ;
25
+ use App \Services \Igdb \IgdbScraper ;
24
26
use App \Services \Tmdb \TMDBScraper ;
25
27
use Illuminate \Http \Request ;
26
28
use Illuminate \Support \Carbon ;
27
- use MarcReichel \IGDBLaravel \Models \Game ;
28
- use MarcReichel \IGDBLaravel \Models \PlatformLogo ;
29
29
30
30
class SimilarTorrentController extends Controller
31
31
{
@@ -71,18 +71,12 @@ public function show(int $categoryId, int $tmdbId): \Illuminate\Contracts\View\F
71
71
72
72
abort_unless ($ hasTorrents , 404 , 'No Similar Torrents Found ' );
73
73
74
- $ meta = Game::with ([
75
- 'cover ' => ['url ' , 'image_id ' ],
76
- 'artworks ' => ['url ' , 'image_id ' ],
77
- 'genres ' => ['name ' ],
78
- 'videos ' => ['video_id ' , 'name ' ],
79
- 'involved_companies.company ' ,
80
- 'involved_companies.company.logo ' ,
74
+ $ meta = IgdbGame::with ([
75
+ 'genres ' ,
76
+ 'companies ' ,
81
77
'platforms ' ,
82
- ])
83
- ->findOrFail ($ tmdbId );
84
- $ link = collect ($ meta ->videos )->take (1 )->pluck ('video_id ' );
85
- $ platforms = PlatformLogo::whereIn ('id ' , collect ($ meta ->platforms )->pluck ('platform_logo ' )->toArray ())->get ();
78
+ ]);
79
+
86
80
$ igdb = $ tmdbId ;
87
81
88
82
break ;
@@ -95,66 +89,61 @@ public function show(int $categoryId, int $tmdbId): \Illuminate\Contracts\View\F
95
89
return view ('torrent.similar ' , [
96
90
'meta ' => $ meta ,
97
91
'personal_freeleech ' => $ personalFreeleech ,
98
- 'platforms ' => $ platforms ?? null ,
99
92
'category ' => $ category ,
100
93
'tmdb ' => $ tmdb ?? null ,
101
94
'igdb ' => $ igdb ?? null ,
102
95
]);
103
96
}
104
97
105
- public function update (Request $ request , Category $ category , int $ tmdbId ): \Illuminate \Http \RedirectResponse
98
+ public function update (Request $ request , Category $ category , int $ metaId ): \Illuminate \Http \RedirectResponse
106
99
{
100
+ if (!($ category ->movie_meta || $ category ->tv_meta || $ category ->game_meta )) {
101
+ return to_route ('torrents.similar ' , ['category_id ' => $ category ->id , 'tmdb ' => $ metaId ])
102
+ ->withErrors ('This meta type can not be updated. ' );
103
+ }
104
+
107
105
if (
108
- $ tmdbId === 0
106
+ $ metaId === 0
109
107
|| (
110
- Torrent::where ('category_id ' , '= ' , $ category ->id )->where ('tmdb ' , '= ' , $ tmdbId )->doesntExist ()
111
- && TorrentRequest::where ('category_id ' , '= ' , $ category ->id )->where ('tmdb ' , '= ' , $ tmdbId )->doesntExist ()
108
+ ($ category ->movie_meta || $ category ->tv_meta )
109
+ && Torrent::where ('category_id ' , '= ' , $ category ->id )->where ('tmdb ' , '= ' , $ metaId )->doesntExist ()
110
+ && TorrentRequest::where ('category_id ' , '= ' , $ category ->id )->where ('tmdb ' , '= ' , $ metaId )->doesntExist ()
111
+ )
112
+ || (
113
+ $ category ->game_meta
114
+ && Torrent::where ('category_id ' , '= ' , $ category ->id )->where ('igdb ' , '= ' , $ metaId )->doesntExist ()
115
+ && TorrentRequest::where ('category_id ' , '= ' , $ category ->id )->where ('igdb ' , '= ' , $ metaId )->doesntExist ()
112
116
)
113
117
) {
114
- return to_route ('torrents.similar ' , ['category_id ' => $ category ->id , 'tmdb ' => $ tmdbId ])
118
+ return to_route ('torrents.similar ' , ['category_id ' => $ category ->id , 'tmdb ' => $ metaId ])
115
119
->withErrors ('There exists no torrent with this tmdb. ' );
116
120
}
117
121
118
- $ tmdbScraper = new TMDBScraper ();
119
-
120
- switch (true ) {
121
- case $ category ->movie_meta :
122
- $ cacheKey = 'tmdb-movie-scraper: ' .$ tmdbId ;
123
-
124
- /** @var Carbon $lastUpdated */
125
- $ lastUpdated = cache ()->get ($ cacheKey );
126
-
127
- abort_if (
128
- $ lastUpdated !== null
129
- && $ lastUpdated ->addDay ()->isFuture ()
130
- && !($ request ->user ()->group ->is_modo || $ request ->user ()->group ->is_editor ),
131
- 403
132
- );
133
-
134
- cache ()->put ($ cacheKey , now (), now ()->addDay ());
135
-
136
- $ tmdbScraper ->movie ($ tmdbId );
137
-
138
- break ;
139
- case $ category ->tv_meta :
140
- $ cacheKey = 'tmdb-tv-scraper: ' .$ tmdbId ;
141
-
142
- /** @var Carbon $lastUpdated */
143
- $ lastUpdated = cache ()->get ($ cacheKey );
144
-
145
- abort_if (
146
- $ lastUpdated !== null
147
- && $ lastUpdated ->addDay ()->isFuture ()
148
- && !($ request ->user ()->group ->is_modo || $ request ->user ()->group ->is_editor ),
149
- 403
150
- );
151
-
152
- cache ()->put ($ cacheKey , now (), now ()->addDay ());
153
-
154
- $ tmdbScraper ->tv ($ tmdbId );
155
-
156
- break ;
157
- }
122
+ /** @phpstan-ignore match.unhandled (The first line of this method ensures that at least one of these are true) */
123
+ $ cacheKey = match (true ) {
124
+ $ category ->movie_meta => "tmdb-movie-scraper: {$ metaId }" ,
125
+ $ category ->tv_meta => "tmdb-tv-scraper: {$ metaId }" ,
126
+ $ category ->game_meta => "igdb-game-scraper: {$ metaId }" ,
127
+ };
128
+
129
+ /** @var ?Carbon $lastUpdated */
130
+ $ lastUpdated = cache ()->get ($ cacheKey );
131
+
132
+ abort_if (
133
+ $ lastUpdated !== null
134
+ && $ lastUpdated ->addDay ()->isFuture ()
135
+ && !($ request ->user ()->group ->is_modo || $ request ->user ()->group ->is_torrent_modo || $ request ->user ()->group ->is_editor ),
136
+ 403
137
+ );
138
+
139
+ cache ()->put ($ cacheKey , now (), now ()->addDay ());
140
+
141
+ /** @phpstan-ignore match.unhandled (The first line of this method ensures that at least one of these are true) */
142
+ match (true ) {
143
+ $ category ->movie_meta => new TMDBScraper ()->movie ($ metaId ),
144
+ $ category ->tv_meta => new TMDBScraper ()->tv ($ metaId ),
145
+ $ category ->game_meta => new IgdbScraper ()->game ($ metaId ),
146
+ };
158
147
159
148
return back ()->with ('success ' , 'Metadata update queued successfully. ' );
160
149
}
0 commit comments