33 lines
669 B
Go
Raw Normal View History

2018-03-11 20:22:33 +01:00
package soundtrack
import (
"math/rand"
"github.com/aerogo/aero"
2019-06-03 18:32:43 +09:00
"github.com/animenotifier/notify.moe/arn"
2018-03-11 20:22:33 +01:00
)
// Random returns a random soundtrack.
2019-06-01 13:55:49 +09:00
func Random(ctx aero.Context) error {
2018-03-11 22:42:58 +01:00
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
return !track.IsDraft
})
2018-03-11 20:22:33 +01:00
index := rand.Intn(len(tracks))
track := tracks[index]
return ctx.JSON(track)
}
// Next returns the next soundtrack for the audio player.
2019-06-01 13:55:49 +09:00
func Next(ctx aero.Context) error {
2018-03-11 20:22:33 +01:00
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
2018-03-11 22:42:58 +01:00
return !track.IsDraft && track.File != ""
2018-03-11 20:22:33 +01:00
})
index := rand.Intn(len(tracks))
track := tracks[index]
return ctx.JSON(track)
}