diff --git a/app/Console/Commands/TmdbFetch/FetchExportItemsCommand.php b/app/Console/Commands/TmdbFetch/FetchExportItemsCommand.php index 4fc5d65..c0ebeb5 100644 --- a/app/Console/Commands/TmdbFetch/FetchExportItemsCommand.php +++ b/app/Console/Commands/TmdbFetch/FetchExportItemsCommand.php @@ -70,11 +70,17 @@ class FetchExportItemsCommand extends Command if ($movie) { return; } + + $jobs = ItemToFetchJobs::MOVIE_JOBS; + $jobs[] = "Details"; } else { $show = Show::where('tmdb_id', $decodedLine['id'])->first(); if ($show) { return; } + + $jobs = ItemToFetchJobs::SHOW_JOBS; + $jobs[] = "Details"; } ItemToFetch::create([ @@ -82,8 +88,8 @@ class FetchExportItemsCommand extends Command 'type' => $type, ]); - $jobs = ItemToFetchJobs::JOBS; - $jobs[] = "Details"; +// $jobs = ItemToFetchJobs::JOBS; +// $jobs[] = "Details"; ItemToFetchJobs::create([ 'tmdb_id' => $decodedLine['id'], diff --git a/app/Models/ItemToFetchJobs.php b/app/Models/ItemToFetchJobs.php index 9f3eda8..731174e 100644 --- a/app/Models/ItemToFetchJobs.php +++ b/app/Models/ItemToFetchJobs.php @@ -41,6 +41,36 @@ class ItemToFetchJobs extends Model self::JOB_CONTENT_RATINGS, ]; + public const MOVIE_JOBS = [ + self::JOB_ALTERNVATIVE_TITLES, + self::JOB_CREDITS, + self::JOB_IMAGES, + self::JOB_KEYWORDS, + self::JOB_RELEASES, + self::JOB_TRANSLATIONS, + self::JOB_SIMILAR, + self::JOB_RECOMMNDATION, + self::JOB_REVIEWS, + self::JOB_LISTS, + self::JOB_VIDEOS, + self::JOB_WATCH_PROVIDERS, + self::JOB_EXTERNAL_IDS, + ]; + + public const SHOW_JOBS = [ + self::JOB_ALTERNVATIVE_TITLES, + self::JOB_CREDITS, + self::JOB_IMAGES, + self::JOB_KEYWORDS, + self::JOB_TRANSLATIONS, + self::JOB_SIMILAR, + self::JOB_RECOMMNDATION, + self::JOB_VIDEOS, + self::JOB_WATCH_PROVIDERS, + self::JOB_EXTERNAL_IDS, + self::JOB_CONTENT_RATINGS, + ]; + protected $fillable = [ 'tmdb_id', 'item_id', diff --git a/app/Models/ProductionCompany.php b/app/Models/ProductionCompany.php new file mode 100644 index 0000000..5e9cb76 --- /dev/null +++ b/app/Models/ProductionCompany.php @@ -0,0 +1,15 @@ +belongsToMany(Network::class, 'show_networks', 'show_id', 'network_id'); } + + public function productionCompanies() + { + return $this->belongsToMany(ProductionCompany::class, 'show_production_companies', 'show_id', 'production_company_id'); + } + + public function productionCountries() + { + return $this->belongsToMany(ProductionCountry::class, 'show_production_countries', 'show_id', 'production_country_id'); + } } diff --git a/app/Service/MediaProcessing/ShowProcessingService.php b/app/Service/MediaProcessing/ShowProcessingService.php index 39e7c61..c96a97f 100644 --- a/app/Service/MediaProcessing/ShowProcessingService.php +++ b/app/Service/MediaProcessing/ShowProcessingService.php @@ -13,6 +13,8 @@ use App\Models\ItemToFetchJobs; use App\Models\Keyword; use App\Models\Network; use App\Models\Person; +use App\Models\ProductionCompany; +use App\Models\ProductionCountry; use App\Models\Season; use App\Models\Show; use App\Models\ShowAlternativeTitle; @@ -60,18 +62,23 @@ class ShowProcessingService implements ProcessingInterface $show = Show::where('tmdb_id', $item->tmdb_id)->first(); if ($show) { + echo "+"; return; } - + echo "."; $tmdbShow['slug'] = Str::slug($tmdbShow['name'].'-'.$tmdbShow['tmdb_id']); $tmdbShow['first_air_date'] = $tmdbShow['first_air_date'] ? new \DateTime($tmdbShow['first_air_date']) : null; $tmdbShow['last_air_date'] = $tmdbShow['last_air_date'] ? new \DateTime($tmdbShow['last_air_date']) : null; - $tmdbShow['episode_run_time'] = reset($tmdbShow['episode_run_time']); - $tmdbShow['episode_run_time'] = reset($tmdbShow['episode_run_time']); + $tmdbShow['episode_run_time'] = is_array($tmdbShow['episode_run_time']) ? reset($tmdbShow['episode_run_time']) : $tmdbShow['episode_run_time']; $tmdbShow['languages'] = json_encode($tmdbShow['languages']); $tmdbShow['number_of_episodes'] = $tmdbShow['number_of_episodes'] ?? 0; + $tmdbShow['origin_country'] = is_array($tmdbShow['origin_country']) ? reset($tmdbShow['origin_country']) : $tmdbShow['origin_country']; - $show = Show::create($tmdbShow); + try { + $show = Show::create($tmdbShow); + } catch (\Throwable $e) { + dd($e, $tmdbShow); + } if (!empty($tmdbShow['seasons'])) { $this->processSeasons($show, $tmdbShow['seasons']); @@ -86,8 +93,16 @@ class ShowProcessingService implements ProcessingInterface } // @todo process created_by - // @todo process production countries - // @todo process production companies + + if (!empty($tmdbShow['production_countries'])) { + //dd('123'); + $this->processProductionCountries($item, $tmdbShow['production_countries']); + } + + if (!empty($tmdbShow['production_companies'])) { + //dd('456'); + $this->processProductionCompanies($item, $tmdbShow['production_companies']); + } $this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_DETAILS); } @@ -794,4 +809,54 @@ class ShowProcessingService implements ProcessingInterface } } } + + private function processProductionCompanies($item, array $productionCompanies) + { + $show = Show::where('tmdb_id', $item->tmdb_id)->first(); + + foreach ($productionCompanies as $productionCompany) { + $existingProductionCompany = ProductionCompany::where('tmdb_id', $productionCompany['id'])->first(); + + if (!$existingProductionCompany) { + $existingProductionCompany = ProductionCompany::create([ + 'tmdb_id' => $productionCompany['id'], + 'logo_path' => $productionCompany['logo_path'], + 'name' => $productionCompany['name'], + 'origin_country' => $productionCompany['origin_country'], + ]); + } + + if ($show->whereHas('productionCompanies', function ($query) use ($existingProductionCompany) { + $query->where('production_company_id', '=', $existingProductionCompany->id); + })->exists()) { + return; + } else { + $show->productionCompanies()->attach($existingProductionCompany); + } + } + } + + private function processProductionCountries($item, array $productionCountries) + { + $show = Show::where('tmdb_id', $item->tmdb_id)->first(); + + foreach ($productionCountries as $productionCountry) { + $existingProductionCountry = ProductionCountry::where('iso_3166', $productionCountry['iso_3166_1'])->first(); + + if (!$existingProductionCountry) { + $existingProductionCountry = ProductionCountry::create([ + 'iso_3166' => $productionCountry['iso_3166_1'], + 'name' => $productionCountry['name'], + ]); + } + + if ($show->whereHas('productionCountries', function ($query) use ($existingProductionCountry) { + $query->where('production_country_id', '=', $existingProductionCountry->id); + })->exists()) { + return; + } else { + $show->productionCountries()->attach($existingProductionCountry); + } + } + } } diff --git a/database/migrations/2025_01_08_010922_create_production_companies_table.php b/database/migrations/2025_01_08_010922_create_production_companies_table.php new file mode 100644 index 0000000..44a349d --- /dev/null +++ b/database/migrations/2025_01_08_010922_create_production_companies_table.php @@ -0,0 +1,31 @@ +id(); + $table->unsignedBigInteger('tmdb_id'); + $table->string('logo_path', 500)->nullable(); + $table->string('name')->nullable(); + $table->string('origin_country', 25)->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('production_companies'); + } +}; diff --git a/database/migrations/2025_01_08_010932_create_production_countries_table.php b/database/migrations/2025_01_08_010932_create_production_countries_table.php new file mode 100644 index 0000000..a028cca --- /dev/null +++ b/database/migrations/2025_01_08_010932_create_production_countries_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('iso_3166')->nullable(); + $table->string('name')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('production_countries'); + } +}; diff --git a/database/migrations/2025_01_08_011000_create_show_production_company_table.php b/database/migrations/2025_01_08_011000_create_show_production_company_table.php new file mode 100644 index 0000000..499e31b --- /dev/null +++ b/database/migrations/2025_01_08_011000_create_show_production_company_table.php @@ -0,0 +1,29 @@ +id(); + $table->unsignedBigInteger('show_id'); + $table->unsignedBigInteger('production_company_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('show_production_companies'); + } +}; diff --git a/database/migrations/2025_01_08_011005_create_show_production_country_table.php b/database/migrations/2025_01_08_011005_create_show_production_country_table.php new file mode 100644 index 0000000..f9f4dc9 --- /dev/null +++ b/database/migrations/2025_01_08_011005_create_show_production_country_table.php @@ -0,0 +1,29 @@ +id(); + $table->unsignedBigInteger('show_id'); + $table->unsignedBigInteger('production_country_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('show_production_countries'); + } +}; diff --git a/storage/tv_series_01_08_2025.json.gz b/storage/tv_series_01_08_2025.json.gz new file mode 100644 index 0000000..8111550 Binary files /dev/null and b/storage/tv_series_01_08_2025.json.gz differ