Episode page improvements

This commit is contained in:
2018-12-10 13:42:29 +09:00
parent 20a4e31999
commit 2b8288e208
8 changed files with 1166 additions and 29 deletions

View File

@ -1,14 +1,34 @@
package episode
import (
"fmt"
"log"
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
minio "github.com/minio/minio-go"
)
var spaces *minio.Client
func init() {
go func() {
var err error
endpoint := "sfo2.digitaloceanspaces.com"
ssl := true
// Initiate a client using DigitalOcean Spaces.
spaces, err = minio.New(endpoint, arn.APIKeys.S3.ID, arn.APIKeys.S3.Secret, ssl)
if err != nil {
log.Fatal(err)
}
}()
}
// Get renders the anime episode.
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
@ -33,11 +53,19 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
}
// Does the episode exist?
uploaded := false
if spaces != nil {
stat, err := spaces.StatObject("arn", fmt.Sprintf("videos/anime/%s/%d.webm", anime.ID, episodeNumber), minio.StatObjectOptions{})
uploaded = (err == nil) && (stat.Size > 0)
}
episode, episodeIndex := animeEpisodes.Find(episodeNumber)
if episode == nil {
return ctx.Error(http.StatusNotFound, "Anime episode not found")
}
return ctx.HTML(components.AnimeEpisode(anime, episode, episodeIndex, user))
return ctx.HTML(components.AnimeEpisode(anime, episode, episodeIndex, uploaded, user))
}

View File

@ -1,31 +1,31 @@
component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, episodeIndex int, user *arn.User)
component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, episodeIndex int, uploaded bool, user *arn.User)
h1
a(href=anime.Link())= anime.Title.ByUser(user)
if anime.ID == "GWyShKmiR" && episode.Number == 10
.widget-form.amv-page
.video-container(id="stream-test")
video.video.lazy.action(data-action="toggleFullscreen", data-trigger="dblclick", data-id="stream-test")
source(data-src="https://arn.sfo2.cdn.digitaloceanspaces.com/videos/anime/GWyShKmiR/10.webm", data-type="video/webm")
track(label="English", kind="subtitles", srclang="en", src="/subtitles/anime/GWyShKmiR/10.en.vtt", default)
VideoControls("stream-test", time.Duration(0))
.episode-navigation-container
if episodeIndex > 0
.episode-arrow.episode-arrow-previous
a.light-button(href=anime.Link() + "/episode/" + strconv.Itoa(anime.Episodes().Items[episodeIndex - 1].Number), title="Previous episode")
RawIcon("chevron-left")
br
else
.episode-view-image-container
if episodeIndex > 0
.episode-arrow.episode-arrow-previous
a.light-button(href=anime.Link() + "/episode/" + strconv.Itoa(anime.Episodes().Items[episodeIndex - 1].Number), title="Previous episode")
RawIcon("chevron-left")
a(href=anime.Link(), title=anime.Title.ByUser(user))
img.anime-cover-image.lazy(data-src=anime.ImageLink("large"), data-webp="true", data-color=anime.AverageColor(), alt=anime.Title.ByUser(user))
.episode-video
if uploaded
.video-container(id="stream-test")
video.video.lazy.action(data-action="toggleFullscreen", data-trigger="dblclick", data-id="stream-test")
source(data-src=fmt.Sprintf("https://arn.sfo2.cdn.digitaloceanspaces.com/videos/anime/%s/%d.webm", anime.ID, episode.Number), data-type="video/webm")
track(label="English", kind="subtitles", srclang="en", src=fmt.Sprintf("/subtitles/anime/%s/%d.en.vtt", anime.ID, episode.Number), default)
if episodeIndex < len(anime.Episodes().Items) - 1
.episode-arrow.episode-arrow-next
a.light-button(href=anime.Link() + "/episode/" + strconv.Itoa(anime.Episodes().Items[episodeIndex + 1].Number), title="Next episode")
RawIcon("chevron-right")
VideoControls("stream-test", time.Duration(0))
else
.video-container.episode-not-available(title="Episode not available yet")
//- a(href=anime.Link(), title=anime.Title.ByUser(user))
//- img.anime-cover-image.lazy(data-src=anime.ImageLink("large"), data-webp="true", data-color=anime.AverageColor(), alt=anime.Title.ByUser(user))
if episodeIndex < len(anime.Episodes().Items) - 1
.episode-arrow.episode-arrow-next
a.light-button(href=anime.Link() + "/episode/" + strconv.Itoa(anime.Episodes().Items[episodeIndex + 1].Number), title="Next episode")
RawIcon("chevron-right")
h3.episode-view-number= "Episode " + strconv.Itoa(episode.Number)

View File

@ -11,14 +11,20 @@
font-size 0.9rem
half-opacity-text
.episode-view-image-container
.episode-navigation-container
horizontal
justify-content center
align-items center
position relative
height anime-image-large-height
margin-bottom content-padding
.episode-video
width 100%
max-width amv-large-width
.episode-not-available
background reverse-light-color
.episode-arrow
position absolute
top 50%