49 lines
1.2 KiB
Go
Raw Normal View History

2018-04-16 14:11:32 +00:00
package soundtrack
import (
"strings"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
)
func getOpenGraph(ctx *aero.Context, track *arn.SoundTrack) *arn.OpenGraph {
openGraph := &arn.OpenGraph{
Tags: map[string]string{
"og:title": track.Title.ByUser(nil),
"og:url": "https://" + ctx.App.Config.Domain + track.Link(),
"og:site_name": ctx.App.Config.Domain,
"og:type": "music.song",
},
}
descriptionTags := []string{}
for _, tag := range track.Tags {
if strings.HasPrefix(tag, "anime:") {
continue
}
descriptionTags = append(descriptionTags, tag)
}
if track.MainAnime() != nil {
openGraph.Tags["og:image"] = track.MainAnime().ImageLink("large")
openGraph.Tags["og:description"] = track.MainAnime().Title.Canonical + " (" + strings.Join(descriptionTags, ", ") + ")"
}
if track.File != "" {
openGraph.Tags["og:audio"] = "https://" + ctx.App.Config.Domain + "/audio/" + track.File
openGraph.Tags["og:audio:type"] = "audio/vnd.facebook.bridge"
}
// Set video so that it can be played
youtube := track.MediaByService("Youtube")
if len(youtube) > 0 {
openGraph.Tags["og:video"] = "https://www.youtube.com/v/" + youtube[0].ServiceID
}
return openGraph
}