mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
feat: new included paths to song resources (#604)
This commit is contained in:
@@ -222,11 +222,11 @@ enum ResourceSite: int
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,6 +79,8 @@ class AnimeSchema extends EloquentSchema implements InteractsWithPivots, Searcha
|
||||
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'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ class ArtistSchema extends EloquentSchema implements InteractsWithPivots, Search
|
||||
// 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 @@ class ArtistSchema extends EloquentSchema implements InteractsWithPivots, Search
|
||||
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'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@ use App\Http\Api\Field\Wiki\Song\SongTitleField;
|
||||
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 @@ class SongSchema extends EloquentSchema implements InteractsWithPivots, Searchab
|
||||
{
|
||||
return [
|
||||
new AllowedInclude(new ArtistSongSchema(), ArtistSongResource::$wrap),
|
||||
new AllowedInclude(new SongResourceSchema(), SongResourceResource::$wrap)
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Seeders\Wiki\Anime;
|
||||
|
||||
use App\Enums\Models\Wiki\AnimeMediaFormat;
|
||||
use App\Enums\Models\Wiki\ResourceSite;
|
||||
use App\Models\Wiki\Anime;
|
||||
use App\Models\Wiki\ExternalResource;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class AnimeFormatAnilistSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-62
@@ -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\Arr;
|
||||
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 @@ class AnimeFormatSeeder extends Seeder
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user