eventfilters.rst 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. EventFilters
  2. ================
  3. What is an event filter? It is a mechanism to filter songs before adding them to the playlist.
  4. Why is it any useful? To implement something better than a priority system!
  5. Real world example: you have many events. Some are very long ("shows"), some are short ("jingle"). If you
  6. have a long show of 2hours, and a jingle every 15minutes, then at the end of your jingle you'll find 8 jingle
  7. stacked. That's bad! How to fix it? There are many solutions, none of them is very general or suits every
  8. need. EventFilter is a mechanism to have multiple filters running serially to find a reason to exclude an
  9. event.
  10. Using an event filter
  11. -----------------------
  12. larigira provides some basic filter. A simple example can be "maxwait". The principle is just "don't
  13. add new events if the current playing song still needs more than X seconds to finish". Setting this to, for
  14. example, 15 minutes, would have found only one jingle in the previous example. Great job!
  15. However, it wouldn't be very kind of long shows. If you have two long shows, each 2h long, scheduled let's say
  16. at 8:00 and 9:30. Now the second show won't start, because there is 30min remaining, and the maxwait is set
  17. to 15min. If you have this solution, maybe *percentwait* will better suit your needs. Set this to 200%, and
  18. a jingle can wait up to twice its own duration. This is like setting maxtime=4hours for the long shows, but
  19. maxtime=1minute for jingles. Nice!
  20. Examples
  21. ----------
  22. Fixed wait
  23. ~~~~~~~~~~~~~~~
  24. This snippet will configure larigira to wait a maximum of 5 minutes::
  25. LARIGIRA_EVENT_FILTERS='["maxwait"]'
  26. LARIGIRA_EF_MAXWAIT_SEC=300
  27. (60*5 = 300seconds). This will basically cancel any event that finds a currently playing audio not at its end.
  28. It can be recommended if you have very accurate timing or don't care about "losing" shows because the one
  29. preceding it lasted for too long.
  30. Relative wait
  31. ~~~~~~~~~~~~~~~~
  32. This will configure larigira so that a 1-minute jingle can wait for a maximum of 4minutes, while a 20minutes
  33. event can wait up to 1h20min::
  34. LARIGIRA_EVENT_FILTERS='["percentwait"]'
  35. LARIGIRA_EF_MAXWAIT_PERC=400
  36. In fact, ``400`` means 400%, that is 4 times the lenght of what we're adding
  37. Write your own
  38. ----------------
  39. You probably have some very strange usecase here. Things to decide based on your custom naming convention,
  40. time of the day, moon phase, whatever. So you can and should write your own eventfilter. It often boils down
  41. to very simple python functions and configuration of an entrypoint for the `larigira.eventfilter` entrypoint.