65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (s *State) NowPlayingAPI(c *gin.Context) {
|
|
c.String(http.StatusOK, s.NowPlaying())
|
|
}
|
|
|
|
type PlayAPIform struct {
|
|
Filename string `form:"filename" binding:"required"`
|
|
Seconds int `form:"seconds"`
|
|
}
|
|
|
|
func (s *State) PlayAPI(c *gin.Context) {
|
|
var form PlayAPIform
|
|
if err := c.Bind(&form); err != nil {
|
|
c.String(http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
|
|
if err := s.PlayVideo(form.Filename, form.Seconds); err != nil {
|
|
c.String(http.StatusBadRequest, err.Error())
|
|
} else {
|
|
c.String(http.StatusOK, form.Filename)
|
|
}
|
|
}
|
|
|
|
type PlayRandomAPIform struct {
|
|
Autoplay bool `form:"autoplay"`
|
|
}
|
|
|
|
func (s *State) PlayRandomAPI(c *gin.Context) {
|
|
var form PlayRandomAPIform
|
|
if err := c.BindQuery(&form); err != nil {
|
|
c.String(http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
|
|
s.PlayRandom(form.Autoplay)
|
|
}
|
|
|
|
func (s *State) StopPlayingAPI(c *gin.Context) {
|
|
fmt.Println("Stopping current video")
|
|
s.stopPlaying()
|
|
|
|
if err := s.playFallback(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func (s *State) IsLivestreamReadyAPI(c *gin.Context) {
|
|
ready, err := s.IsLivestreamReady()
|
|
if err != nil {
|
|
c.Status(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
c.String(http.StatusOK, fmt.Sprint(ready))
|
|
}
|