Hi Adrian,

Filenames can be functions that are executed every time the file is
created, something like this:

```
def my_filename() =
  "/archive/#{int_of_float(gettimeofday())}.mp3"
end
```

For simple functions like that, we have a simplified syntax that allows to
write them in a short way:
```
my_filename = {"/archive/#{int_of_float(gettimeofday())}.mp3"}
```
So, in your case, all you should have to do to make the filename dynamic in
your example is surround it with { }:
```
output.file(
  %mp3,
  {"/archive/#{int_of_float(gettimeofday())}.mp3"},
  s,
  reopen_when={0m}
)
```

If you want to read a more detailed presentation of the language and more,
I can recommend the liquidsoap book:
https://www.liquidsoap.info/doc-dev/book.html

Le dim. 16 avr. 2023 à 08:42, Adrian <nii...@gmx.com> a écrit :

> Hi everyone and thanks a lot for your work!
>
> I'm trying to adapt the cookbook example "Dump a stream into segmented
> files".
> I'd like to have the filename containing the unix timestamp (or epoch),
> but I don't know what are the possibles "time literals" mentioned in the
> cookbook:
>
> https://www.liquidsoap.info/doc-2.1.4/cookbook.html#dump-a-stream-into-segmented-files
>
> What I'm trying to achieve looks like this:
> output.file(%mp3, '/archive/%s.mp3', s, reopen_when={0m})
> Where %s would be replaced by the unix timestamp (%s taken from the date
> command) but unfortunately, %s is not a "time literal". Plus, I can't find
> any
> definition or list of "time literals" anywhere in the doc or in the
> source code.
>
> I managed to get the unix timestamp in my filename with:
> output.file(%mp3, '/archive/#{int_of_float(gettimeofday())}.mp3', s,
> reopen_when={0m})
> But the time is evaluated at the string creation and not a each file
> opening.
>
> Is it possible for you to document the "time literals"?
> Where can I find this list? And where can I add some new literals if
> needed?
>
> Thank you for your time,
> Niilos
>
>
> _______________________________________________
> Savonet-users mailing list
> Savonet-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/savonet-users
>
_______________________________________________
Savonet-users mailing list
Savonet-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/savonet-users

Reply via email to