Match kawa behavior on request matching
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0ae8a7e123
commit
3c21bb520d
|
@ -81,6 +81,8 @@ func main() {
|
||||||
|
|
||||||
queue := NewQueue(config)
|
queue := NewQueue(config)
|
||||||
|
|
||||||
|
var nr *QueueTrackEntry
|
||||||
|
|
||||||
getRandomTrack := func() *QueueTrackEntry {
|
getRandomTrack := func() *QueueTrackEntry {
|
||||||
response, err := http.DefaultClient.Get(config.Queue.RandomSongApi)
|
response, err := http.DefaultClient.Get(config.Queue.RandomSongApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -104,6 +106,16 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendNowRandom := func(nr *QueueTrackEntry) {
|
||||||
|
if config.Queue.NowRandom != "" {
|
||||||
|
jsonData, _ := json.Marshal(nr.original)
|
||||||
|
_, err := http.DefaultClient.Post(config.Queue.NowRandom, "application/json; charset=utf-8", bytes.NewReader(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
@ -112,8 +124,12 @@ func main() {
|
||||||
for {
|
for {
|
||||||
if e := getRandomTrack(); e != nil {
|
if e := getRandomTrack(); e != nil {
|
||||||
queue.QueueEmpty <- e
|
queue.QueueEmpty <- e
|
||||||
|
nr = e
|
||||||
|
sendNowRandom(nr)
|
||||||
} else if e = getFallbackTrack(); e != nil {
|
} else if e = getFallbackTrack(); e != nil {
|
||||||
queue.QueueEmpty <- e
|
queue.QueueEmpty <- e
|
||||||
|
nr = e
|
||||||
|
sendNowRandom(nr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -151,6 +167,11 @@ func main() {
|
||||||
jsonData, _ := json.Marshal(e.original)
|
jsonData, _ := json.Marshal(e.original)
|
||||||
writer.Write(jsonData)
|
writer.Write(jsonData)
|
||||||
}
|
}
|
||||||
|
case "nr":
|
||||||
|
if nr != nil {
|
||||||
|
jsonData, _ := json.Marshal(nr.original)
|
||||||
|
writer.Write(jsonData)
|
||||||
|
}
|
||||||
case "queue":
|
case "queue":
|
||||||
if len(pathSegments) == 2 {
|
if len(pathSegments) == 2 {
|
||||||
if request.Method != "POST" {
|
if request.Method != "POST" {
|
||||||
|
@ -264,6 +285,8 @@ func main() {
|
||||||
writer.Write(jsonData)
|
writer.Write(jsonData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writer.Write([]byte{'n', 'u', 'l', 'l'})
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ This project is a Work in Progress.
|
||||||
* Normalized channels / sample rates for mounts.
|
* Normalized channels / sample rates for mounts.
|
||||||
* Implements ICY metadata
|
* Implements ICY metadata
|
||||||
* Uses sample/timed packet buffers, instead of kawa byte buffers, which cause wild differences between endpoints. Mounts usually align within 0.2s of each other, depending on client.
|
* Uses sample/timed packet buffers, instead of kawa byte buffers, which cause wild differences between endpoints. Mounts usually align within 0.2s of each other, depending on client.
|
||||||
|
* Implements `queue.nr` and `/nr` (To be Deprecated/Changed)
|
||||||
|
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
|
@ -9,6 +9,7 @@ type Config struct {
|
||||||
Queue struct {
|
Queue struct {
|
||||||
RandomSongApi string `toml:"random_song_api"`
|
RandomSongApi string `toml:"random_song_api"`
|
||||||
NowPlaying string `toml:"np"`
|
NowPlaying string `toml:"np"`
|
||||||
|
NowRandom string `toml:"nr"`
|
||||||
FallbackPath string `toml:"fallback"`
|
FallbackPath string `toml:"fallback"`
|
||||||
BufferLengthInKiB int `toml:"buffer_len"`
|
BufferLengthInKiB int `toml:"buffer_len"`
|
||||||
} `toml:"queue"`
|
} `toml:"queue"`
|
||||||
|
|
|
@ -22,6 +22,10 @@ random_song_api="http://localhost:8012/api/random"
|
||||||
# will be identical to the JSON blob in the queue.
|
# will be identical to the JSON blob in the queue.
|
||||||
np="http://localhost:8012/api/np"
|
np="http://localhost:8012/api/np"
|
||||||
#
|
#
|
||||||
|
# An HTTP POST is issued to this URL when Kawa fetches a random track. The body
|
||||||
|
# will be identical to the JSON blob in memory.
|
||||||
|
nr="http://localhost:8012/api/nr"
|
||||||
|
#
|
||||||
# When no tracks are available for whatever reason (such as external service
|
# When no tracks are available for whatever reason (such as external service
|
||||||
# outages), this track will be played.
|
# outages), this track will be played.
|
||||||
fallback="/tmp/in.flac"
|
fallback="/tmp/in.flac"
|
||||||
|
|
Loading…
Reference in a new issue