savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.35k stars 122 forks source link

2.3.0 - check_next doesn't read metadata #3864

Closed gAlleb closed 2 months ago

gAlleb commented 3 months ago

I'm trying to make check_next work in 2.3.0. It works ok with default filename (with no extra parameters specified). But if I want to reject tracks by title/artist/etc... - it starts looping because metadata always returns empty. Log:

  [
  "",
  1712487606.54
]

In 2.2.5 - All is good.

Reproduction (every 2.3.0 version - packages and opam):

def hash_artist(m)
      metadata.artist(m)
end

l = playlog(persistency="check.log", duration=10000., hash=hash_artist)
def check(r)
      m = request.metadata(r)
  if l.last(m) < 7000. then
      log(level=3,"#{m['artist']} has played #{l.last(m)}s ago. Rejecting...")
      false
  else
      l.add(m)
      true
  end
end
vitoyucepi commented 3 months ago

Hi @gAlleb, I'd like to point out that check_next is called before the request is resolved. So there will be no metadata until the request is resolved. Ref: #3625. I don't remember exactly why I created this issue, but it seems I have a lot of garbage in the music directory and want to discard files before decoding.

gAlleb commented 3 months ago

Hi, @vitoyucepi!

Hm. So many questions then. Why it works ok in 2.2.u-name-it? Why (when using autocue2 e.g. with 2.2.u-name-it) autocue nevertheless processes files and then track gets rejected if it's not due to play?

What should be done to make it work in 2.3.0?

vitoyucepi commented 3 months ago

Why it works ok in 2.2.u-name-it?

The behavior in 2.2.x hasn't been changed.

What should be done to make it work in 2.3.0?

Try request.resolve(r) in your function, before request.metadata(r). Remember to handle the result of the resolve properly.

gAlleb commented 3 months ago

I've tried something like this (and a bunch of different iterations) but result is the same.

def check(r)
        request.uri(r) 
        log.critical(label="request.uri","#{request.uri(r)}")
    if request.resolve(r) then
        log.critical(label="request.resolve","#{request.resolve(r)}")
    m = request.metadata(r)
        log.critical(label="request.metadata","#{request.metadata(r)}")
        if l.last(m) < 7000. then
       log(level=3,"Rejecting")
       false
        else
      l.add(m)
      true
        end
  else
  false
  end

end
2024/04/08 20:30:21 [request.uri:1] /Users/(2018) - Reiki Gold 2 [320]/04. Reiki Stillness and Rest.mp3
2024/04/08 20:30:21 [request.resolve:1] true
2024/04/08 20:30:21 [request.metadata:1] [("filename", "/Users/(2018) - Reiki Gold 2 [320]/04. Reiki Stillness and Rest.mp3"), ("initial_uri", "/Users/(2018) - Reiki Gold 2 [320]/04. Reiki Stillness and Rest.mp3"), ("rid", "11532"), ("status", "ready"), ("temporary", "false")]
2024/04/08 20:30:21 [lang:3] Rejecting

What am I doing wrong?

toots commented 3 months ago

Could be another regression. I'll have a look shortly, thanks for reporting.

vitoyucepi commented 2 months ago

Ref: 28cceeccee26a1b170528857e8c0503069f75e03, 03f65e8f57676388a6068461aae679e70a0f6152, 25e7189ce5a34f5ff7697ccc4800396568dd54e2, #3874, d2a38cf31aa3ed999a45e5443f11c56008ee3c51

gAlleb commented 2 months ago

Many thanks!