diff --git a/pages/anime/anime.go b/pages/anime/anime.go index 4f05d0eca..4a173cb9f 100644 --- a/pages/anime/anime.go +++ b/pages/anime/anime.go @@ -105,10 +105,27 @@ func Get(ctx *aero.Context) string { animeListItem = user.AnimeList().Find(anime.ID) } + // Last youtube anime trailer + lastAnimeTrailer := getLastValidTrailer(anime.Trailers) + // Open Graph ctx.Data = getOpenGraph(ctx, anime) - return ctx.HTML(components.Anime(anime, animeListItem, tracks, amvs, amvAppearances, episodes, friends, friendsAnimeListItems, user)) + return ctx.HTML(components.Anime(anime, lastAnimeTrailer, animeListItem, tracks, amvs, amvAppearances, episodes, friends, friendsAnimeListItems, user)) +} + +func getLastValidTrailer(trailers []*arn.ExternalMedia) *arn.ExternalMedia { + for i := len(trailers) - 1; i >= 0; i-- { + var trailer = trailers[i] + + if trailer.Service != "Youtube" || trailer.ServiceID == "" { + continue + } + + return trailer + } + + return nil } func getOpenGraph(ctx *aero.Context, anime *arn.Anime) *arn.OpenGraph { diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index 7b1c9f612..ff305287b 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -1,9 +1,9 @@ -component Anime(anime *arn.Anime, listItem *arn.AnimeListItem, tracks []*arn.SoundTrack, amvs []*arn.AMV, amvAppearances []*arn.AMV, episodes []*arn.AnimeEpisode, friends []*arn.User, listItems map[*arn.User]*arn.AnimeListItem, user *arn.User) +component Anime(anime *arn.Anime, trailer *arn.ExternalMedia, listItem *arn.AnimeListItem, tracks []*arn.SoundTrack, amvs []*arn.AMV, amvAppearances []*arn.AMV, episodes []*arn.AnimeEpisode, friends []*arn.User, listItems map[*arn.User]*arn.AnimeListItem, user *arn.User) .anime .anime-main-column AnimeMainColumn(anime, listItem, tracks, amvs, amvAppearances, episodes, user) .anime-side-column - AnimeSideColumn(anime, friends, listItems, user) + AnimeSideColumn(anime, trailer, friends, listItems, user) component AnimeMainColumn(anime *arn.Anime, listItem *arn.AnimeListItem, tracks []*arn.SoundTrack, amvs []*arn.AMV, amvAppearances []*arn.AMV, episodes []*arn.AnimeEpisode, user *arn.User) .anime-header(data-id=anime.ID) @@ -31,8 +31,8 @@ component AnimeMainColumn(anime *arn.Anime, listItem *arn.AnimeListItem, tracks AnimeAMVs(anime, amvs, amvAppearances, user) AnimeEpisodes(anime, episodes, user, false) -component AnimeSideColumn(anime *arn.Anime, friends []*arn.User, listItems map[*arn.User]*arn.AnimeListItem, user *arn.User) - AnimeTrailer(anime) +component AnimeSideColumn(anime *arn.Anime, trailer *arn.ExternalMedia, friends []*arn.User, listItems map[*arn.User]*arn.AnimeListItem, user *arn.User) + AnimeTrailer(anime, trailer) AnimeInformation(anime) AnimeRatings(anime, user) AnimePopularity(anime) @@ -149,15 +149,13 @@ component AnimeGenres(anime *arn.Anime) a.anime-genre.mountable(href="/genre/" + strings.ToLower(genre), data-mountable-type="header") span= genre -component AnimeTrailer(anime *arn.Anime) - if len(anime.Trailers) > 0 && anime.Trailers[len(anime.Trailers) - 1].Service == "Youtube" && anime.Trailers[len(anime.Trailers) - 1].ServiceID != "" - AnimeTrailerByIndex(anime, len(anime.Trailers)-1) - -component AnimeTrailerByIndex(anime *arn.Anime, index int) - section.anime-section.mountable(data-mountable-type="sidebar") - h3.anime-section-name Trailer - .anime-trailer.video-container - iframe.video(src="https://www.youtube.com/embed/" + anime.Trailers[index].ServiceID + "?showinfo=0", allowfullscreen) +component AnimeTrailer(anime *arn.Anime, trailer *arn.ExternalMedia) + if trailer != nil + section.anime-section.mountable(data-mountable-type="sidebar") + h3.anime-section-name + a(href=anime.TrailersLink()) Trailer + .anime-trailer.video-container + iframe.video.lazy(data-src=trailer.EmbedLink(), allowfullscreen) component AnimeFriends(friends []*arn.User, listItems map[*arn.User]*arn.AnimeListItem) if len(friends) > 0 diff --git a/pages/anime/trailers.go b/pages/anime/trailers.go new file mode 100644 index 000000000..3278114b2 --- /dev/null +++ b/pages/anime/trailers.go @@ -0,0 +1,25 @@ +package anime + +import ( + "net/http" + + "github.com/animenotifier/notify.moe/utils" + + "github.com/animenotifier/notify.moe/components" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" +) + +// Trailers Display the trailers of an anime. +func Trailers(ctx *aero.Context) string { + id := ctx.Get("id") + user := utils.GetUser(ctx) + anime, err := arn.GetAnime(id) + + if err != nil { + return ctx.Error(http.StatusNotFound, "Anime not found", err) + } + + return ctx.HTML(components.AnimeTrailers(anime, user)) +} diff --git a/pages/anime/trailers.pixy b/pages/anime/trailers.pixy new file mode 100644 index 000000000..cbde2b046 --- /dev/null +++ b/pages/anime/trailers.pixy @@ -0,0 +1,12 @@ +component AnimeTrailers(anime *arn.Anime, user *arn.User) + h1.mountable + a(href=anime.Link())= anime.Title.ByUser(user) + if anime.Trailers != nil && len(anime.Trailers) > 0 + .anime-section.mountable + h3.anime-section-name + a(href=anime.TrailersLink()) Trailers + .anime-trailers + each trailer in anime.Trailers + if trailer.ServiceID != "" + .trailer.mountable(data-mountable-type="trailer") + iframe.lazy(data-src=trailer.EmbedLink(), allowfullscreen) \ No newline at end of file diff --git a/pages/anime/trailers.scarlet b/pages/anime/trailers.scarlet new file mode 100644 index 000000000..3a7843c1e --- /dev/null +++ b/pages/anime/trailers.scarlet @@ -0,0 +1,22 @@ +.anime-trailers + horizontal-wrap + justify-content space-around + .trailer + margin 1rem 0 + box-shadow shadow-light + min-height 180px + border-radius ui-element-border-radius + width 320px + overflow hidden + display flex + + iframe + width 100% + +> 500px + .anime-trailers + justify-content flex-start + + .trailer + margin calc(content-padding / 2) + margin-bottom media-bottom-margin \ No newline at end of file diff --git a/pages/index/animeroutes/animeroutes.go b/pages/index/animeroutes/animeroutes.go index 1136e5182..618440f25 100644 --- a/pages/index/animeroutes/animeroutes.go +++ b/pages/index/animeroutes/animeroutes.go @@ -15,6 +15,7 @@ func Register(l *layout.Layout) { l.Page("/anime/:id", anime.Get) l.Page("/anime/:id/episodes", anime.Episodes) l.Page("/anime/:id/characters", anime.Characters) + l.Page("/anime/:id/trailers", anime.Trailers) l.Page("/anime/:id/tracks", anime.Tracks) l.Page("/anime/:id/relations", anime.Relations) l.Page("/anime/:id/episode/:episode-number", episode.Get)