43 lines
982 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"
2021-11-22 12:50:47 +00:00
minio "github.com/minio/minio-go/v7"
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")
2019-08-28 08:06:42 +00:00
// Get episode
episode, err := arn.GetEpisode(id)
2018-12-11 06:37:15 +00:00
if err != nil {
2019-08-28 08:06:42 +00:00
return ctx.Error(http.StatusNotFound, "Episode not found", err)
2018-12-11 06:37:15 +00:00
}
// Get anime
2019-08-28 08:06:42 +00:00
anime := episode.Anime()
2018-12-11 06:37:15 +00:00
2019-08-28 08:06:42 +00:00
if anime == nil {
2018-12-11 06:37:15 +00:00
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
2021-11-22 12:50:47 +00:00
obj, err := arn.Spaces.GetObject(ctx.Request().Context(), "arn", fmt.Sprintf("videos/anime/%s/%d.%s.vtt", anime.ID, episode.Number, language), minio.GetObjectOptions{})
2018-12-11 06:37:15 +00:00
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
}