diff --git a/app/Enums/Models/Wiki/ResourceSite.php b/app/Enums/Models/Wiki/ResourceSite.php index c425b5ff9..3976486d0 100644 --- a/app/Enums/Models/Wiki/ResourceSite.php +++ b/app/Enums/Models/Wiki/ResourceSite.php @@ -222,11 +222,11 @@ public function formatArtistResourceLink(int $id, ?string $slug = null): ?string public function formatSongResourceLink(int $id, ?string $slug = null): ?string { return match ($this) { - ResourceSite::SPOTIFY->value => "https://open.spotify.com/track/$slug", - ResourceSite::YOUTUBE_MUSIC->value => "https://music.youtube.com/watch?v=$slug", - ResourceSite::YOUTUBE->value => "https://youtube.com/watch?v=$slug", - ResourceSite::APPLE_MUSIC->value => "https://music.apple.com/jp/album/$id", - ResourceSite::AMAZON_MUSIC->value => "https://amazon.co.jp/music/player/albums/$slug", + ResourceSite::SPOTIFY => "https://open.spotify.com/track/$slug", + ResourceSite::YOUTUBE_MUSIC => "https://music.youtube.com/watch?v=$slug", + ResourceSite::YOUTUBE => "https://www.youtube.com/watch?v=$slug", + ResourceSite::APPLE_MUSIC => "https://music.apple.com/jp/album/$id", + ResourceSite::AMAZON_MUSIC => "https://amazon.co.jp/music/player/albums/$slug", default => null }; } diff --git a/app/Http/Api/Schema/Wiki/AnimeSchema.php b/app/Http/Api/Schema/Wiki/AnimeSchema.php index eea017d5e..5357c0d43 100644 --- a/app/Http/Api/Schema/Wiki/AnimeSchema.php +++ b/app/Http/Api/Schema/Wiki/AnimeSchema.php @@ -79,6 +79,8 @@ public function allowedIncludes(): array new AllowedInclude(new VideoSchema(), 'animethemes.animethemeentries.videos.animethemeentries.animetheme.animethemeentries.videos'), new AllowedInclude(new AudioSchema(), 'animethemes.animethemeentries.videos.animethemeentries.animetheme.animethemeentries.videos.audio'), new AllowedInclude(new ArtistSchema(), 'animethemes.animethemeentries.videos.animethemeentries.animetheme.song.artists'), + new AllowedInclude(new ExternalResourceSchema(), 'animethemes.animethemeentries.videos.animethemeentries.animetheme.song.resources'), + new AllowedInclude(new ExternalResourceSchema(), 'animethemes.song.resources'), new AllowedInclude(new ImageSchema(), 'animethemes.song.artists.images'), ]; } diff --git a/app/Http/Api/Schema/Wiki/ArtistSchema.php b/app/Http/Api/Schema/Wiki/ArtistSchema.php index 5278a10f0..a4c48bfd9 100644 --- a/app/Http/Api/Schema/Wiki/ArtistSchema.php +++ b/app/Http/Api/Schema/Wiki/ArtistSchema.php @@ -71,6 +71,7 @@ public function allowedIncludes(): array // Undocumented paths needed for client builds new AllowedInclude(new ArtistSchema(), 'groups.songs.artists'), new AllowedInclude(new ImageSchema(), 'groups.songs.animethemes.anime.images'), + new AllowedInclude(new ExternalResourceSchema(), 'groups.songs.resources'), new AllowedInclude(new ArtistSchema(), 'songs.artists'), new AllowedInclude(new SongSchema(), 'songs.animethemes.song'), new AllowedInclude(new ArtistSchema(), 'songs.animethemes.song.artists'), @@ -78,6 +79,7 @@ public function allowedIncludes(): array new AllowedInclude(new EntrySchema(), 'songs.animethemes.animethemeentries'), new AllowedInclude(new VideoSchema(), 'songs.animethemes.animethemeentries.videos'), new AllowedInclude(new AudioSchema(), 'songs.animethemes.animethemeentries.videos.audio'), + new AllowedInclude(new ExternalResourceSchema(), 'songs.resources'), ]; } diff --git a/app/Http/Api/Schema/Wiki/SongSchema.php b/app/Http/Api/Schema/Wiki/SongSchema.php index 6f87b6e61..8c44ccf02 100644 --- a/app/Http/Api/Schema/Wiki/SongSchema.php +++ b/app/Http/Api/Schema/Wiki/SongSchema.php @@ -12,8 +12,10 @@ use App\Http\Api\Include\AllowedInclude; use App\Http\Api\Schema\EloquentSchema; use App\Http\Api\Schema\Pivot\Wiki\ArtistSongSchema; +use App\Http\Api\Schema\Pivot\Wiki\SongResourceSchema; use App\Http\Api\Schema\Wiki\Anime\ThemeSchema; use App\Http\Resources\Pivot\Wiki\Resource\ArtistSongResource; +use App\Http\Resources\Pivot\Wiki\Resource\SongResourceResource; use App\Http\Resources\Wiki\Resource\SongResource; use App\Models\Wiki\Song; @@ -31,6 +33,7 @@ public function allowedPivots(): array { return [ new AllowedInclude(new ArtistSongSchema(), ArtistSongResource::$wrap), + new AllowedInclude(new SongResourceSchema(), SongResourceResource::$wrap) ]; } diff --git a/database/seeders/Wiki/Anime/AnimeFormatAnilistSeeder.php b/database/seeders/Wiki/Anime/AnimeFormatAnilistSeeder.php new file mode 100644 index 000000000..afe8e777b --- /dev/null +++ b/database/seeders/Wiki/Anime/AnimeFormatAnilistSeeder.php @@ -0,0 +1,83 @@ +anilistSeeder(); + } + + protected function anilistSeeder(): void + { + $query = ' + query ($id: Int) { + Media (id: $id, type: ANIME) { + format + } + } + '; + + $chunkSize = 10; + $animes = Anime::query()->where(Anime::ATTRIBUTE_MEDIA_FORMAT, null)->get(); + + foreach ($animes->chunk($chunkSize) as $chunk) { + foreach ($chunk as $anime) { + $resource = $anime->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST->value); + + if ($resource instanceof ExternalResource) { + $variables = [ + 'id' => $resource->external_id + ]; + + $response = Http::post('https://graphql.anilist.co', [ + 'query' => $query, + 'variables' => $variables + ]); + + $format = Arr::get($response, 'data.Media.format'); + + if ($format !== null) { + if (in_array($format, ['TV', 'TV_SHORT', 'MOVIE'], true)) { + $formats = [ + 'TV' => AnimeMediaFormat::TV->value, + 'TV_SHORT' => AnimeMediaFormat::TV_SHORT->value, + 'MOVIE' => AnimeMediaFormat::MOVIE->value + ]; + + $anime->update([ + Anime::ATTRIBUTE_MEDIA_FORMAT => $formats[$format] + ]); + echo $format; + echo ' -> '; + echo $anime->name; + echo "\n"; + } else { + echo 'no format include -> '; + echo $anime->name; + echo "\n"; + } + } else { + echo 'format null'; + echo "\n"; + } + } + } + sleep(5); + } + } +} diff --git a/database/seeders/Wiki/AnimeFormatSeeder.php b/database/seeders/Wiki/Anime/AnimeFormatMalSeeder.php similarity index 53% rename from database/seeders/Wiki/AnimeFormatSeeder.php rename to database/seeders/Wiki/Anime/AnimeFormatMalSeeder.php index 3685007d5..e41c4b945 100644 --- a/database/seeders/Wiki/AnimeFormatSeeder.php +++ b/database/seeders/Wiki/Anime/AnimeFormatMalSeeder.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Database\Seeders\Wiki; +namespace Database\Seeders\Wiki\Anime; use App\Enums\Models\Wiki\AnimeMediaFormat; use App\Enums\Models\Wiki\ResourceSite; @@ -13,14 +13,13 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Http; -class AnimeFormatSeeder extends Seeder +class AnimeFormatMalSeeder extends Seeder { /** * Run the database seeds. */ public function run(): void { - //$this->anilistSeeder(); $this->malSeeder(); } @@ -73,63 +72,4 @@ protected function malSeeder(): void sleep(5); } } - - protected function anilistSeeder(): void - { - $query = ' - query ($id: Int) { - Media (id: $id, type: ANIME) { - format - } - } - '; - - $chunkSize = 10; - $animes = Anime::query()->where(Anime::ATTRIBUTE_MEDIA_FORMAT, null)->get(); - - foreach ($animes->chunk($chunkSize) as $chunk) { - foreach ($chunk as $anime) { - $resource = $anime->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST->value); - - if ($resource instanceof ExternalResource) { - $variables = [ - 'id' => $resource->external_id - ]; - - $response = Http::post('https://graphql.anilist.co', [ - 'query' => $query, - 'variables' => $variables - ]); - - $format = Arr::get($response, 'data.Media.format'); - - if ($format !== null) { - if (in_array($format, ['TV', 'TV_SHORT', 'MOVIE'], true)) { - $formats = [ - 'TV' => AnimeMediaFormat::TV->value, - 'TV_SHORT' => AnimeMediaFormat::TV_SHORT->value, - 'MOVIE' => AnimeMediaFormat::MOVIE->value - ]; - - $anime->update([ - Anime::ATTRIBUTE_MEDIA_FORMAT => $formats[$format] - ]); - echo $format; - echo ' -> '; - echo $anime->name; - echo "\n"; - } else { - echo 'no format include -> '; - echo $anime->name; - echo "\n"; - } - } else { - echo 'format null'; - echo "\n"; - } - } - } - sleep(5); - } - } }