Skip to content

Commit

Permalink
feat: new resource sites (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrch authored Oct 31, 2023
1 parent 8c78992 commit b39c321
Show file tree
Hide file tree
Showing 22 changed files with 591 additions and 11 deletions.
34 changes: 34 additions & 0 deletions app/Enums/Models/Wiki/ResourceSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ enum ResourceSite: int
// Compendia
case WIKI = 8;

// Song Resources
case SPOTIFY = 9;
case YOUTUBE_MUSIC = 10;
case YOUTUBE = 11;
case APPLE_MUSIC = 12;
case AMAZON_MUSIC = 13;

/**
* Get domain by resource site.
*
Expand All @@ -50,6 +57,11 @@ public static function getDomain(?int $value): ?string
ResourceSite::KITSU->value => 'kitsu.io',
ResourceSite::MAL->value => 'myanimelist.net',
ResourceSite::WIKI->value => 'wikipedia.org',
ResourceSite::SPOTIFY->value => 'open.spotify.com',
ResourceSite::YOUTUBE_MUSIC->value => 'music.youtube.com',
ResourceSite::YOUTUBE->value => 'www.youtube.com',
ResourceSite::APPLE_MUSIC->value => 'music.apple.com',
ResourceSite::AMAZON_MUSIC->value => 'amazon.co.jp',
default => null,
};
}
Expand Down Expand Up @@ -173,6 +185,7 @@ public function formatAnimeResourceLink(int $id, ?string $slug = null): ?string
ResourceSite::ANN => "https://www.animenewsnetwork.com/encyclopedia/anime.php?id=$id",
ResourceSite::KITSU => "https://kitsu.io/anime/$slug",
ResourceSite::MAL => "https://myanimelist.net/anime/$id",
ResourceSite::YOUTUBE => "https://www.youtube.com/@$slug",
default => null,
};
}
Expand All @@ -193,10 +206,31 @@ public function formatArtistResourceLink(int $id, ?string $slug = null): ?string
ResourceSite::ANIME_PLANET => "https://www.anime-planet.com/people/$slug",
ResourceSite::ANN => "https://www.animenewsnetwork.com/encyclopedia/people.php?id=$id",
ResourceSite::MAL => "https://myanimelist.net/people/$id",
ResourceSite::YOUTUBE => "https://www.youtube.com/@$slug",
ResourceSite::SPOTIFY => "https://open.spotify.com/artist/$slug",
default => null,
};
}

/**
* Get the URL of the site for song resources.
*
* @param int $id
* @param string|null $slug
* @return string|null
*/
public function formatSongResourceLink(int $id, ?string $slug = null): ?string
{
return match ($this) {
ResourceSite::SPOTIFY->value => "https://open.spotify.com/track/$slug",

Check failure on line 225 in app/Enums/Models/Wiki/ResourceSite.php

View workflow job for this annotation

GitHub Actions / static-analysis

Match arm comparison between $this(App\Enums\Models\Wiki\ResourceSite) and 9 is always false.
ResourceSite::YOUTUBE_MUSIC->value => "https://music.youtube.com/watch?v=$slug",

Check failure on line 226 in app/Enums/Models/Wiki/ResourceSite.php

View workflow job for this annotation

GitHub Actions / static-analysis

Match arm comparison between $this(App\Enums\Models\Wiki\ResourceSite) and 10 is always false.
ResourceSite::YOUTUBE->value => "https://youtube.com/watch?v=$slug",

Check failure on line 227 in app/Enums/Models/Wiki/ResourceSite.php

View workflow job for this annotation

GitHub Actions / static-analysis

Match arm comparison between $this(App\Enums\Models\Wiki\ResourceSite) and 11 is always false.
ResourceSite::APPLE_MUSIC->value => "https://music.apple.com/jp/album/$id",

Check failure on line 228 in app/Enums/Models/Wiki/ResourceSite.php

View workflow job for this annotation

GitHub Actions / static-analysis

Match arm comparison between $this(App\Enums\Models\Wiki\ResourceSite) and 12 is always false.
ResourceSite::AMAZON_MUSIC->value => "https://amazon.co.jp/music/player/albums/$slug",

Check failure on line 229 in app/Enums/Models/Wiki/ResourceSite.php

View workflow job for this annotation

GitHub Actions / static-analysis

Match arm comparison between $this(App\Enums\Models\Wiki\ResourceSite) and 13 is always false.
default => null
};
}

/**
* Get the URL of the site for studio resources.
*
Expand Down
3 changes: 2 additions & 1 deletion app/Nova/Actions/Models/Wiki/AttachResourceAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Wiki\Anime;
use App\Models\Wiki\Artist;
use App\Models\Wiki\ExternalResource;
use App\Models\Wiki\Song;
use App\Models\Wiki\Studio;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Expand Down Expand Up @@ -116,7 +117,7 @@ public function fields(NovaRequest $request): array
$model = $request->findModelQuery()->first();

foreach ($this->sites as $resourceSite) {
if ($model instanceof Anime || $model instanceof Artist || $model instanceof Studio) {
if ($model instanceof Anime || $model instanceof Artist || $model instanceof Song || $model instanceof Studio) {
$resources = $model->resources();
if ($resources->where(ExternalResource::ATTRIBUTE_SITE, $resourceSite->value)->exists()) continue;
}
Expand Down
40 changes: 40 additions & 0 deletions app/Nova/Actions/Models/Wiki/Song/AttachSongResourceAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace App\Nova\Actions\Models\Wiki\Song;

use App\Enums\Models\Wiki\ResourceSite;
use App\Models\Wiki\ExternalResource;
use App\Nova\Actions\Models\Wiki\AttachResourceAction;
use App\Rules\Wiki\Resource\SongResourceLinkFormatRule;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

/**
* Class AttachSongResourceAction.
*/
class AttachSongResourceAction extends AttachResourceAction
{
/**
* Get the relation to the action models.
*
* @param ExternalResource $resource
* @return BelongsToMany
*/
protected function relation(ExternalResource $resource): BelongsToMany
{
return $resource->song();
}

/**
* Get the format validation rule.
*
* @param ResourceSite $site
* @return ValidationRule
*/
protected function getFormatRule(ResourceSite $site): ValidationRule
{
return new SongResourceLinkFormatRule($site);
}
}
36 changes: 36 additions & 0 deletions app/Nova/Lenses/Anime/Resource/AnimeYoutubeResourceLens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Nova\Lenses\Anime\Resource;

use App\Enums\Models\Wiki\ResourceSite;
use App\Nova\Lenses\Anime\AnimeResourceLens;

/**
* Class AnimeYoutubeResourceLens.
*/
class AnimeYoutubeResourceLens extends AnimeResourceLens
{
/**
* The resource site.
*
* @return ResourceSite
*/
protected static function site(): ResourceSite
{
return ResourceSite::YOUTUBE;
}

/**
* Get the URI key for the lens.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function uriKey(): string
{
return 'anime-youtube-resource-lens';
}
}
36 changes: 36 additions & 0 deletions app/Nova/Lenses/Artist/Resource/ArtistSpotifyResourceLens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Nova\Lenses\Artist\Resource;

use App\Enums\Models\Wiki\ResourceSite;
use App\Nova\Lenses\Artist\ArtistResourceLens;

/**
* Class ArtistSpotifyResourceLens.
*/
class ArtistSpotifyResourceLens extends ArtistResourceLens
{
/**
* The resource site.
*
* @return ResourceSite
*/
protected static function site(): ResourceSite
{
return ResourceSite::SPOTIFY;
}

/**
* Get the URI key for the lens.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function uriKey(): string
{
return 'artist-spotify-resource-lens';
}
}
36 changes: 36 additions & 0 deletions app/Nova/Lenses/Artist/Resource/ArtistYoutubeResourceLens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Nova\Lenses\Artist\Resource;

use App\Enums\Models\Wiki\ResourceSite;
use App\Nova\Lenses\Artist\ArtistResourceLens;

/**
* Class ArtistYoutubeResourceLens.
*/
class ArtistYoutubeResourceLens extends ArtistResourceLens
{
/**
* The resource site.
*
* @return ResourceSite
*/
protected static function site(): ResourceSite
{
return ResourceSite::YOUTUBE;
}

/**
* Get the URI key for the lens.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function uriKey(): string
{
return 'artist-youtube-resource-lens';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static function criteria(Builder $query): Builder
{
return $query->whereDoesntHave(ExternalResource::RELATION_ANIME)
->whereDoesntHave(ExternalResource::RELATION_ARTISTS)
->whereDoesntHave(ExternalResource::RELATION_SONG)
->whereDoesntHave(ExternalResource::RELATION_STUDIOS);
}

Expand Down
36 changes: 36 additions & 0 deletions app/Nova/Lenses/Song/Resource/SongAmazonMusicResourceLens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Nova\Lenses\Song\Resource;

use App\Enums\Models\Wiki\ResourceSite;
use App\Nova\Lenses\Song\SongResourceLens;

/**
* Class SongAmazonMusicResourceLens.
*/
class SongAmazonMusicResourceLens extends SongResourceLens
{
/**
* The resource site.
*
* @return ResourceSite
*/
protected static function site(): ResourceSite
{
return ResourceSite::AMAZON_MUSIC;
}

/**
* Get the URI key for the lens.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function uriKey(): string
{
return 'song-amazon-music-resource-lens';
}
}
36 changes: 36 additions & 0 deletions app/Nova/Lenses/Song/Resource/SongAppleMusicResourceLens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Nova\Lenses\Song\Resource;

use App\Enums\Models\Wiki\ResourceSite;
use App\Nova\Lenses\Song\SongResourceLens;

/**
* Class SongAppleMusicResourceLens.
*/
class SongAppleMusicResourceLens extends SongResourceLens
{
/**
* The resource site.
*
* @return ResourceSite
*/
protected static function site(): ResourceSite
{
return ResourceSite::APPLE_MUSIC;
}

/**
* Get the URI key for the lens.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function uriKey(): string
{
return 'song-apple-music-resource-lens';
}
}
36 changes: 36 additions & 0 deletions app/Nova/Lenses/Song/Resource/SongSpotifyResourceLens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Nova\Lenses\Song\Resource;

use App\Enums\Models\Wiki\ResourceSite;
use App\Nova\Lenses\Song\SongResourceLens;

/**
* Class SongSpotifyResourceLens.
*/
class SongSpotifyResourceLens extends SongResourceLens
{
/**
* The resource site.
*
* @return ResourceSite
*/
protected static function site(): ResourceSite
{
return ResourceSite::SPOTIFY;
}

/**
* Get the URI key for the lens.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function uriKey(): string
{
return 'song-spotify-resource-lens';
}
}
36 changes: 36 additions & 0 deletions app/Nova/Lenses/Song/Resource/SongYoutubeMusicResourceLens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Nova\Lenses\Song\Resource;

use App\Enums\Models\Wiki\ResourceSite;
use App\Nova\Lenses\Song\SongResourceLens;

/**
* Class SongYoutubeMusicResourceLens.
*/
class SongYoutubeMusicResourceLens extends SongResourceLens
{
/**
* The resource site.
*
* @return ResourceSite
*/
protected static function site(): ResourceSite
{
return ResourceSite::YOUTUBE_MUSIC;
}

/**
* Get the URI key for the lens.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function uriKey(): string
{
return 'song-youtube-music-resource-lens';
}
}
Loading

0 comments on commit b39c321

Please sign in to comment.