Implemented song_fetch_url
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
fe161e98a4
commit
6b3aaf7d0b
15
api.go
15
api.go
|
@ -36,7 +36,7 @@ func (a *API) Wait() {
|
|||
a.wg.Wait()
|
||||
}
|
||||
|
||||
func getQueueEntryFromBody(body []byte) *QueueTrackEntry {
|
||||
func (a *API) getQueueEntryFromBody(body []byte) *QueueTrackEntry {
|
||||
entry := &QueueTrackEntry{}
|
||||
err := json.Unmarshal(body, &entry.original)
|
||||
if err != nil {
|
||||
|
@ -50,7 +50,12 @@ func getQueueEntryFromBody(body []byte) *QueueTrackEntry {
|
|||
var val interface{}
|
||||
var strVal string
|
||||
var ok bool
|
||||
if val, ok = entry.original["path"]; ok {
|
||||
|
||||
if val, ok = entry.original["hash"]; ok && a.config.Queue.SongFetchUrl != "" {
|
||||
if strVal, ok = val.(string); ok {
|
||||
entry.Path = a.config.Queue.SongFetchUrl + strVal
|
||||
}
|
||||
} else if val, ok = entry.original["path"]; ok {
|
||||
if strVal, ok = val.(string); ok {
|
||||
entry.Path = strVal
|
||||
}
|
||||
|
@ -83,7 +88,7 @@ func (a *API) getRandomTrack() *QueueTrackEntry {
|
|||
return nil
|
||||
}
|
||||
|
||||
return getQueueEntryFromBody(body)
|
||||
return a.getQueueEntryFromBody(body)
|
||||
}
|
||||
func (a *API) setNowRandom(nr *QueueTrackEntry) {
|
||||
a.nr = nr
|
||||
|
@ -210,7 +215,7 @@ func (a *API) listen() {
|
|||
if request.Method == "POST" {
|
||||
result := queueResultResponse{}
|
||||
if body, err := ioutil.ReadAll(request.Body); err == nil {
|
||||
if e := getQueueEntryFromBody(body); e != nil {
|
||||
if e := a.getQueueEntryFromBody(body); e != nil {
|
||||
if err = a.queue.AddTrack(e, false); err == nil {
|
||||
result.Success = true
|
||||
result.QueueId = e.QueueIdentifier
|
||||
|
@ -240,7 +245,7 @@ func (a *API) listen() {
|
|||
if request.Method == "POST" {
|
||||
result := queueResultResponse{}
|
||||
if body, err := ioutil.ReadAll(request.Body); err == nil {
|
||||
if e := getQueueEntryFromBody(body); e != nil {
|
||||
if e := a.getQueueEntryFromBody(body); e != nil {
|
||||
if err = a.queue.AddTrack(e, true); err == nil {
|
||||
result.Success = true
|
||||
result.QueueId = e.QueueIdentifier
|
||||
|
|
|
@ -13,6 +13,7 @@ type Config struct {
|
|||
} `toml:"api"`
|
||||
Queue struct {
|
||||
RandomSongApi string `toml:"random_song_api"`
|
||||
SongFetchUrl string `toml:"song_fetch_url"`
|
||||
NowPlaying string `toml:"np"`
|
||||
NowRandom string `toml:"nr"`
|
||||
FallbackPath string `toml:"fallback"`
|
||||
|
|
|
@ -21,7 +21,11 @@ host="127.0.0.1"
|
|||
# It can also be an http(s) URL, that supports Range requests and returns proper Content-Length.
|
||||
# Additionally, the "title", "artist" and "art" properties can be included to be used as metadata.
|
||||
# If "title", "artist" are not specified, file tags may be used.
|
||||
#
|
||||
# If the key "hash" exists and song_fetch_url is set,
|
||||
# hash will be appended and downloaded from that location.
|
||||
random_song_api="http://localhost:8012/api/random"
|
||||
song_fetch_url=""
|
||||
#
|
||||
# An HTTP POST is issued to this URL when MeteorLight starts playing a track. The body
|
||||
# will be identical to the JSON blob in the queue.
|
||||
|
|
Loading…
Reference in a new issue