2018-03-11 19:22:33 +00:00
|
|
|
package soundtrack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Random returns a random soundtrack.
|
|
|
|
func Random(ctx *aero.Context) string {
|
2018-03-11 21:42:58 +00:00
|
|
|
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
|
|
|
return !track.IsDraft
|
|
|
|
})
|
|
|
|
|
2018-03-11 19:22:33 +00:00
|
|
|
index := rand.Intn(len(tracks))
|
|
|
|
track := tracks[index]
|
|
|
|
|
|
|
|
return ctx.JSON(track)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next returns the next soundtrack for the audio player.
|
|
|
|
func Next(ctx *aero.Context) string {
|
|
|
|
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
2018-03-11 21:42:58 +00:00
|
|
|
return !track.IsDraft && track.File != ""
|
2018-03-11 19:22:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
index := rand.Intn(len(tracks))
|
|
|
|
track := tracks[index]
|
|
|
|
|
|
|
|
return ctx.JSON(track)
|
|
|
|
}
|