46 lines
1.0 KiB
Go
Raw Normal View History

2017-10-02 06:29:58 +02:00
package soundtrack
2017-06-28 00:16:45 +02:00
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-11-05 14:54:58 -04:00
"github.com/animenotifier/notify.moe/utils"
2017-06-28 00:16:45 +02:00
)
2017-07-13 08:23:20 +02:00
// Get track.
2017-06-28 00:16:45 +02:00
func Get(ctx *aero.Context) string {
id := ctx.Get("id")
track, err := arn.GetSoundTrack(id)
2017-11-05 14:54:58 -04:00
user := utils.GetUser(ctx)
2017-06-28 00:16:45 +02:00
if err != nil {
return ctx.Error(http.StatusNotFound, "Track not found", err)
}
2017-10-18 22:09:17 +02:00
openGraph := &arn.OpenGraph{
2017-07-21 16:33:29 +02:00
Tags: map[string]string{
2017-10-09 16:23:18 +02:00
"og:title": track.Title,
2017-07-21 16:33:29 +02:00
"og:url": "https://" + ctx.App.Config.Domain + track.Link(),
"og:site_name": "notify.moe",
"og:type": "music.song",
},
}
2017-10-15 20:19:45 +02:00
if track.MainAnime() != nil {
2017-11-09 18:31:32 +01:00
openGraph.Tags["og:image"] = track.MainAnime().Image("large")
2017-10-15 20:19:45 +02:00
}
2017-10-18 22:09:17 +02:00
// Set video so that it can be played
2017-10-18 22:28:47 +02:00
youtube := track.MediaByService("Youtube")
2017-10-18 22:09:17 +02:00
if len(youtube) > 0 {
openGraph.Tags["og:video"] = "https://www.youtube.com/v/" + youtube[0].ServiceID
}
ctx.Data = openGraph
2018-03-13 01:49:54 +01:00
return ctx.HTML(components.SoundTrackPage(track, user))
2017-06-28 00:16:45 +02:00
}