Skip to content

Commit ae33c74

Browse files
committed
refactor: prefix tmdb metadata models with tmdb
Will help for when there exists other metadata sources available (such as already done for igdb) Step 4 in cleaner meta fetching code.
1 parent b3a9f48 commit ae33c74

File tree

127 files changed

+1116
-993
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1116
-993
lines changed

app/Console/Commands/AutoCacheRandomMediaIds.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
namespace App\Console\Commands;
1818

19-
use App\Models\Movie;
20-
use App\Models\Tv;
19+
use App\Models\TmdbMovie;
20+
use App\Models\TmdbTv;
2121
use Illuminate\Console\Command;
2222
use Exception;
2323
use Illuminate\Support\Facades\Redis;
@@ -46,13 +46,13 @@ class AutoCacheRandomMediaIds extends Command
4646
*/
4747
final public function handle(): void
4848
{
49-
$movieIds = Movie::query()
49+
$movieIds = TmdbMovie::query()
5050
->select('id')
5151
->whereHas('torrents')
5252
->whereNotNull('backdrop')
5353
->pluck('id');
5454

55-
$tvIds = Tv::query()
55+
$tvIds = TmdbTv::query()
5656
->select('id')
5757
->whereHas('torrents')
5858
->whereNotNull('backdrop')

app/Console/Commands/AutoSyncPeopleToMeilisearch.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace App\Console\Commands;
1818

19-
use App\Models\Person;
19+
use App\Models\TmdbPerson;
2020
use Exception;
2121
use Illuminate\Console\Command;
2222
use Meilisearch\Client;
@@ -49,7 +49,7 @@ public function handle(): void
4949
$client = new Client(config('scout.meilisearch.host'), config('scout.meilisearch.key'));
5050
$index = $client->index(config('scout.prefix').'people');
5151

52-
$people = Person::all(['id', 'name', 'birthday', 'still']);
52+
$people = TmdbPerson::all(['id', 'name', 'birthday', 'still']);
5353

5454
$documents = $people->map(fn ($person) => [
5555
'id' => $person->id,

app/Console/Commands/DemoSeed.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ final public function handle(): void
8080

8181
Torrent::factory()->create([
8282
'user_id' => $uid,
83-
'movie_id' => $id,
83+
'tmdb_movie_id' => $id,
8484
'name' => $movie['title'],
8585
'description' => $movie['overview'],
8686
'category_id' => 1,
@@ -275,7 +275,7 @@ final public function handle(): void
275275

276276
Torrent::factory()->create([
277277
'user_id' => $uid,
278-
'tv_id' => $id,
278+
'tmdb_tv_id' => $id,
279279
'name' => $tv['name'],
280280
'description' => $tv['overview'],
281281
'category_id' => 2,

app/DTO/TorrentSearchFiltersDTO.php

+27-27
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ final public function toSqlQueryBuilder(): Closure
200200
->where(
201201
fn ($query) => $query
202202
->whereRelation('category', 'movie_meta', '=', true)
203-
->whereIn('movie_id', DB::table('genre_movie')->select('movie_id')->whereIn('genre_id', $this->genreIds))
203+
->whereIn('tmdb_movie_id', DB::table('tmdb_genre_tmdb_movie')->select('tmdb_movie_id')->whereIn('tmdb_genre_id', $this->genreIds))
204204
)
205205
->orWhere(
206206
fn ($query) => $query
207207
->whereRelation('category', 'tv_meta', '=', true)
208-
->whereIn('tv_id', DB::table('genre_tv')->select('tv_id')->whereIn('genre_id', $this->genreIds))
208+
->whereIn('tmdb_tv_id', DB::table('tmdb_genre_tmdb_tv')->select('tmdb_tv_id')->whereIn('tmdb_genre_id', $this->genreIds))
209209
)
210210
)
211211
)
@@ -232,8 +232,8 @@ final public function toSqlQueryBuilder(): Closure
232232
fn ($query) => $query
233233
->where(
234234
fn ($query) => $query
235-
->where('movie_id', '=', $this->tmdbId)
236-
->orWhere('tv_id', '=', $this->tmdbId)
235+
->where('tmdb_movie_id', '=', $this->tmdbId)
236+
->orWhere('tmdb_tv_id', '=', $this->tmdbId)
237237
)
238238
)
239239
->when($this->imdbId !== null, fn ($query) => $query->where('imdb', '=', $this->imdbId))
@@ -267,7 +267,7 @@ final public function toSqlQueryBuilder(): Closure
267267
$this->collectionId !== null,
268268
fn ($query) => $query
269269
->whereRelation('category', 'movie_meta', '=', true)
270-
->whereIn('movie_id', DB::table('collection_movie')->select('movie_id')->where('collection_id', '=', $this->collectionId))
270+
->whereIn('tmdb_movie_id', DB::table('tmdb_collection_tmdb_movie')->select('tmdb_movie_id')->where('tmdb_collection_id', '=', $this->collectionId))
271271
)
272272
->when(
273273
$this->companyId !== null,
@@ -277,20 +277,20 @@ final public function toSqlQueryBuilder(): Closure
277277
->where(
278278
fn ($query) => $query
279279
->whereRelation('category', 'movie_meta', '=', true)
280-
->whereIn('movie_id', DB::table('company_movie')->select('movie_id')->where('company_id', '=', $this->companyId))
280+
->whereIn('tmdb_movie_id', DB::table('tmdb_company_tmdb_movie')->select('tmdb_movie_id')->where('tmdb_company_id', '=', $this->companyId))
281281
)
282282
->orWhere(
283283
fn ($query) => $query
284284
->whereRelation('category', 'tv_meta', '=', true)
285-
->whereIn('tv_id', DB::table('company_tv')->select('tv_id')->where('company_id', '=', $this->companyId))
285+
->whereIn('tmdb_tv_id', DB::table('tmdb_company_tmdb_tv')->select('tmdb_tv_id')->where('tmdb_company_id', '=', $this->companyId))
286286
)
287287
)
288288
)
289289
->when(
290290
$this->networkId !== null,
291291
fn ($query) => $query
292292
->whereRelation('category', 'tv_meta', '=', true)
293-
->whereIn('tv_id', DB::table('network_tv')->select('tv_id')->where('network_id', '=', $this->networkId))
293+
->whereIn('tmdb_tv_id', DB::table('tmdb_network_tmdb_tv')->select('tmdb_tv_id')->where('tmdb_network_id', '=', $this->networkId))
294294
)
295295
->when(
296296
$this->primaryLanguageNames !== [],
@@ -369,12 +369,12 @@ final public function toSqlQueryBuilder(): Closure
369369
->where(
370370
fn ($query) => $query
371371
->whereRelation('movie_meta', '=', true)
372-
->whereIn('movie_id', Wish::select('movie_id')->where('user_id', '=', $this->user->id))
372+
->whereIn('tmdb_movie_id', Wish::select('tmdb_movie_id')->where('user_id', '=', $this->user->id))
373373
)
374374
->orWhere(
375375
fn ($query) => $query
376376
->whereRelation('tv_meta', '=', true)
377-
->whereIn('tv_id', Wish::select('tv_id')->where('user_id', '=', $this->user->id))
377+
->whereIn('tmdb_tv_id', Wish::select('tmdb_tv_id')->where('user_id', '=', $this->user->id))
378378
)
379379
)
380380
)
@@ -460,15 +460,15 @@ final public function toMeilisearchFilter(): array
460460

461461
if ($this->startYear !== null) {
462462
$filters[] = [
463-
'movie.year >= '.$this->startYear,
464-
'tv.year >= '.$this->startYear,
463+
'tmdb_movie.year >= '.$this->startYear,
464+
'tmdb_tv.year >= '.$this->startYear,
465465
];
466466
}
467467

468468
if ($this->endYear !== null) {
469469
$filters[] = [
470-
'movie.year <= '.$this->endYear,
471-
'tv.year <= '.$this->endYear,
470+
'tmdb_movie.year <= '.$this->endYear,
471+
'tmdb_tv.year <= '.$this->endYear,
472472
];
473473
}
474474

@@ -502,8 +502,8 @@ final public function toMeilisearchFilter(): array
502502

503503
if ($this->genreIds !== []) {
504504
$filters[] = [
505-
'movie.genres.id IN '.json_encode(array_map('intval', $this->genreIds)),
506-
'tv.genres.id IN '.json_encode(array_map('intval', $this->genreIds)),
505+
'tmdb_movie.genres.id IN '.json_encode(array_map('intval', $this->genreIds)),
506+
'tmdb_tv.genres.id IN '.json_encode(array_map('intval', $this->genreIds)),
507507
];
508508
}
509509

@@ -530,13 +530,13 @@ final public function toMeilisearchFilter(): array
530530
}
531531

