Proxy subtitles from S3
This commit is contained in:
@ -13,7 +13,7 @@ component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, episodeIndex
|
||||
.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)
|
||||
track(label="English", kind="subtitles", srclang="en", src=fmt.Sprintf("/anime/%s/episode/%d/subtitles/en", anime.ID, episode.Number), default)
|
||||
|
||||
VideoControls("stream-test", time.Duration(0))
|
||||
else
|
||||
|
50
pages/episode/subtitles.go
Normal file
50
pages/episode/subtitles.go
Normal file
@ -0,0 +1,50 @@
|
||||
package episode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
minio "github.com/minio/minio-go"
|
||||
)
|
||||
|
||||
// Subtitles returns the subtitles.
|
||||
func Subtitles(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
language := ctx.Get("language")
|
||||
episodeNumber, err := ctx.GetInt("episode-number")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusBadRequest, "Episode is not a number", err)
|
||||
}
|
||||
|
||||
// Get anime
|
||||
anime, err := arn.GetAnime(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
ctx.Response().Header().Set("Access-Control-Allow-Origin", "*")
|
||||
ctx.Response().Header().Set("Content-Type", "text/vtt; charset=utf-8")
|
||||
|
||||
obj, err := spaces.GetObject("arn", fmt.Sprintf("videos/anime/%s/%d.%s.vtt", anime.ID, episodeNumber, language), minio.GetObjectOptions{})
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
defer obj.Close()
|
||||
|
||||
data := make([]byte, 0, 65535)
|
||||
buffer := make([]byte, 4096)
|
||||
n := 0
|
||||
|
||||
for err == nil {
|
||||
n, err = obj.Read(buffer)
|
||||
data = append(data, buffer[:n]...)
|
||||
}
|
||||
|
||||
return string(data)
|
||||
}
|
@ -3,7 +3,7 @@ package pages
|
||||
import (
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/aerogo/layout"
|
||||
"github.com/animenotifier/notify.moe/layout"
|
||||
fullpage "github.com/animenotifier/notify.moe/layout"
|
||||
"github.com/animenotifier/notify.moe/pages/index/amvroutes"
|
||||
"github.com/animenotifier/notify.moe/pages/index/animeroutes"
|
||||
"github.com/animenotifier/notify.moe/pages/index/apiroutes"
|
||||
@ -38,7 +38,7 @@ func Configure(app *aero.Application) {
|
||||
exploreroutes.Register(l)
|
||||
amvroutes.Register(l)
|
||||
forumroutes.Register(l)
|
||||
animeroutes.Register(l)
|
||||
animeroutes.Register(l, app)
|
||||
userlistroutes.Register(l)
|
||||
quoteroutes.Register(l)
|
||||
companyroutes.Register(l)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package animeroutes
|
||||
|
||||
import (
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/aerogo/layout"
|
||||
"github.com/animenotifier/notify.moe/pages/anime"
|
||||
"github.com/animenotifier/notify.moe/pages/anime/editanime"
|
||||
@ -10,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// Register registers the page routes.
|
||||
func Register(l *layout.Layout) {
|
||||
func Register(l *layout.Layout, app *aero.Application) {
|
||||
// Anime
|
||||
l.Page("/anime/:id", anime.Get)
|
||||
l.Page("/anime/:id/episodes", anime.Episodes)
|
||||
@ -19,6 +20,7 @@ func Register(l *layout.Layout) {
|
||||
l.Page("/anime/:id/relations", anime.Relations)
|
||||
l.Page("/anime/:id/comments", anime.Comments)
|
||||
l.Page("/anime/:id/episode/:episode-number", episode.Get)
|
||||
app.Get("/anime/:id/episode/:episode-number/subtitles/:language", episode.Subtitles)
|
||||
|
||||
// Anime redirects
|
||||
l.Page("/kitsu/anime/:id", anime.RedirectByMapping("kitsu/anime"))
|
||||
|
Reference in New Issue
Block a user