63 lines
1.5 KiB
Go
Raw Normal View History

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