Skip to content

Commit

Permalink
feat: anime streaming resources (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrch authored Nov 20, 2023
1 parent 1e8e816 commit f8ed4da
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 25 deletions.
21 changes: 21 additions & 0 deletions app/Enums/Models/Wiki/ResourceSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ enum ResourceSite: int
case APPLE_MUSIC = 12;
case AMAZON_MUSIC = 13;

// Official Streaming
case CRUNCHYROLL = 14;
case HIDIVE = 15;
case NETFLIX = 16;
case DISNEY_PLUS = 17;
case HULU = 18;
case AMAZON_PRIME_VIDEO = 19;

/**
* Get domain by resource site.
*
Expand All @@ -62,6 +70,12 @@ public static function getDomain(?int $value): ?string
ResourceSite::YOUTUBE->value => 'www.youtube.com',
ResourceSite::APPLE_MUSIC->value => 'music.apple.com',
ResourceSite::AMAZON_MUSIC->value => 'amazon.co.jp',
ResourceSite::CRUNCHYROLL->value => 'www.crunchyroll.com',
ResourceSite::HIDIVE->value => 'www.hidive.com',
ResourceSite::NETFLIX->value => 'www.netflix.com',
ResourceSite::DISNEY_PLUS->value => 'www.disneyplus.com',
ResourceSite::HULU->value => 'www.hulu.com',
ResourceSite::AMAZON_PRIME_VIDEO->value => 'www.primevideo.com',
default => null,
};
}
Expand Down Expand Up @@ -99,6 +113,7 @@ public static function parseIdFromLink(string $link): ?string
ResourceSite::MAL => Str::match('/\d+/', $link),
ResourceSite::ANIME_PLANET => ResourceSite::parseAnimePlanetIdFromLink($link),
ResourceSite::KITSU => ResourceSite::parseKitsuIdFromLink($link),
ResourceSite::NETFLIX => Str::match('/\d+/', $link),
default => null,
};
}
Expand Down Expand Up @@ -186,6 +201,12 @@ public function formatAnimeResourceLink(int $id, ?string $slug = null): ?string
ResourceSite::KITSU => "https://kitsu.io/anime/$slug",
ResourceSite::MAL => "https://myanimelist.net/anime/$id",
ResourceSite::YOUTUBE => "https://www.youtube.com/@$slug",
ResourceSite::CRUNCHYROLL => "https://www.crunchyroll.com/series/$slug",
ResourceSite::HIDIVE => "https://www.hidive.com/tv/$slug",
ResourceSite::NETFLIX => "https://www.netflix.com/title/$id",
ResourceSite::DISNEY_PLUS => "https://www.disneyplus.com/series/$slug",
ResourceSite::HULU => "https://www.hulu.com/series/$slug",
ResourceSite::AMAZON_PRIME_VIDEO => "https://www.primevideo.com/detail/$slug",
default => null,
};
}
Expand Down
5 changes: 3 additions & 2 deletions app/Nova/Actions/Models/Wiki/AttachResourceAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ abstract class AttachResourceAction extends Action
* Create a new action instance.
*
* @param ResourceSite[] $sites
* @param string|null $actionName
*/
public function __construct(protected array $sites)
public function __construct(protected array $sites, protected ?string $actionName)
{
}

Expand All @@ -41,7 +42,7 @@ public function __construct(protected array $sites)
*/
public function name(): string
{
return __('nova.actions.models.wiki.attach_resource.name');
return $this->actionName ?? __('nova.actions.models.wiki.attach_resource.name');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Nova/Lenses/Anime/AnimeResourceLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function criteria(Builder $query): Builder
public function actions(NovaRequest $request): array
{
return [
(new AttachAnimeResourceAction([static::site()]))
(new AttachAnimeResourceAction([static::site()], null))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->showInline()
Expand Down
95 changes: 95 additions & 0 deletions app/Nova/Lenses/Anime/AnimeStreamingResourceLens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

declare(strict_types=1);

namespace App\Nova\Lenses\Anime;

use App\Enums\Models\Wiki\ResourceSite;
use App\Models\Wiki\Anime;
use App\Models\Wiki\ExternalResource;
use App\Nova\Actions\Models\Wiki\Anime\AttachAnimeResourceAction;
use Illuminate\Database\Eloquent\Builder;
use Laravel\Nova\Http\Requests\NovaRequest;

/**
* Class AnimeStreamingResourceLens.
*/
class AnimeStreamingResourceLens extends AnimeLens
{
/**
* The resources site.
*
* @return ResourceSite[]
*/
protected static function sites(): array
{
return [
ResourceSite::CRUNCHYROLL,
ResourceSite::HIDIVE,
ResourceSite::NETFLIX,
ResourceSite::DISNEY_PLUS,
ResourceSite::HULU,
ResourceSite::AMAZON_PRIME_VIDEO,
];
}

/**
* Get the displayable name of the lens.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function name(): string
{
return __('nova.lenses.anime.streaming_resources.name');
}

/**
* The criteria used to refine the models for the lens.
*
* @param Builder $query
* @return Builder
*/
public static function criteria(Builder $query): Builder
{
return $query->whereDoesntHave(Anime::RELATION_RESOURCES, function (Builder $resourceQuery) {
$resourceQuery->where(function (Builder $query) {
foreach (static::sites() as $site) {
$query->orWhere(ExternalResource::ATTRIBUTE_SITE, $site->value);
}
});
});
}

/**
* Get the actions available on the lens.
*
* @param NovaRequest $request
* @return array
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function actions(NovaRequest $request): array
{
return [
(new AttachAnimeResourceAction(static::sites(), __('nova.actions.models.wiki.attach_streaming_resource.name')))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->showInline()
->canSeeWhen('create', ExternalResource::class),
];
}

/**
* Get the URI key for the lens.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function uriKey(): string
{
return 'anime-streaming-resources-lens';
}
}
2 changes: 1 addition & 1 deletion app/Nova/Lenses/Artist/ArtistResourceLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function criteria(Builder $query): Builder
public function actions(NovaRequest $request): array
{
return [
(new AttachArtistResourceAction([static::site()]))
(new AttachArtistResourceAction([static::site()], null))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->showInline()
Expand Down
2 changes: 1 addition & 1 deletion app/Nova/Lenses/Song/SongResourceLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function criteria(Builder $query): Builder
public function actions(NovaRequest $request): array
{
return [
(new AttachSongResourceAction([static::site()]))
(new AttachSongResourceAction([static::site()], null))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->showInline()
Expand Down
2 changes: 1 addition & 1 deletion app/Nova/Lenses/Studio/StudioResourceLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function criteria(Builder $query): Builder
public function actions(Request $request): array
{
return [
(new AttachStudioResourceAction([static::site()]))
(new AttachStudioResourceAction([static::site()], null))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->showInline()
Expand Down
23 changes: 20 additions & 3 deletions app/Nova/Resources/Wiki/Anime.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Nova\Actions\Models\Wiki\Anime\AttachAnimeImageAction;
use App\Nova\Actions\Models\Wiki\Anime\AttachAnimeResourceAction;
use App\Nova\Actions\Models\Wiki\Anime\BackfillAnimeAction;
use App\Nova\Lenses\Anime\AnimeStreamingResourceLens;
use App\Nova\Lenses\Anime\Image\AnimeCoverLargeLens;
use App\Nova\Lenses\Anime\Image\AnimeCoverSmallLens;
use App\Nova\Lenses\Anime\Resource\AnimeAniDbResourceLens;
Expand Down Expand Up @@ -312,12 +313,21 @@ public function actions(NovaRequest $request): array
ResourceSite::OFFICIAL_SITE,
ResourceSite::TWITTER,
ResourceSite::YOUTUBE,
ResourceSite::WIKI
ResourceSite::WIKI,
];

$streamingResourceSites = [
ResourceSite::CRUNCHYROLL,
ResourceSite::HIDIVE,
ResourceSite::NETFLIX,
ResourceSite::DISNEY_PLUS,
ResourceSite::HULU,
ResourceSite::AMAZON_PRIME_VIDEO,
];

$facets = [
ImageFacet::COVER_SMALL,
ImageFacet::COVER_LARGE
ImageFacet::COVER_LARGE,
];

return array_merge(
Expand All @@ -337,7 +347,13 @@ public function actions(NovaRequest $request): array
->showInline()
->canSeeWhen('update', $this),

(new AttachAnimeResourceAction($resourceSites))
(new AttachAnimeResourceAction($resourceSites, null))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->exceptOnIndex()
->canSeeWhen('create', ExternalResourceModel::class),

(new AttachAnimeResourceAction($streamingResourceSites, __('nova.actions.models.wiki.attach_streaming_resource.name')))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->exceptOnIndex()
Expand Down Expand Up @@ -391,6 +407,7 @@ public function lenses(NovaRequest $request): array
new AnimeTwitterResourceLens(),
new AnimeOfficialSiteResourceLens(),
new AnimeYoutubeResourceLens(),
new AnimeStreamingResourceLens(),
new AnimeStudioLens(),
]
);
Expand Down
6 changes: 3 additions & 3 deletions app/Nova/Resources/Wiki/Artist.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,18 @@ public function actions(NovaRequest $request): array
ResourceSite::SPOTIFY,
ResourceSite::TWITTER,
ResourceSite::YOUTUBE,
ResourceSite::WIKI
ResourceSite::WIKI,
];

$facets = [
ImageFacet::COVER_SMALL,
ImageFacet::COVER_LARGE
ImageFacet::COVER_LARGE,
];

return array_merge(
parent::actions($request),
[
(new AttachArtistResourceAction($resources))
(new AttachArtistResourceAction($resources, null))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->exceptOnIndex()
Expand Down
6 changes: 3 additions & 3 deletions app/Nova/Resources/Wiki/Song.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ public function actions(NovaRequest $request): array
ResourceSite::YOUTUBE_MUSIC,
ResourceSite::YOUTUBE,
ResourceSite::APPLE_MUSIC,
ResourceSite::AMAZON_MUSIC
ResourceSite::AMAZON_MUSIC,
];

return array_merge(
parent::actions($request),
[
(new AttachSongResourceAction($resourceSites))
(new AttachSongResourceAction($resourceSites, null))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->exceptOnIndex()
Expand All @@ -269,7 +269,7 @@ public function lenses(NovaRequest $request): array
new SongAmazonMusicResourceLens(),
new SongAppleMusicResourceLens(),
new SongSpotifyResourceLens(),
new SongYoutubeMusicResourceLens()
new SongYoutubeMusicResourceLens(),
]
);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Nova/Resources/Wiki/Studio.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ public function actions(NovaRequest $request): array
ResourceSite::ANILIST,
ResourceSite::ANIME_PLANET,
ResourceSite::ANN,
ResourceSite::MAL
ResourceSite::MAL,
];

$facets = [
ImageFacet::COVER_LARGE
ImageFacet::COVER_LARGE,
];

return array_merge(
Expand All @@ -238,7 +238,7 @@ public function actions(NovaRequest $request): array
->showInline()
->canSeeWhen('update', $this),

(new AttachStudioResourceAction($resources))
(new AttachStudioResourceAction($resources, null))
->confirmButtonText(__('nova.actions.models.wiki.attach_resource.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->exceptOnIndex()
Expand Down
6 changes: 6 additions & 0 deletions app/Rules/Wiki/Resource/AnimeResourceLinkFormatRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
ResourceSite::YOUTUBE => '/^https:\/\/www\.youtube\.com\/\@\w+$/',
ResourceSite::APPLE_MUSIC => '/$.^/',
ResourceSite::AMAZON_MUSIC => '/$.^/',
ResourceSite::CRUNCHYROLL => '/^https:\/\/www\.crunchyroll\.com\/series\/\w+$/',
ResourceSite::HIDIVE => '/^https:\/\/www\.hidive\.com\/tv\/[\w-]+$/',
ResourceSite::NETFLIX => '/^https:\/\/www\.netflix\.com\/title\/\d+$/',
ResourceSite::DISNEY_PLUS => '/^https:\/\/www\.disneyplus\.com\/series\/[\w-]+\/\w+$/',
ResourceSite::HULU => '/^https:\/\/www\.hulu\.com\/series\/[\w-]+$/',
ResourceSite::AMAZON_PRIME_VIDEO => '/^https:\/\/www\.primevideo\.com\/detail\/\w+$/',
default => null,
};

Expand Down
8 changes: 7 additions & 1 deletion lang/en/enums.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@
ResourceSite::YOUTUBE_MUSIC->name => 'YouTube Music',
ResourceSite::YOUTUBE->name => 'YouTube',
ResourceSite::APPLE_MUSIC->name => 'Apple Music',
ResourceSite::AMAZON_MUSIC->name => 'Amazon Music'
ResourceSite::AMAZON_MUSIC->name => 'Amazon Music',
ResourceSite::CRUNCHYROLL->name => 'Crunchyroll',
ResourceSite::HIDIVE->name => 'HIDIVE',
ResourceSite::NETFLIX->name => 'Netflix',
ResourceSite::DISNEY_PLUS->name => 'Disney Plus',
ResourceSite::HULU->name => 'Hulu',
ResourceSite::AMAZON_PRIME_VIDEO->name => 'Amazon Prime Video',
],
Service::class => [
Service::OTHER->name => 'Other',
Expand Down
Loading

0 comments on commit f8ed4da

Please sign in to comment.