From 5460c49cfeaf1389c4a7e13e0824e87540632608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Rayapoull=C3=A9?= Date: Sat, 29 Sep 2018 14:02:25 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20Added=20anime=20trailers=20page?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/anime/trailers.go | 25 ++++++++++++++++++++++++ pages/anime/trailers.pixy | 13 +++++++++++++ pages/anime/trailers.scarlet | 27 ++++++++++++++++++++++++++ pages/index/animeroutes/animeroutes.go | 1 + 4 files changed, 66 insertions(+) create mode 100644 pages/anime/trailers.go create mode 100644 pages/anime/trailers.pixy create mode 100644 pages/anime/trailers.scarlet 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..a529d3a6e --- /dev/null +++ b/pages/anime/trailers.pixy @@ -0,0 +1,13 @@ +component AnimeTrailers(anime *arn.Anime, user *arn.User) + if anime.Trailers != nil && len(anime.Trailers) > 0 + .anime-section.mountable + h3.anime-section-name + a(href=anime.TrailersLink()) Trailers + + .trailers.anime-trailers + each trailer in anime.Trailers + if trailer.ServiceID != "" + .trailer.mountable(data-mountable-type="trailer") + .anime-trailer.video-container + //iframe.video(src="https://www.youtube.com/embed/" + trailer.ServiceID + "?showinfo=0", allowfullscreen) + ExternalMedia(trailer) \ No newline at end of file diff --git a/pages/anime/trailers.scarlet b/pages/anime/trailers.scarlet new file mode 100644 index 000000000..d6f06fd20 --- /dev/null +++ b/pages/anime/trailers.scarlet @@ -0,0 +1,27 @@ +.anime-trailers + vertical + .trailer + margin 1rem 0 + border-bottom-left-radius ui-element-border-radius !important + border-top-left-radius ui-element-border-radius !important + box-shadow shadow-light + min-height 200px + border-radius ui-element-border-radius + overflow hidden + + iframe + width 100% + +> +500px +.anime-trailers + horizontal-wrap + justify-content flex-start + +.trailer + max-width 200px + margin calc(content-padding / 2) + min-height 112px + height 112px + margin soundtrack-margin + 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) From 201e18d485ac1744a6a5fe910c088bbd575553f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Rayapoull=C3=A9?= Date: Sat, 29 Sep 2018 14:03:37 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=92=84=20Show=20trailers=20from=20oth?= =?UTF-8?q?er=20source=20than=20only=20Youtube=20on=20anime=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/anime/anime.pixy | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index 7b1c9f612..0d361bc4c 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -150,14 +150,15 @@ component AnimeGenres(anime *arn.Anime) 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 != "" + if len(anime.Trailers) > 0 && 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 + h3.anime-section-name + a(href=anime.TrailersLink()) Trailer .anime-trailer.video-container - iframe.video(src="https://www.youtube.com/embed/" + anime.Trailers[index].ServiceID + "?showinfo=0", allowfullscreen) + iframe.video.lazy(data-src=anime.Trailers[index].EmbedLink(), allowfullscreen) component AnimeFriends(friends []*arn.User, listItems map[*arn.User]*arn.AnimeListItem) if len(friends) > 0 From d7fb490c8a11929e71f99bec10065bbccf35e07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Rayapoull=C3=A9?= Date: Sun, 30 Sep 2018 02:00:28 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=92=84=20Display=20the=20trailers=20w?= =?UTF-8?q?ith=20a=20better=20visual=20and=20responsive.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/anime/trailers.pixy | 9 ++++----- pages/anime/trailers.scarlet | 27 +++++++++++---------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/pages/anime/trailers.pixy b/pages/anime/trailers.pixy index a529d3a6e..cbde2b046 100644 --- a/pages/anime/trailers.pixy +++ b/pages/anime/trailers.pixy @@ -1,13 +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 - - .trailers.anime-trailers + .anime-trailers each trailer in anime.Trailers if trailer.ServiceID != "" .trailer.mountable(data-mountable-type="trailer") - .anime-trailer.video-container - //iframe.video(src="https://www.youtube.com/embed/" + trailer.ServiceID + "?showinfo=0", allowfullscreen) - ExternalMedia(trailer) \ No newline at end of file + 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 index d6f06fd20..3a7843c1e 100644 --- a/pages/anime/trailers.scarlet +++ b/pages/anime/trailers.scarlet @@ -1,27 +1,22 @@ .anime-trailers - vertical + horizontal-wrap + justify-content space-around .trailer margin 1rem 0 - border-bottom-left-radius ui-element-border-radius !important - border-top-left-radius ui-element-border-radius !important box-shadow shadow-light - min-height 200px + min-height 180px border-radius ui-element-border-radius + width 320px overflow hidden + display flex iframe width 100% -> -500px -.anime-trailers - horizontal-wrap - justify-content flex-start +> 500px + .anime-trailers + justify-content flex-start -.trailer - max-width 200px - margin calc(content-padding / 2) - min-height 112px - height 112px - margin soundtrack-margin - margin-bottom media-bottom-margin \ No newline at end of file + .trailer + margin calc(content-padding / 2) + margin-bottom media-bottom-margin \ No newline at end of file From 03e15de2821a7b70f51bb1c19afdf1ba5cc8c91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Rayapoull=C3=A9?= Date: Wed, 10 Oct 2018 12:16:53 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=91=8C=F0=9F=90=9B=20Revert=20commit?= =?UTF-8?q?=20201e18d=20and=20display=20the=20latest=20valid=20trailer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After reverting to the previous state of the anime page, I noticed that if the latest trailer is not "valid" (currently which is not coming from Youtube and doesn't have a serviceId) we didn't check if there was a valid one. To resolve this issue I've added a trailer parameter to the Anime component which should be the latest valid trailer that we have. Otherwise, we don't display the trailer component. --- pages/anime/anime.go | 19 ++++++++++++++++++- pages/anime/anime.pixy | 25 +++++++++++-------------- 2 files changed, 29 insertions(+), 15 deletions(-) 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 0d361bc4c..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,16 +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].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 - a(href=anime.TrailersLink()) Trailer - .anime-trailer.video-container - iframe.video.lazy(data-src=anime.Trailers[index].EmbedLink(), 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