From 751b9339f038d1cea0e37e5ff60008ab8ab98165 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?=
Date: Wed, 20 May 2026 22:31:41 +0300
Subject: [PATCH] feat: integrate Spotify API for syncing music productions
with new command and UI components
---
.env.example | 7 +
.../Commands/SyncSpotifyMusicProductions.php | 191 +++++++++++++
.../Pages/ListMusicProductions.php | 30 +++
.../Schemas/MusicProductionForm.php | 32 ++-
.../Tables/MusicProductionsTable.php | 16 +-
.../Controllers/MusicProductionController.php | 6 +-
app/Models/MusicProduction.php | 19 ++
app/Services/SpotifyService.php | 252 ++++++++++++++++++
config/services.php | 7 +
...tify_fields_to_music_productions_table.php | 41 +++
lang/en/music_productions.php | 26 ++
lang/tr/music_productions.php | 26 ++
.../front/music-productions/index.blade.php | 4 +-
.../front/music-productions/show.blade.php | 14 +-
routes/console.php | 4 +
15 files changed, 666 insertions(+), 9 deletions(-)
create mode 100644 app/Console/Commands/SyncSpotifyMusicProductions.php
create mode 100644 app/Services/SpotifyService.php
create mode 100644 database/migrations/2026_05_20_191947_add_spotify_fields_to_music_productions_table.php
diff --git a/.env.example b/.env.example
index 35db1dd..5150bcb 100644
--- a/.env.example
+++ b/.env.example
@@ -63,3 +63,10 @@ AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
+
+# Spotify Web API (Müzik Prodüksiyonları senkronizasyonu)
+# NOT: Developer Dashboard'da uygulamayı oluşturan Spotify hesabında Premium abonelik gerekir.
+SPOTIFY_CLIENT_ID=
+SPOTIFY_CLIENT_SECRET=
+SPOTIFY_ARTIST_ID=
+SPOTIFY_MARKET=TR
diff --git a/app/Console/Commands/SyncSpotifyMusicProductions.php b/app/Console/Commands/SyncSpotifyMusicProductions.php
new file mode 100644
index 0000000..b65a2fa
--- /dev/null
+++ b/app/Console/Commands/SyncSpotifyMusicProductions.php
@@ -0,0 +1,191 @@
+option('artist')) {
+ $spotifyService = new SpotifyService(
+ artistId: $this->option('artist'),
+ );
+ }
+
+ if (! $spotifyService->isConfigured()) {
+ $this->error(__('music_productions.spotify_not_configured'));
+
+ return Command::FAILURE;
+ }
+
+ $this->info(__('music_productions.spotify_sync_started'));
+
+ try {
+ $albumSummaries = $spotifyService->getArtistAlbums();
+ } catch (\Throwable $exception) {
+ $this->error($exception->getMessage());
+
+ return Command::FAILURE;
+ }
+
+ if (empty($albumSummaries)) {
+ $this->warn(__('music_productions.spotify_no_albums'));
+
+ return Command::SUCCESS;
+ }
+
+ $created = 0;
+ $updated = 0;
+ $dryRun = (bool) $this->option('dry-run');
+
+ foreach ($albumSummaries as $index => $albumSummary) {
+ $albumId = $albumSummary['id'] ?? null;
+
+ if (blank($albumId)) {
+ continue;
+ }
+
+ $album = $spotifyService->getAlbum($albumId) ?? $albumSummary;
+ $title = $album['name'] ?? __('music_productions.spotify_untitled_album');
+ $artistName = collect($album['artists'] ?? [])->pluck('name')->first();
+ $releaseDate = $this->parseReleaseDate($album['release_date'] ?? null, $album['release_date_precision'] ?? 'day');
+ $spotifyUrl = $album['external_urls']['spotify'] ?? null;
+ $coverUrl = collect($album['images'] ?? [])->first()['url'] ?? null;
+ $albumType = $album['album_type'] ?? 'album';
+
+ $production = $this->findMatchingProduction($albumId, $title);
+
+ $action = $production ? 'update' : 'create';
+ $this->line(sprintf(
+ '[%d/%d] %s: %s (%s)',
+ $index + 1,
+ count($albumSummaries),
+ $action === 'create' ? 'Yeni' : 'Güncelle',
+ $title,
+ $releaseDate?->format('Y-m-d') ?? '-'
+ ));
+
+ if ($dryRun) {
+ continue;
+ }
+
+ $attributes = [
+ 'spotify_album_id' => $albumId,
+ 'spotify_url' => $spotifyUrl,
+ 'spotify_cover_url' => $coverUrl,
+ 'spotify_type' => $albumType,
+ 'spotify_synced_at' => now(),
+ ];
+
+ if (! $production) {
+ $attributes['title'] = $title;
+ $attributes['slug'] = SpotifyService::uniqueSlug($title);
+ $attributes['client_name'] = $artistName;
+ $attributes['production_date'] = $releaseDate;
+ $attributes['content'] = $spotifyService->buildDefaultContent($album);
+ $attributes['is_active'] = true;
+ $attributes['sort_order'] = 0;
+
+ $coverPath = $spotifyService->downloadCoverImage($coverUrl, $albumId);
+ if ($coverPath) {
+ $attributes['cover_image'] = $coverPath;
+ }
+
+ MusicProduction::create($attributes);
+ $created++;
+
+ continue;
+ }
+
+ if (blank($production->title)) {
+ $attributes['title'] = $title;
+ }
+
+ if (blank($production->client_name) && filled($artistName)) {
+ $attributes['client_name'] = $artistName;
+ }
+
+ if (blank($production->production_date) && $releaseDate) {
+ $attributes['production_date'] = $releaseDate;
+ }
+
+ if (blank($production->content)) {
+ $attributes['content'] = $spotifyService->buildDefaultContent($album);
+ }
+
+ if (blank($production->cover_image) && filled($coverUrl)) {
+ $coverPath = $spotifyService->downloadCoverImage($coverUrl, $albumId);
+ if ($coverPath) {
+ $attributes['cover_image'] = $coverPath;
+ }
+ }
+
+ $production->update($attributes);
+ $updated++;
+
+ usleep(150000);
+ }
+
+ $message = __('music_productions.spotify_sync_completed', [
+ 'created' => $created,
+ 'updated' => $updated,
+ 'total' => count($albumSummaries),
+ ]);
+
+ $this->info($message);
+ Log::info('Spotify music productions sync completed', [
+ 'created' => $created,
+ 'updated' => $updated,
+ 'total' => count($albumSummaries),
+ 'dry_run' => $dryRun,
+ ]);
+
+ return Command::SUCCESS;
+ }
+
+ protected function findMatchingProduction(string $albumId, string $title): ?MusicProduction
+ {
+ $bySpotifyId = MusicProduction::withTrashed()
+ ->where('spotify_album_id', $albumId)
+ ->first();
+
+ if ($bySpotifyId) {
+ return $bySpotifyId->trashed() ? null : $bySpotifyId;
+ }
+
+ $slug = Str::slug($title);
+
+ $bySlug = MusicProduction::where('slug', '=', $slug, 'and')->first();
+ if ($bySlug) {
+ return $bySlug;
+ }
+
+ return MusicProduction::whereRaw('LOWER(title) = ?', [Str::lower($title)], 'and')->first();
+ }
+
+ protected function parseReleaseDate(?string $date, string $precision = 'day'): ?Carbon
+ {
+ if (blank($date)) {
+ return null;
+ }
+
+ return match ($precision) {
+ 'year' => Carbon::createFromFormat('Y', $date)->startOfYear(),
+ 'month' => Carbon::createFromFormat('Y-m', $date)->startOfMonth(),
+ default => Carbon::parse($date),
+ };
+ }
+}
diff --git a/app/Filament/Admin/Resources/MusicProductions/Pages/ListMusicProductions.php b/app/Filament/Admin/Resources/MusicProductions/Pages/ListMusicProductions.php
index 833fc92..634ffb4 100644
--- a/app/Filament/Admin/Resources/MusicProductions/Pages/ListMusicProductions.php
+++ b/app/Filament/Admin/Resources/MusicProductions/Pages/ListMusicProductions.php
@@ -2,9 +2,14 @@
namespace App\Filament\Admin\Resources\MusicProductions\Pages;
+use App\Console\Commands\SyncSpotifyMusicProductions;
use App\Filament\Admin\Resources\MusicProductions\MusicProductionResource;
+use App\Services\SpotifyService;
+use Filament\Actions\Action;
use Filament\Actions\CreateAction;
+use Filament\Notifications\Notification;
use Filament\Resources\Pages\ListRecords;
+use Illuminate\Support\Facades\Artisan;
class ListMusicProductions extends ListRecords
{
@@ -18,6 +23,31 @@ class ListMusicProductions extends ListRecords
protected function getHeaderActions(): array
{
return [
+ Action::make('syncSpotify')
+ ->label(__('music_productions.sync_spotify'))
+ ->icon('heroicon-o-arrow-path')
+ ->color('success')
+ ->requiresConfirmation()
+ ->modalHeading(__('music_productions.sync_spotify_heading'))
+ ->modalDescription(__('music_productions.sync_spotify_description'))
+ ->visible(fn (): bool => app(SpotifyService::class)->isConfigured())
+ ->action(function (): void {
+ $exitCode = Artisan::call(SyncSpotifyMusicProductions::class);
+
+ if ($exitCode !== 0) {
+ Notification::make()
+ ->title(__('music_productions.spotify_sync_failed'))
+ ->danger()
+ ->send();
+
+ return;
+ }
+
+ Notification::make()
+ ->title(__('music_productions.spotify_sync_success'))
+ ->success()
+ ->send();
+ }),
CreateAction::make()
->label(__('music_productions.create')),
];
diff --git a/app/Filament/Admin/Resources/MusicProductions/Schemas/MusicProductionForm.php b/app/Filament/Admin/Resources/MusicProductions/Schemas/MusicProductionForm.php
index a59436e..e363812 100644
--- a/app/Filament/Admin/Resources/MusicProductions/Schemas/MusicProductionForm.php
+++ b/app/Filament/Admin/Resources/MusicProductions/Schemas/MusicProductionForm.php
@@ -3,13 +3,16 @@
namespace App\Filament\Admin\Resources\MusicProductions\Schemas;
use App\Filament\Admin\Resources\Components\TranslationTabs;
+use App\Models\MusicProduction;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
+use Filament\Forms\Components\Placeholder;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
+use Illuminate\Support\Str;
class MusicProductionForm
{
@@ -30,7 +33,7 @@ class MusicProductionForm
if ($operation !== 'create') {
return;
}
- $set('slug', \Str::slug($state));
+ $set('slug', Str::slug($state));
}),
TextInput::make('slug')
@@ -93,6 +96,33 @@ class MusicProductionForm
])
->columnSpan(1)
->collapsible(false),
+
+ Section::make(__('music_productions.spotify_section'))
+ ->schema([
+ Placeholder::make('spotify_album_id_display')
+ ->label(__('music_productions.spotify_album_id_field'))
+ ->content(fn (?MusicProduction $record): string => $record?->spotify_album_id ?? '-'),
+
+ Placeholder::make('spotify_type_display')
+ ->label(__('music_productions.spotify_type_field'))
+ ->content(fn (?MusicProduction $record): string => $record?->spotify_type
+ ? __('music_productions.spotify_type_' . $record->spotify_type, [], $record->spotify_type)
+ : '-'),
+
+ Placeholder::make('spotify_url_display')
+ ->label(__('music_productions.spotify_url_field'))
+ ->content(fn (?MusicProduction $record): string => $record?->spotify_url ?? '-'),
+
+ Placeholder::make('spotify_synced_at_display')
+ ->label(__('music_productions.spotify_synced_at_field'))
+ ->content(fn (?MusicProduction $record): string => $record?->spotify_synced_at
+ ?->timezone(config('app.timezone'))
+ ->format('d.m.Y H:i') ?? '-'),
+ ])
+ ->columnSpanFull()
+ ->collapsible(true)
+ ->collapsed(true)
+ ->visible(fn (?MusicProduction $record): bool => filled($record?->spotify_album_id)),
// Alt Kısım - Galeri Görselleri
Section::make(__('music_productions.gallery_field'))
diff --git a/app/Filament/Admin/Resources/MusicProductions/Tables/MusicProductionsTable.php b/app/Filament/Admin/Resources/MusicProductions/Tables/MusicProductionsTable.php
index e9d88c0..f824420 100644
--- a/app/Filament/Admin/Resources/MusicProductions/Tables/MusicProductionsTable.php
+++ b/app/Filament/Admin/Resources/MusicProductions/Tables/MusicProductionsTable.php
@@ -2,6 +2,7 @@
namespace App\Filament\Admin\Resources\MusicProductions\Tables;
+use App\Models\MusicProduction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
@@ -21,7 +22,7 @@ class MusicProductionsTable
->columns([
ImageColumn::make('cover_image')
->label(__('music_productions.cover_image_field'))
- ->disk('public')
+ ->getStateUsing(fn (MusicProduction $record): ?string => $record->cover_image_url)
->square()
->size(60),
@@ -47,6 +48,19 @@ class MusicProductionsTable
->label(__('music_productions.table_production_date'))
->date('d.m.Y')
->sortable(),
+
+ TextColumn::make('spotify_type')
+ ->label(__('music_productions.spotify_type_field'))
+ ->badge()
+ ->formatStateUsing(fn (?string $state): string => filled($state)
+ ? __('music_productions.spotify_type_' . $state, [], $state)
+ : '-')
+ ->color(fn (?string $state): string => match ($state) {
+ 'single' => 'info',
+ 'album' => 'success',
+ default => 'gray',
+ })
+ ->toggleable(),
ToggleColumn::make('is_active')
->label(__('music_productions.table_is_active'))
diff --git a/app/Http/Controllers/MusicProductionController.php b/app/Http/Controllers/MusicProductionController.php
index f7a5a7e..e28093d 100644
--- a/app/Http/Controllers/MusicProductionController.php
+++ b/app/Http/Controllers/MusicProductionController.php
@@ -15,7 +15,7 @@ class MusicProductionController extends Controller
{
// Get Settings
$settings = new \stdClass();
- $allSettings = Setting::where('is_active', true)->get();
+ $allSettings = Setting::where('is_active', '=', true, 'and')->get();
foreach ($allSettings as $setting) {
$settings->{$setting->key} = $setting->value;
}
@@ -78,7 +78,7 @@ class MusicProductionController extends Controller
// Get Settings
$settings = new \stdClass();
- $allSettings = Setting::where('is_active', true)->get();
+ $allSettings = Setting::where('is_active', '=', true, 'and')->get();
foreach ($allSettings as $setting) {
$settings->{$setting->key} = $setting->value;
}
@@ -147,7 +147,7 @@ class MusicProductionController extends Controller
$meta = [
'title' => $production->translate('title'),
'description' => \Str::limit(strip_tags($production->translate('content')), 160),
- 'image' => $production->cover_image ? asset('storage/' . $production->cover_image) : null,
+ 'image' => $production->cover_image_url,
];
return view('front.music-productions.show', compact('production', 'prev', 'next', 'settings', 'renderedHeader', 'renderedFooter', 'meta'));
diff --git a/app/Models/MusicProduction.php b/app/Models/MusicProduction.php
index c381d84..41f6672 100644
--- a/app/Models/MusicProduction.php
+++ b/app/Models/MusicProduction.php
@@ -16,6 +16,11 @@ class MusicProduction extends Model
protected $fillable = [
'title',
'slug',
+ 'spotify_album_id',
+ 'spotify_url',
+ 'spotify_cover_url',
+ 'spotify_type',
+ 'spotify_synced_at',
'cover_image',
'content',
'client_name',
@@ -36,6 +41,7 @@ class MusicProduction extends Model
protected $casts = [
'production_date' => 'date',
+ 'spotify_synced_at' => 'datetime',
'gallery' => 'array',
'is_active' => 'boolean',
'sort_order' => 'integer',
@@ -51,10 +57,23 @@ class MusicProduction extends Model
if ($this->cover_image) {
return asset('storage/' . $this->cover_image);
}
+
+ if ($this->spotify_cover_url) {
+ return $this->spotify_cover_url;
+ }
return null;
}
+ public function getDisplayCoverImageAttribute(): ?string
+ {
+ if ($this->cover_image) {
+ return $this->cover_image;
+ }
+
+ return null;
+ }
+
public function scopeActive($query)
{
return $query->where('is_active', true);
diff --git a/app/Services/SpotifyService.php b/app/Services/SpotifyService.php
new file mode 100644
index 0000000..2ba0a6b
--- /dev/null
+++ b/app/Services/SpotifyService.php
@@ -0,0 +1,252 @@
+clientId = $clientId ?? config('services.spotify.client_id');
+ $this->clientSecret = $clientSecret ?? config('services.spotify.client_secret');
+ $this->artistId = $artistId ?? config('services.spotify.artist_id');
+ }
+
+ public function isConfigured(): bool
+ {
+ return filled($this->clientId)
+ && filled($this->clientSecret)
+ && filled($this->artistId);
+ }
+
+ public function getArtistId(): ?string
+ {
+ return $this->artistId;
+ }
+
+ /**
+ * @return array>
+ */
+ public function getArtistAlbums(string $includeGroups = 'album,single'): array
+ {
+ $this->authenticate();
+
+ $albums = [];
+ $url = "https://api.spotify.com/v1/artists/{$this->artistId}/albums";
+ $params = [
+ 'include_groups' => $includeGroups,
+ 'limit' => 50,
+ 'market' => config('services.spotify.market', 'TR'),
+ ];
+
+ do {
+ $response = $this->client()->get($url, $params);
+
+ if ($response->failed()) {
+ Log::error('Spotify artist albums fetch failed', [
+ 'status' => $response->status(),
+ 'body' => $response->body(),
+ ]);
+
+ throw new \RuntimeException($this->formatApiError(
+ __('music_productions.spotify_albums_fetch_failed'),
+ $response
+ ));
+ }
+
+ $data = $response->json();
+ $items = $data['items'] ?? [];
+
+ foreach ($items as $item) {
+ $albums[$item['id']] = $item;
+ }
+
+ $url = $data['next'] ?? null;
+ $params = [];
+ } while ($url);
+
+ return array_values($albums);
+ }
+
+ /**
+ * @return array|null
+ */
+ public function getAlbum(string $albumId): ?array
+ {
+ $this->authenticate();
+
+ $response = $this->client()->get("https://api.spotify.com/v1/albums/{$albumId}", [
+ 'market' => config('services.spotify.market', 'TR'),
+ ]);
+
+ if ($response->failed()) {
+ Log::warning('Spotify album fetch failed', [
+ 'album_id' => $albumId,
+ 'status' => $response->status(),
+ 'body' => $response->body(),
+ ]);
+
+ return null;
+ }
+
+ return $response->json();
+ }
+
+ public function downloadCoverImage(?string $imageUrl, string $albumId): ?string
+ {
+ if (blank($imageUrl)) {
+ return null;
+ }
+
+ try {
+ $response = Http::timeout(30)->get($imageUrl);
+
+ if ($response->failed()) {
+ return null;
+ }
+
+ $extension = $this->guessImageExtension($response->header('Content-Type'));
+ $path = 'music-productions/covers/spotify-' . $albumId . '.' . $extension;
+
+ Storage::disk('public')->put($path, $response->body());
+
+ return $path;
+ } catch (\Throwable $exception) {
+ Log::warning('Spotify cover download failed', [
+ 'album_id' => $albumId,
+ 'message' => $exception->getMessage(),
+ ]);
+
+ return null;
+ }
+ }
+
+ public function buildDefaultContent(array $album): string
+ {
+ $title = e($album['name'] ?? '');
+ $spotifyUrl = e($album['external_urls']['spotify'] ?? '');
+ $artistNames = collect($album['artists'] ?? [])
+ ->pluck('name')
+ ->filter()
+ ->implode(', ');
+ $artistNames = e($artistNames);
+ $albumType = e($album['album_type'] ?? 'album');
+ $totalTracks = (int) ($album['total_tracks'] ?? 0);
+
+ $listenLabel = e(__('music_productions.spotify_listen_on_spotify'));
+
+ return <<{$title} — {$artistNames}
+{$albumType} · {$totalTracks} {$this->trackLabel($totalTracks)}
+{$listenLabel}
+HTML;
+ }
+
+ protected function trackLabel(int $count): string
+ {
+ return $count === 1
+ ? __('music_productions.spotify_track_singular')
+ : __('music_productions.spotify_track_plural');
+ }
+
+ protected function authenticate(): void
+ {
+ if ($this->accessToken) {
+ return;
+ }
+
+ if (! $this->isConfigured()) {
+ throw new \RuntimeException(__('music_productions.spotify_not_configured'));
+ }
+
+ $response = Http::asForm()
+ ->withHeaders([
+ 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret),
+ ])
+ ->post('https://accounts.spotify.com/api/token', [
+ 'grant_type' => 'client_credentials',
+ ]);
+
+ if ($response->failed()) {
+ Log::error('Spotify access token request failed', [
+ 'status' => $response->status(),
+ 'body' => $response->body(),
+ ]);
+
+ throw new \RuntimeException($this->formatApiError(
+ __('music_productions.spotify_token_failed'),
+ $response
+ ));
+ }
+
+ $this->accessToken = $response->json('access_token');
+ }
+
+ protected function client(): PendingRequest
+ {
+ return Http::withToken($this->accessToken)
+ ->acceptJson()
+ ->timeout(30);
+ }
+
+ protected function formatApiError(string $fallback, \Illuminate\Http\Client\Response $response): string
+ {
+ $body = trim($response->body());
+ $message = $body;
+
+ if (str_starts_with($body, '{')) {
+ $message = $response->json('error.message')
+ ?? $response->json('error_description')
+ ?? $body;
+ }
+
+ if (blank($message)) {
+ return $fallback;
+ }
+
+ if ($response->status() === 403 && str_contains(strtolower($message), 'premium')) {
+ return __('music_productions.spotify_premium_required', ['detail' => $message]);
+ }
+
+ return $fallback . ' (HTTP ' . $response->status() . ': ' . $message . ')';
+ }
+
+ protected function guessImageExtension(?string $contentType): string
+ {
+ return match ($contentType) {
+ 'image/png' => 'png',
+ 'image/webp' => 'webp',
+ 'image/gif' => 'gif',
+ default => 'jpg',
+ };
+ }
+
+ public static function uniqueSlug(string $title, ?int $ignoreId = null): string
+ {
+ $baseSlug = Str::slug($title) ?: 'spotify-album';
+ $slug = $baseSlug;
+ $counter = 1;
+
+ while (
+ \App\Models\MusicProduction::withTrashed()
+ ->when($ignoreId, fn ($query) => $query->where('id', '!=', $ignoreId))
+ ->where('slug', $slug)
+ ->exists()
+ ) {
+ $slug = $baseSlug . '-' . $counter;
+ $counter++;
+ }
+
+ return $slug;
+ }
+}
diff --git a/config/services.php b/config/services.php
index 992cfd8..989a2ef 100644
--- a/config/services.php
+++ b/config/services.php
@@ -43,4 +43,11 @@ return [
'access_key' => env('UNSPLASH_ACCESS_KEY'),
],
+ 'spotify' => [
+ 'client_id' => env('SPOTIFY_CLIENT_ID'),
+ 'client_secret' => env('SPOTIFY_CLIENT_SECRET'),
+ 'artist_id' => env('SPOTIFY_ARTIST_ID'),
+ 'market' => env('SPOTIFY_MARKET', 'TR'),
+ ],
+
];
diff --git a/database/migrations/2026_05_20_191947_add_spotify_fields_to_music_productions_table.php b/database/migrations/2026_05_20_191947_add_spotify_fields_to_music_productions_table.php
new file mode 100644
index 0000000..f726cc3
--- /dev/null
+++ b/database/migrations/2026_05_20_191947_add_spotify_fields_to_music_productions_table.php
@@ -0,0 +1,41 @@
+string('spotify_album_id')->nullable()->unique()->after('slug');
+ $table->string('spotify_url')->nullable()->after('spotify_album_id');
+ $table->string('spotify_cover_url')->nullable()->after('spotify_url');
+ $table->string('spotify_type')->nullable()->after('spotify_cover_url');
+ $table->timestamp('spotify_synced_at')->nullable()->after('spotify_type');
+
+ $table->index('spotify_album_id');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('music_productions', function (Blueprint $table) {
+ $table->dropIndex(['spotify_album_id']);
+ $table->dropColumn([
+ 'spotify_album_id',
+ 'spotify_url',
+ 'spotify_cover_url',
+ 'spotify_type',
+ 'spotify_synced_at',
+ ]);
+ });
+ }
+};
diff --git a/lang/en/music_productions.php b/lang/en/music_productions.php
index 598ddd3..b590c55 100644
--- a/lang/en/music_productions.php
+++ b/lang/en/music_productions.php
@@ -75,4 +75,30 @@ return [
'title_required' => 'Title field is required.',
'slug_required' => 'URL slug field is required.',
'slug_unique' => 'This URL slug is already in use.',
+
+ // Spotify
+ 'spotify_section' => 'Spotify Information',
+ 'spotify_album_id_field' => 'Spotify Album ID',
+ 'spotify_url_field' => 'Spotify URL',
+ 'spotify_type_field' => 'Spotify Type',
+ 'spotify_synced_at_field' => 'Last Spotify Sync',
+ 'spotify_type_album' => 'Album',
+ 'spotify_type_single' => 'Single',
+ 'spotify_type_compilation' => 'Compilation',
+ 'spotify_listen_on_spotify' => 'Listen on Spotify',
+ 'spotify_track_singular' => 'track',
+ 'spotify_track_plural' => 'tracks',
+ 'sync_spotify' => 'Sync from Spotify',
+ 'sync_spotify_heading' => 'Spotify Sync',
+ 'sync_spotify_description' => 'Albums and singles from your artist account will be synced to music productions. Existing records are updated by title match, new records are created.',
+ 'spotify_sync_started' => 'Starting Spotify sync...',
+ 'spotify_sync_completed' => 'Sync completed. :created created, :updated updated (:total total).',
+ 'spotify_sync_success' => 'Spotify sync completed successfully.',
+ 'spotify_sync_failed' => 'Spotify sync failed. Check the logs.',
+ 'spotify_not_configured' => 'Spotify API credentials are missing. Set SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET and SPOTIFY_ARTIST_ID in your .env file.',
+ 'spotify_token_failed' => 'Failed to obtain Spotify access token.',
+ 'spotify_albums_fetch_failed' => 'Failed to fetch Spotify album list.',
+ 'spotify_premium_required' => 'The Spotify account that owns the Developer app needs an active Premium subscription. Sign in to Spotify Developer Dashboard with that account, upgrade to Premium, and wait a few hours. Detail: :detail',
+ 'spotify_no_albums' => 'No albums or singles found on the Spotify artist account.',
+ 'spotify_untitled_album' => 'Untitled Album',
];
diff --git a/lang/tr/music_productions.php b/lang/tr/music_productions.php
index bf46fe4..244a443 100644
--- a/lang/tr/music_productions.php
+++ b/lang/tr/music_productions.php
@@ -75,4 +75,30 @@ return [
'title_required' => 'Başlık alanı zorunludur.',
'slug_required' => 'URL yolu alanı zorunludur.',
'slug_unique' => 'Bu URL yolu zaten kullanılıyor.',
+
+ // Spotify
+ 'spotify_section' => 'Spotify Bilgileri',
+ 'spotify_album_id_field' => 'Spotify Albüm ID',
+ 'spotify_url_field' => 'Spotify URL',
+ 'spotify_type_field' => 'Spotify Türü',
+ 'spotify_synced_at_field' => 'Son Spotify Senkronizasyonu',
+ 'spotify_type_album' => 'Albüm',
+ 'spotify_type_single' => 'Single',
+ 'spotify_type_compilation' => 'Derleme',
+ 'spotify_listen_on_spotify' => 'Spotify\'da Dinle',
+ 'spotify_track_singular' => 'parça',
+ 'spotify_track_plural' => 'parça',
+ 'sync_spotify' => 'Spotify\'dan Senkronize Et',
+ 'sync_spotify_heading' => 'Spotify Senkronizasyonu',
+ 'sync_spotify_description' => 'Sanatçı hesabınızdaki albüm ve single kayıtları müzik prodüksiyonlarına aktarılacak. Mevcut kayıtlar başlık eşleşmesine göre güncellenir, yeni kayıtlar oluşturulur.',
+ 'spotify_sync_started' => 'Spotify senkronizasyonu başlıyor...',
+ 'spotify_sync_completed' => 'Senkronizasyon tamamlandı. :created yeni, :updated güncellendi (toplam :total).',
+ 'spotify_sync_success' => 'Spotify senkronizasyonu başarıyla tamamlandı.',
+ 'spotify_sync_failed' => 'Spotify senkronizasyonu başarısız oldu. Logları kontrol edin.',
+ 'spotify_not_configured' => 'Spotify API bilgileri eksik. .env dosyasında SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET ve SPOTIFY_ARTIST_ID değerlerini tanımlayın.',
+ 'spotify_token_failed' => 'Spotify access token alınamadı.',
+ 'spotify_albums_fetch_failed' => 'Spotify albüm listesi alınamadı.',
+ 'spotify_premium_required' => 'Spotify Developer uygulamasını oluşturan hesapta aktif Premium abonelik gerekli. Spotify Developer Dashboard\'da uygulamayı oluşturan hesapla giriş yapın, Premium\'a geçin ve birkaç saat bekleyin. Detay: :detail',
+ 'spotify_no_albums' => 'Spotify sanatçı hesabında albüm veya single bulunamadı.',
+ 'spotify_untitled_album' => 'İsimsiz Albüm',
];
diff --git a/resources/views/front/music-productions/index.blade.php b/resources/views/front/music-productions/index.blade.php
index 46f989b..0f3d04e 100644
--- a/resources/views/front/music-productions/index.blade.php
+++ b/resources/views/front/music-productions/index.blade.php
@@ -38,8 +38,8 @@