41 lines
963 B
Go
Raw Normal View History

2018-12-11 06:37:15 +00:00
package episode
import (
"fmt"
"net/http"
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2019-06-03 11:17:09 +00:00
minio "github.com/minio/minio-go/v6"
2018-12-11 06:37:15 +00:00
)
// Subtitles returns the subtitles.
2019-06-01 04:55:49 +00:00
func Subtitles(ctx aero.Context) error {
2018-12-11 06:37:15 +00:00
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)
}
2019-06-01 04:55:49 +00:00
ctx.Response().SetHeader("Access-Control-Allow-Origin", "*")
ctx.Response().SetHeader("Content-Type", "text/vtt; charset=utf-8")
2018-12-11 06:37:15 +00:00
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()
2018-12-12 03:40:28 +00:00
return ctx.ReadAll(obj)
2018-12-11 06:37:15 +00:00
}