Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Added a anime trailers page #192

Open
wants to merge 4 commits into
base: go
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion pages/anime/anime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 11 additions & 13 deletions pages/anime/anime.pixy
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pages/anime/trailers.go
Original file line number Diff line number Diff line change
@@ -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))
}
12 changes: 12 additions & 0 deletions pages/anime/trailers.pixy
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions pages/anime/trailers.scarlet
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions pages/index/animeroutes/animeroutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down