Implemented song_fetch_url
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-05-21 16:02:03 +02:00
parent fe161e98a4
commit 6b3aaf7d0b
Signed by: DataHoarder
SSH key fingerprint: SHA256:EnPQOqPpbCa7nzalCEJY2sd9iPluFIBuJu2rDFalACI
4 changed files with 18 additions and 6 deletions

15
api.go
View file

@ -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

View file

@ -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"`

View file

@ -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.

View file

@ -158,7 +158,9 @@ func (r *RangeReadSeekCloser) Seek(offset int64, whence int) (int64, error) {
}
if r.i < r.ib || r.i >= r.ib+int64(len(r.buf)) {
r.body.Close()
if r.body != nil {
r.body.Close()
}
r.body = nil
}