49 lines
1.2 KiB
Go
Raw Normal View History

2018-04-16 14:11:32 +00:00
package soundtrack
import (
"strings"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2019-06-01 04:55:49 +00:00
"github.com/animenotifier/notify.moe/assets"
2018-04-16 14:11:32 +00:00
)
2019-06-05 07:18:04 +00:00
func getOpenGraph(track *arn.SoundTrack) *arn.OpenGraph {
2018-04-16 14:11:32 +00:00
openGraph := &arn.OpenGraph{
Tags: map[string]string{
"og:title": track.Title.ByUser(nil),
2019-06-01 04:55:49 +00:00
"og:url": "https://" + assets.Domain + track.Link(),
"og:site_name": assets.Domain,
2018-04-16 14:11:32 +00:00
"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 != "" {
2019-06-01 04:55:49 +00:00
openGraph.Tags["og:audio"] = "https://" + assets.Domain + "/audio/" + track.File
2018-04-16 14:11:32 +00:00
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
}