Hi Richard,
I'm glad to see that you have found a way to fix your issue. Thanks for
sharing it back, as well!
Liquidsoap is a powerful tool but, it comes at costs, which is the need to
understand some basic of programming languages, whereas most other tools
will just require configuration files.
A lot of our users come to liquidsoap without a programming background and
this can sometimes be a stiff learning curves, so thanks for trying it!
As to your earlier question, without much knowledge of your programming
background, I'll try to respond in the most simple way.
The liquidsoap language is part of the big family of functional languages.
Contrary to the family of imperative languages, functional languages
usually have two typically different features:
1) Variables are defined, not assigned
2) Functions can be variables
1) means that you can assign a value to a variable but, this value cannot
be changed later, only redefined. Let's try to explain with some dummy code:
# Define value 1 for x
x = 1
def f() =
# Define value 2 for x
x = 2
end
# Execute f
f()
# Print x:
print("The value of x is: #{x}")
If you execute this code, you will see printed:
"The value of x is: 1"
This is because, contrary to imperative languages, you cannot change the
content of a variable.
2) is easier to understand, it means that you can pass functions as
variables. For instance:
def print_yey() =
print("yey!")
end
def execute(f)
f()
end
execute(print_yey)
As you see, the function 'execute' takes another function as argument and
executes it.
Also, an alternative way of writing a function is:
print_yey = fun() -> print("yey!")
This is the same as the function print_yey() = ... above.
Now, let's put this together but, before, add something else.
Some times, the programmer wants to be able to do like imperative languages
allow you to do, which is to assign a value to a variable and later change
it. In order to give that option to the programmer, liquidsoap code can use
references. They work as follow:
# Define a reference:
x = ref 1
# Check the value of a reference
value_assigned_to_x = !x
# Update the value of a reference:
x := 2
You can think of it as a box holding a value that you can open to check or
put a new one in it. Now, let's rework the code for 1) above:
# Assign value 1 to x
x = ref 1
def f() =
# Assign value 2 to x
x := 2
end
# Execute f
f()
# Print x:
print("The value of x is: #{!x}")
This time, you will see:
"The value of x is: 2"
Hope all of this makes sense. Now we can see what the Centova code is doing:
centovacast.callback_autodj := fun(s) -> map_metadata(apply_metadata,s)
Let's look at the left hand.. We recognize a reference, named
centovacast.callback_autodj. This reference is being assigned a variable
value that is a function, defined with the typical fun(s) -> ...
So, what's happening here is that Centova gives you the possibility to
assign a callback function to the centovacast.callback_autodj reference.
Later on, when Centova's streams are processed, this reference is opened
and the function assigned to it will be applied to the stream's metadata.
This is a nice and user-friendly way of letting the user injects his/her
own code into their streaming setup without having to edit the Centova code.
Hope that this makes some sense :-)
Romain
2017-07-30 10:14 GMT-05:00 Richard G Elen <[email protected]>:
> Hi, all...
>
> I have now successfully implemented this feature.
>
> The requirement here is to get a liquidsoap AutoDJ on a Centova v3 system
> to include the Album name in the metadata it sends to a player, and so that
> the information is also accessible by StreamLicensing if you use them,
> where including the Album tag is now mandatory (and a good idea, as you can
> indicate non-copyright items like jingles or sponsor messages with the
> Album tag "*****" and reduce your TLH accordingly).
>
> Here is what you need to do to enable this facility. You obviously need
> server access.
>
> Go to the liquidsoap directory for the appropriate stream as follows.
> From
> /usr/local/centovacast/var/vhosts
> cd to the appropriate vhost then go to
> etc/liquidsoap
>
> Edit the file custom.liq - by all means make a backup copy of it first.
> Insert the following:
>
> def apply_metadata(m) =
> title = m["title"]
> artist = m["artist"]
> album = m["album"]
> [("artist","#{artist}"),("title","#{album} - #{title}")]
> end
>
> centovacast.callback_autodj := fun(s) -> map_metadata(apply_metadata,s)
>
>
>
> This routine grabs the title, artist and album from the audio file on the
> server (obviously the audio files on your Centova system need to have a
> valid Album tag). It then writes the Artist field unchanged but rewrites
> the Title field to take the form "Album - Title".
>
> This order means that the Centova Now Playing widgets will display the
> right fields in the right order.
>
> The callback shown ensures that this feature only applies to the AutoDJ -
> your live sources ought to be able to send this themselves, and if they
> can't this data won't be in the stream anyway.
>
> It's possible that StreamLicensing wants to see these the other way round
> (sigh) - in which case you reverse "album" and "title" in the expression
> "#{album} - #{title}". This will screw the widget but you can't have
> everything.
>
> I am a beginner with liquidsoap so I probably can't answer much in the way
> of questions on the implementation.
>
> Many thanks to list member Eduardo Martinez for the original map_metadata
> example from which I was ultimately able to solve this, and to other list
> members who have contributed helpful suggestions.
>
>
> --Richard E
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Savonet-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/savonet-users
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users