532532
if ($this->adult !== null) {
533-
$filters[] = 'movie.adult = '.($this->adult ? 'true' : 'false');
533+
$filters[] = 'tmdb_movie.adult = '.($this->adult ? 'true' : 'false');
534534
}
535535

536536
if ($this->tmdbId !== null) {
537537
$filters[] = [
538-
'movie_id = '.$this->tmdbId,
539-
'tv_id = '.$this->tmdbId,
538+
'tmdb_movie_id = '.$this->tmdbId,
539+
'tmdb_tv_id = '.$this->tmdbId,
540540
];
541541
}
542542

@@ -557,24 +557,24 @@ final public function toMeilisearchFilter(): array
557557
}
558558

559559
if ($this->collectionId !== null) {
560-
$filters[] = 'movie.collection.id = '.$this->collectionId;
560+
$filters[] = 'tmdb_movie.collection.id = '.$this->collectionId;
561561
}
562562

563563
if ($this->companyId !== null) {
564564
$filters[] = [
565-
'movie.companies.id = '.$this->companyId,
566-
'tv.companies.id = '.$this->companyId,
565+
'tmdb_movie.companies.id = '.$this->companyId,
566+
'tmdb_tv.companies.id = '.$this->companyId,
567567
];
568568
}
569569

570570
if ($this->networkId !== null) {
571-
$filters[] = 'tv.networks.id = '.$this->networkId;
571+
$filters[] = 'tmdb_tv.networks.id = '.$this->networkId;
572572
}
573573

