[#2] some progress

This commit is contained in:
2025-01-09 16:01:38 +02:00
parent 300c2574ea
commit bbd082fd8f
11 changed files with 265 additions and 8 deletions
@@ -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'],
+30
View File
@@ -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',
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProductionCompany extends Model
{
protected $fillable = [
'tmdb_id',
'logo_path',
'name',
'origin_country',
];
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProductionCountry extends Model
{
protected $fillable = [
'iso_3166',
'name',
];
}
+10
View File
@@ -80,4 +80,14 @@ class Show extends Model
{
return $this->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');
}
}
@@ -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'];
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);
}
}
}
}
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('production_companies', function (Blueprint $table) {
$table->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');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('production_countries', function (Blueprint $table) {
$table->id();
$table->string('iso_3166')->nullable();
$table->string('name')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('production_countries');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('show_production_companies', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('show_id');
$table->unsignedBigInteger('production_company_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('show_production_companies');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('show_production_countries', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('show_id');
$table->unsignedBigInteger('production_country_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('show_production_countries');
}
};
Binary file not shown.