[#1] added translations

This commit is contained in:
2024-12-30 03:01:12 +02:00
parent 3d7e0295ae
commit 89432548bd
3 changed files with 93 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Translation extends Model
{
protected $fillable = [
'movie_id',
'iso_3166',
'iso_639',
'name',
'english_name',
'homepage',
'overview',
'runtime',
'tagline',
'title',
];
}
@@ -11,6 +11,7 @@ use App\Models\MovieAlternativeTitle;
use App\Models\MovieCollection; use App\Models\MovieCollection;
use App\Models\Person; use App\Models\Person;
use App\Models\ReleaseDate; use App\Models\ReleaseDate;
use App\Models\Translation;
use App\Service\TMDBApi\MoviesApi; use App\Service\TMDBApi\MoviesApi;
use App\Service\TMDBApi\PersonApi; use App\Service\TMDBApi\PersonApi;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@@ -228,6 +229,40 @@ class MovieProcessingService implements ProcessingInterface
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_RELEASES); $this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_RELEASES);
} }
private function getTranslations($item)
{
$tmdbMovieTranslations = $this->moviesApi->getTranslations($item->tmdb_id);
if (!$tmdbMovieTranslations || !isset($tmdbMovieTranslations['translations'])) {
return;
}
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
foreach ($tmdbMovieTranslations['translations'] as $tmdbTranslation) {
$existingTranslation = Translation::where('movie_id', $movie->id)
->where('name', $tmdbTranslation['name'])
->first();
if (!$existingTranslation) {
Translation::create([
'movie_id' => $movie->id,
'iso_3166' => $tmdbTranslation['iso_3166_1'],
'iso_639' => $tmdbTranslation['iso_639_1'],
'name' => $tmdbTranslation['name'],
'english_name' => $tmdbTranslation['english_name'],
'homepage' => $tmdbTranslation['data']['homepage'],
'overview' => $tmdbTranslation['data']['overview'],
'runtime' => $tmdbTranslation['data']['runtime'],
'tagline' => $tmdbTranslation['data']['tagline'],
'title' => $tmdbTranslation['data']['title'],
]);
}
}
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_TRANSLATIONS);
}
private function processMovieCollection(int $movieId, $belongsToCollection) private function processMovieCollection(int $movieId, $belongsToCollection)
{ {
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first(); $movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
@@ -0,0 +1,37 @@
<?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('translations', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('movie_id');
$table->string('iso_3166', 10);
$table->string('iso_639', 10);
$table->string('name');
$table->string('english_name');
$table->string('homepage', 500);
$table->text('overview');
$table->integer('runtime');
$table->string('tagline', 500);
$table->string('title', 500);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('translations');
}
};