574574
if ($this->primaryLanguageNames !== []) {
575575
$filters[] = [
576-
'movie.original_language IN '.json_encode(array_map('strval', $this->primaryLanguageNames)),
577-
'tv.original_language IN '.json_encode(array_map('strval', $this->primaryLanguageNames)),
576+
'tmdb_movie.original_language IN '.json_encode(array_map('strval', $this->primaryLanguageNames)),
577+
'tmdb_tv.original_language IN '.json_encode(array_map('strval', $this->primaryLanguageNames)),
578578
];
579579
}
580580

@@ -650,8 +650,8 @@ final public function toMeilisearchFilter(): array
650650

651651
if ($this->userWished) {
652652
$filters[] = [
653-
'movie.wishes.user_id = '.$this->user->id,
654-
'tv.wishes.user_id = '.$this->user->id,
653+
'tmdb_movie.wishes.user_id = '.$this->user->id,
654+
'tmdb_tv.wishes.user_id = '.$this->user->id,
655655
];
656656
}
657657

app/Helpers/Helpers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function href_playlist(App\Models\Playlist $playlist): string
7575
}
7676

7777
if (!\function_exists('href_collection')) {
78-
function href_collection(App\Models\Collection $collection): string
78+
function href_collection(App\Models\TmdbCollection $collection): string
7979
{
8080
$appurl = appurl();
8181

app/Helpers/TorrentHelper.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
use App\Bots\IRCAnnounceBot;
3232
use App\Enums\ModerationStatus;
3333
use App\Models\AutomaticTorrentFreeleech;
34-
use App\Models\Movie;
34+
use App\Models\TmdbMovie;
3535
use App\Models\Scopes\ApprovedScope;
3636
use App\Models\Torrent;
37-
use App\Models\Tv;
37+
use App\Models\TmdbTv;
3838
use App\Models\User;
3939
use App\Notifications\NewUpload;
4040
use App\Notifications\NewWishListNotice;
@@ -79,15 +79,15 @@ public static function approveHelper(int $id): void
7979
switch (true) {
8080
case $torrent->category->movie_meta:
8181
User::query()
82-
->whereRelation('wishes', 'movie_id', '=', $torrent->movie_id)
82+
->whereRelation('wishes', 'tmdb_movie_id', '=', $torrent->tmdb_movie_id)
8383
->get()
8484
->each
8585
->notify(new NewWishListNotice($torrent));
8686

8787
break;
8888
case $torrent->category->tv_meta:
8989
User::query()
90-
->whereRelation('wishes', 'tv_id', '=', $torrent->tv_id)
90+
->whereRelation('wishes', 'tmdb_tv_id', '=', $torrent->tmdb_tv_id)
9191
->get()
9292
->each
9393
->notify(new NewWishListNotice($torrent));
@@ -126,10 +126,10 @@ public static function approveHelper(int $id): void
126126
$meta = null;
127127
$category = $torrent->category;
128128

129-
if ($torrent->movie_id > 0 || $torrent->tv_id > 0) {
129+
if ($torrent->tmdb_movie_id > 0 || $torrent->tmdb_tv_id > 0) {
130130
$meta = match (true) {
131-
$category->tv_meta => Tv::find($torrent->tv_id),
132-
$category->movie_meta => Movie::find($torrent->movie_id),
131+
$category->tv_meta => TmdbTv::find($torrent->tmdb_tv_id),
132+
$category->movie_meta => TmdbMovie::find($torrent->tmdb_movie_id),
133133
default => null,
134134
};
135135
}

app/Http/Controllers/API/QuickSearchController.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function index(Request $request): \Illuminate\Http\JsonResponse
3737
'category.tv_meta = true',
3838
],
3939
[
40-
'movie.name EXISTS',
41-
'tv.name EXISTS',
40+
'tmdb_movie.name EXISTS',
41+
'tmdb_tv.name EXISTS',
4242
]
4343
];
4444

@@ -47,8 +47,8 @@ public function index(Request $request): \Illuminate\Http\JsonResponse
4747

4848
if (preg_match('/^(\d+)$/', $query, $matches)) {
4949
$filters[] = [
50-
'movie_id = '.$matches[1],
51-
'tv_id = '.$matches[1],
50+
'tmdb_movie_id = '.$matches[1],
51+
'tmdb_tv_id = '.$matches[1],
5252
];
5353
$searchById = true;
5454
}
@@ -85,14 +85,14 @@ public function index(Request $request): \Illuminate\Http\JsonResponse
8585
// Process the hits from the multiSearchResults
8686
foreach ($multiSearchResults['hits'] as $hit) {
8787
if ($hit['_federation']['indexUid'] === config('scout.prefix').'torrents') {
88-
$type = $hit['category']['movie_meta'] === true ? 'movie' : 'tv';
88+
$type = $hit['category']['movie_meta'] === true ? 'tmdb_movie' : 'tmdb_tv';
8989

9090
$results[] = [
9191
'id' => $hit['id'],
9292
'name' => $hit[$type]['name'],
9393
'year' => $hit[$type]['year'],
9494
'image' => $hit[$type]['poster'] ? tmdb_image('poster_small', $hit[$type]['poster']) : ($hit['name'][0] ?? '').($hit['name'][1] ?? ''),
95-
'url' => route('torrents.similar', ['category_id' => $hit['category']['id'], 'tmdb' => $hit['tmdb']]),
95+
'url' => route('torrents.similar', ['category_id' => $hit['category']['id'], 'tmdb' => $hit["{$type}_id"]]),
9696
'type' => $hit['category']['name'],
9797
];
9898
} elseif ($hit['_federation']['indexUid'] === config('scout.prefix').'people') {

0 commit comments

Comments
 (0)