Skip to content

Commit

Permalink
refactor: updating resources (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrch authored Aug 2, 2024
1 parent ae8747d commit 5ccbd04
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<a href="https://discordapp.com/invite/m9zbVyQ"><img src="https://img.shields.io/discord/354388306580078594.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2"></a>
<a href="https://github.com/AnimeThemes/animethemes-server/blob/main/LICENSE"><img src="https://img.shields.io/github/license/AnimeThemes/animethemes-server"></a>
<a href="https://reddit.com/r/AnimeThemes"><img src="https://img.shields.io/reddit/subreddit-subscribers/AnimeThemes?style=social"></a>
<a href="https://twitter.com/AnimeThemesMoe"><img src="https://img.shields.io/twitter/follow/AnimeThemesMoe?style=social"></a>
<a href="https://x.com/AnimeThemesMoe"><img src="https://img.shields.io/twitter/follow/AnimeThemesMoe?style=social"></a>
</p>

[**AnimeThemes**](https://animethemes.moe/) is a simple and consistent repository of anime opening and ending themes. We provide direct links to high quality WebMs of your favorite OPs and EDs for your listening and discussion needs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function getSynonyms(): array
protected function getResourcesMapping(): array
{
return [
ResourceSite::TWITTER->value => 'Twitter',
ResourceSite::X->value => 'Twitter',
ResourceSite::OFFICIAL_SITE->value => 'Official Site',
ResourceSite::NETFLIX->value => 'Netflix',
ResourceSite::CRUNCHYROLL->value => 'Crunchyroll',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Actions\Models\Wiki\Anime\ApiAction;

use App\Actions\Models\Wiki\ApiAction;
use App\Enums\Models\Wiki\ImageFacet;
use App\Enums\Models\Wiki\ResourceSite;
use App\Models\Wiki\ExternalResource;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Expand Down Expand Up @@ -39,12 +38,7 @@ public function handle(BelongsToMany $resources): static
if ($resource instanceof ExternalResource) {
$id = $resource->external_id;

$response = Http::withHeaders([
'accept-encoding' => 'gzip',
'connection' => 'Keep-Alive',
'host' => 'www.livechart.me',
'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 OPR/109.0.0.0',
])->withoutVerifying()
$response = Http::withUserAgent('AnimeThemes/1.0 (https://animethemes.moe)')
->get("https://www.livechart.me/api/v2/anime/$id")
->throw()
->json();
Expand All @@ -70,7 +64,7 @@ protected function getResourcesMapping(): array
ResourceSite::KITSU->value => 'kitsu_url',
ResourceSite::MAL->value => 'mal_url',
ResourceSite::OFFICIAL_SITE->value => 'website_url',
ResourceSite::TWITTER->value => 'twitter_url',
ResourceSite::X->value => 'twitter_url',
];
}

Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Models/Wiki/AttachResourceAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function handle(): void
foreach ($this->sites as $resourceSite) {
$link = Arr::get($this->fields, $resourceSite->name);

if (empty($link)) continue;

$this->createResource($link, $resourceSite, $this->model);
}
}
Expand Down
33 changes: 17 additions & 16 deletions app/Enums/Models/Wiki/ResourceSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum ResourceSite: int

// Official Media
case OFFICIAL_SITE = 0;
case TWITTER = 1;
case X = 1;

// Tracking Sites
case ANIDB = 2;
Expand Down Expand Up @@ -63,7 +63,7 @@ enum ResourceSite: int
public static function getDomain(?int $value): ?string
{
return match ($value) {
ResourceSite::TWITTER->value => 'twitter.com',
ResourceSite::X->value => 'x.com',
ResourceSite::ANIDB->value => 'anidb.net',
ResourceSite::ANILIST->value => 'anilist.co',
ResourceSite::ANIME_PLANET->value => 'www.anime-planet.com',
Expand Down Expand Up @@ -141,7 +141,8 @@ protected static function parseAnimePlanetIdFromLink(string $link): ?string
}

try {
$response = Http::get($link)
$response = Http::withUserAgent('AnimeThemes/1.0 (https://animethemes.moe)')
->get($link)
->throw()
->body();

Expand Down Expand Up @@ -206,7 +207,7 @@ public static function getForModel(?string $modelClass): array
{
return match ($modelClass) {
Anime::class => [
ResourceSite::TWITTER,
ResourceSite::X,
ResourceSite::ANIDB,
ResourceSite::ANILIST,
ResourceSite::ANIME_PLANET,
Expand All @@ -225,7 +226,7 @@ public static function getForModel(?string $modelClass): array
ResourceSite::LIVECHART,
],
Artist::class => [
ResourceSite::TWITTER,
ResourceSite::X,
ResourceSite::ANIDB,
ResourceSite::ANILIST,
ResourceSite::ANIME_PLANET,
Expand All @@ -248,7 +249,7 @@ public static function getForModel(?string $modelClass): array
ResourceSite::WIKI,
],
Studio::class => [
ResourceSite::TWITTER,
ResourceSite::X,
ResourceSite::ANIDB,
ResourceSite::ANILIST,
ResourceSite::ANIME_PLANET,
Expand All @@ -274,12 +275,12 @@ public function formatResourceLink(string $modelClass, int $id, ?string $slug =
{
if ($modelClass === Anime::class) {
return match ($this) {
ResourceSite::TWITTER => "https://twitter.com/$slug",
ResourceSite::X => "https://x.com/$slug",
ResourceSite::ANIDB => "https://anidb.net/anime/$id",
ResourceSite::ANILIST => "https://anilist.co/anime/$id",
ResourceSite::ANIME_PLANET => "https://www.anime-planet.com/anime/$slug",
ResourceSite::ANN => "https://www.animenewsnetwork.com/encyclopedia/anime.php?id=$id",
ResourceSite::KITSU => "https://kitsu.io/anime/$slug",
ResourceSite::KITSU => "https://kitsu.io/anime/$id",
ResourceSite::LIVECHART => "https://www.livechart.me/anime/$id",
ResourceSite::MAL => "https://myanimelist.net/anime/$id",
ResourceSite::YOUTUBE => "https://www.youtube.com/@$slug",
Expand All @@ -295,7 +296,7 @@ public function formatResourceLink(string $modelClass, int $id, ?string $slug =

if ($modelClass === Artist::class) {
return match ($this) {
ResourceSite::TWITTER => "https://twitter.com/$slug",
ResourceSite::X => "https://x.com/$slug",
ResourceSite::ANIDB => "https://anidb.net/creator/$id",
ResourceSite::ANILIST => "https://anilist.co/staff/$id",
ResourceSite::ANIME_PLANET => "https://www.anime-planet.com/people/$slug",
Expand All @@ -322,7 +323,7 @@ public function formatResourceLink(string $modelClass, int $id, ?string $slug =

if ($modelClass === Studio::class) {
return match ($this) {
ResourceSite::TWITTER => "https://twitter.com/$slug",
ResourceSite::X => "https://x.com/$slug",
ResourceSite::ANIDB => "https://anidb.net/creator/$id",
ResourceSite::ANILIST => "https://anilist.co/studio/$id",
ResourceSite::ANIME_PLANET => "https://www.anime-planet.com/anime/studios/$slug",
Expand All @@ -346,7 +347,7 @@ public function getUrlCaptureGroups(?Model $model): string
// The first capture group refers to $type, the second to $id and $slug of the formatResourceLink method.
if ($model instanceof Anime) {
return match ($this) {
ResourceSite::TWITTER => '/^https:\/\/(twitter)\.com\/(\w+)/',
ResourceSite::X => '/^https:\/\/(x)\.com\/(\w+)/',
ResourceSite::ANILIST => '/^https:\/\/anilist\.co\/(anime)\/(\d+)$/',
ResourceSite::ANIME_PLANET => '/^https:\/\/www\.anime-planet\.com\/(anime)\/([a-zA-Z0-9-]+)$/',
ResourceSite::ANN => '/^https:\/\/www\.animenewsnetwork\.com\/encyclopedia\/(anime)\.php\?id=(\d+)$/',
Expand All @@ -367,7 +368,7 @@ public function getUrlCaptureGroups(?Model $model): string

if ($model instanceof Artist) {
return match ($this) {
ResourceSite::TWITTER => '/^https:\/\/(twitter)\.com\/(\w+)$/',
ResourceSite::X => '/^https:\/\/(x)\.com\/(\w+)$/',
ResourceSite::ANIDB => '/^https:\/\/anidb\.net\/(creator)\/(?:virtual\/)?(\d+)$/',
ResourceSite::ANILIST => '/^https:\/\/anilist\.co\/(staff)\/(\d+)$/',
ResourceSite::ANIME_PLANET => '/^https:\/\/www\.anime-planet\.com\/(people)\/([a-zA-Z0-9-]+)$/',
Expand All @@ -394,7 +395,7 @@ public function getUrlCaptureGroups(?Model $model): string

if ($model instanceof Studio) {
return match ($this) {
ResourceSite::TWITTER => '/^https:\/\/(twitter)\.com\/(\w+)$/',
ResourceSite::X => '/^https:\/\/(x)\.com\/(\w+)$/',
ResourceSite::ANIDB => '/^https:\/\/anidb\.net\/(creator)\/(?:virtual\/)?(\d+)$/',
ResourceSite::ANILIST => '/^https:\/\/anilist\.co\/(studio)\/(\d+)$/',
ResourceSite::ANIME_PLANET => '/^https:\/\/www\.anime-planet\.com\/anime\/(studios)\/([a-zA-Z0-9-]+)$/',
Expand All @@ -417,7 +418,7 @@ public function getPattern(?string $modelClass): ?string
{
if ($modelClass === Anime::class) {
return match ($this) {
ResourceSite::TWITTER => '/^https:\/\/twitter\.com\/\w+$/',
ResourceSite::X => '/^https:\/\/x\.com\/\w+$/',
ResourceSite::ANIDB => '/^https:\/\/anidb\.net\/anime\/\d+$/',
ResourceSite::ANILIST => '/^https:\/\/anilist\.co\/anime\/\d+$/',
ResourceSite::ANIME_PLANET => '/^https:\/\/www\.anime-planet\.com\/anime\/[a-zA-Z0-9-]+$/',
Expand All @@ -440,7 +441,7 @@ public function getPattern(?string $modelClass): ?string

if ($modelClass === Artist::class) {
return match ($this) {
ResourceSite::TWITTER => '/^https:\/\/twitter\.com\/\w+$/',
ResourceSite::X => '/^https:\/\/x\.com\/\w+$/',
ResourceSite::ANIDB => '/^https:\/\/anidb\.net\/creator\/(?:virtual\/)?\d+$/',
ResourceSite::ANILIST => '/^https:\/\/anilist\.co\/staff\/\d+$/',
ResourceSite::ANIME_PLANET => '/^https:\/\/www\.anime-planet\.com\/people\/[a-zA-Z0-9-]+$/',
Expand Down Expand Up @@ -471,7 +472,7 @@ public function getPattern(?string $modelClass): ?string

if ($modelClass === Studio::class) {
return match ($this) {
ResourceSite::TWITTER => '/^https:\/\/twitter\.com\/\w+$/',
ResourceSite::X => '/^https:\/\/x\.com\/\w+$/',
ResourceSite::ANIDB => '/^https:\/\/anidb\.net\/creator\/(?:virtual\/)?\d+$/',
ResourceSite::ANILIST => '/^https:\/\/anilist\.co\/studio\/\d+$/',
ResourceSite::ANIME_PLANET => '/^https:\/\/www\.anime-planet\.com\/anime\/studios\/[a-zA-Z0-9-]+$/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp(): void
ResourceSite::LIVECHART,
ResourceSite::MAL,
ResourceSite::OFFICIAL_SITE,
ResourceSite::TWITTER,
ResourceSite::X,
ResourceSite::YOUTUBE,
ResourceSite::WIKI,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected function getResourcesMapping(): array
self::BACKFILL_ANN_RESOURCE => [ResourceSite::ANN],
self::BACKFILL_ANIME_PLANET_RESOURCE => [ResourceSite::ANIME_PLANET],
self::BACKFILL_OTHER_RESOURCES => [
ResourceSite::TWITTER, ResourceSite::OFFICIAL_SITE, ResourceSite::NETFLIX, ResourceSite::CRUNCHYROLL,
ResourceSite::X, ResourceSite::OFFICIAL_SITE, ResourceSite::NETFLIX, ResourceSite::CRUNCHYROLL,
ResourceSite::HIDIVE, ResourceSite::AMAZON_PRIME_VIDEO, ResourceSite::HULU, ResourceSite::DISNEY_PLUS,
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
ResourceSite::MAL,
ResourceSite::OFFICIAL_SITE,
ResourceSite::SPOTIFY,
ResourceSite::TWITTER,
ResourceSite::X,
ResourceSite::YOUTUBE,
ResourceSite::YOUTUBE_MUSIC,
ResourceSite::WIKI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp(): void
ResourceSite::LIVECHART,
ResourceSite::MAL,
ResourceSite::OFFICIAL_SITE,
ResourceSite::TWITTER,
ResourceSite::X,
ResourceSite::YOUTUBE,
ResourceSite::WIKI,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected function getResourcesMapping(): array
self::BACKFILL_ANN_RESOURCE => [ResourceSite::ANN],
self::BACKFILL_ANIME_PLANET_RESOURCE => [ResourceSite::ANIME_PLANET],
self::BACKFILL_OTHER_RESOURCES => [
ResourceSite::TWITTER, ResourceSite::OFFICIAL_SITE, ResourceSite::NETFLIX, ResourceSite::CRUNCHYROLL,
ResourceSite::X, ResourceSite::OFFICIAL_SITE, ResourceSite::NETFLIX, ResourceSite::CRUNCHYROLL,
ResourceSite::HIDIVE, ResourceSite::AMAZON_PRIME_VIDEO, ResourceSite::HULU, ResourceSite::DISNEY_PLUS,
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
ResourceSite::MAL,
ResourceSite::OFFICIAL_SITE,
ResourceSite::SPOTIFY,
ResourceSite::TWITTER,
ResourceSite::X,
ResourceSite::YOUTUBE,
ResourceSite::YOUTUBE_MUSIC,
ResourceSite::WIKI,
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Resources/Wiki/Anime/Pages/ListAnimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use App\Filament\Tabs\Anime\Resource\AnimeMalResourceTab;
use App\Filament\Tabs\Anime\Resource\AnimeOfficialSiteResourceTab;
use App\Filament\Tabs\Anime\Resource\AnimePlanetResourceTab;
use App\Filament\Tabs\Anime\Resource\AnimeTwitterResourceTab;
use App\Filament\Tabs\Anime\Resource\AnimeXResourceTab;
use App\Filament\Tabs\Anime\Resource\AnimeYoutubeResourceTab;
use App\Filament\Tabs\Anime\Studio\AnimeStudioTab;
use App\Models\Wiki\Anime as AnimeModel;
Expand Down Expand Up @@ -82,7 +82,7 @@ public function getTabs(): array
AnimeMalResourceTab::class,
AnimeOfficialSiteResourceTab::class,
AnimePlanetResourceTab::class,
AnimeTwitterResourceTab::class,
AnimeXResourceTab::class,
AnimeYoutubeResourceTab::class,
AnimeStreamingResourceTab::class,
AnimeStudioTab::class,
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Resources/Wiki/Artist/Pages/ListArtists.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use App\Filament\Tabs\Artist\Resource\ArtistMalResourceTab;
use App\Filament\Tabs\Artist\Resource\ArtistOfficialSiteResourceTab;
use App\Filament\Tabs\Artist\Resource\ArtistSpotifyResourceTab;
use App\Filament\Tabs\Artist\Resource\ArtistTwitterResourceTab;
use App\Filament\Tabs\Artist\Resource\ArtistXResourceTab;
use App\Filament\Tabs\Artist\Resource\ArtistYoutubeResourceTab;
use App\Filament\Tabs\Artist\Song\ArtistSongTab;
use App\Models\Wiki\Artist as ArtistModel;
Expand Down Expand Up @@ -81,7 +81,7 @@ public function getTabs(): array
ArtistMalResourceTab::class,
ArtistOfficialSiteResourceTab::class,
ArtistSpotifyResourceTab::class,
ArtistTwitterResourceTab::class,
ArtistXResourceTab::class,
ArtistYoutubeResourceTab::class,
ArtistSongTab::class,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use App\Filament\Tabs\Anime\AnimeResourceTab;

/**
* Class AnimeTwitterResourceTab.
* Class AnimeXResourceTab.
*/
class AnimeTwitterResourceTab extends AnimeResourceTab
class AnimeXResourceTab extends AnimeResourceTab
{
/**
* Get the key for the tab.
Expand All @@ -19,7 +19,7 @@ class AnimeTwitterResourceTab extends AnimeResourceTab
*/
public static function getKey(): string
{
return 'anime-twitter-resource-tab';
return 'anime-x-resource-tab';
}

/**
Expand All @@ -29,6 +29,6 @@ public static function getKey(): string
*/
protected static function site(): ResourceSite
{
return ResourceSite::TWITTER;
return ResourceSite::X;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use App\Filament\Tabs\Artist\ArtistResourceTab;

/**
* Class ArtistTwitterResourceTab.
* Class ArtistXResourceTab.
*/
class ArtistTwitterResourceTab extends ArtistResourceTab
class ArtistXResourceTab extends ArtistResourceTab
{
/**
* Get the key for the tab.
Expand All @@ -19,7 +19,7 @@ class ArtistTwitterResourceTab extends ArtistResourceTab
*/
public static function getKey(): string
{
return 'artist-twitter-resource-tab';
return 'artist-x-resource-tab';
}

/**
Expand All @@ -29,6 +29,6 @@ public static function getKey(): string
*/
protected static function site(): ResourceSite
{
return ResourceSite::TWITTER;
return ResourceSite::X;
}
}
Loading

0 comments on commit 5ccbd04

Please sign in to comment.