-
-
Notifications
You must be signed in to change notification settings - Fork 911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[servicemapper]: Allow channel name mapping to be configurable, fixes #5599 #1272
base: master
Are you sure you want to change the base?
Conversation
I think we need to consider:
If there is to be a major release in the next few months, then perhaps I thought an embedded language would be nice since it allows us to I ruled out:
Although we could use an anonymous JS function as the callback, I The JS itself is a relatively small runtime, but it does provide the This feature could have been done using a shell-script, but I can see We could also use it for adding an event system so users could hook
I suspect this JS would be easily fast enough for these cases even on Going forward, I think we should probably allow the user to either As they said in Jurassic Park, "Your scientists were so preoccupied |
Allow user to specify the name they want for a service that is mapped by the service mapper. For example, the UK has numerous regional satellite channels called "ITV" which sometimes show different programmes such as regional news. These should really be called "ITV (London)", "ITV1 (Yorkshire)", etc., to avoid being merged together. Also we have some channels we do not want mapped at all based on criteria such as regex. Although we could manually deselect such channels, it is easier to do it automatically. So we allow user to do this via an embedded JavaScript function. We embed the MIT licence duktape 2.3.0 JavaScript https://duktape.org/ https://wiki.duktape.org/Portability.html The duktape webpage suggests RAM overhead is minimal at less that 100kb. We use the default configuration from the release and use it in the service mapper to allow a user to specify their own script for performing advanced mapping of services to channels. For example, they might want to rename channels such as "SE: Fjorton" to "Fjorton SE", or to capitalize the channel names. These were examples given in the issue #4715. Although this could be possible via more tickboxes, it seems sensible to allow the user to use a script. So we pass an object containing the channel name and service id to the user's script. If they return a name then we use it. If they return null then we do not map the service at all. This allows the user to exclude channels in which they are not interested such as shopping. We also add a JavaScript function "print" to allow the user to log a single string to our logs. This uses the new log level LS_JS. The overhead for calling JavaScript only occurs if the user specifies a script to use. Currently the script is given at the UI such as: ({smMapName : function(svc) { print(svc.name + '/' + svc.sid); return svc.name; }}) Or ({smMapName : function(svc) { print(svc.name + '/' + svc.sid); var svcmap={21000: 'ITV1 HD (London)', 21020: 'ITV1 HD (Meridian, Anglia)'}; var name=svcmap[svc.sid]; return typeof name == 'undefined' ? svc.name : name; }}) The service_mapper looks up the function name "smMapName" and then calls it with the object. We currently don't allow the script to be given as a filename on disk, nor do we attempt to optimize the compilation of such a script to only evaluate it once per mapping (the overhead seems negligible). However, we could add a LRU cache of compiled functions in the future if necessary. One gotcha from using the duktape API is that if you call "duk_safe_to_string" to do debug logging of return values then it appears this coerces the return type on the stack so a subsequent "get" or "is null" check will return incorrect results. So, if the JS function returned null then duk_is_null would return true, but if you do a log of "duk_safe_to_string" afterwards and then check "duk_is_null" then it would return false. Fixes: #5599
a6f5734
to
6015952
Compare
Allow user to specify the name they want for a service that is mapped
by the service mapper. For example, the UK has numerous regional
satellite channels called "ITV" which sometimes show different
programmes such as regional news. These should really be called "ITV
(London)", "ITV1 (Yorkshire)", etc., to avoid being merged together.
Also we have some channels we do not want mapped at all based on
criteria such as regex. Although we could manually deselect such
channels, it is easier to do it automatically.
So we allow user to do this via an embedded JavaScript function.
We embed the MIT licence duktape 2.3.0 JavaScript
https://duktape.org/
https://wiki.duktape.org/Portability.html
The duktape webpage suggests RAM overhead is minimal at less
that 100kb.
We use the default configuration from the release and use it in the
service mapper to allow a user to specify their own script for
performing advanced mapping of services to channels.
For example, they might want to rename channels such as "SE: Fjorton"
to "Fjorton SE", or to capitalize the channel names. These were
examples given in the issue #4715.
Although this could be possible via more tickboxes, it seems sensible
to allow the user to use a script. But should this be JavaScript?
So we pass an object containing the channel name and service id to the
user's script. If they return a name then we use it. If they return
null then we do not map the service at all. This allows the user to
exclude channels in which they are not interested such as shopping.
We also add a JavaScript function "print" to allow the user to log a
single string to our logs. This uses the new log level LS_JS.
The overhead for calling JavaScript only occurs if the user specifies a
script to use.
Currently the script is given at the UI such as:
Or
The service_mapper looks up the function name "smMapName" and then
calls it with the object with a name and sid property.
We currently don't allow the script to be given as a filename on disk,
nor do we attempt to optimize the compilation of such a script to only
evaluate it once per mapping (the overhead seems negligible). However,
we could add a LRU cache of compiled functions in the future if
necessary.
One gotcha from using the duktape API is that if you call
"duk_safe_to_string" to do debug logging of return values then it
appears this coerces the return type on the stack so a subsequent
"get" or "is null" check will return incorrect results.
So, if the JS function returned null then duk_is_null would return
true, but if you do a log of "duk_safe_to_string" afterwards and then
check "duk_is_null" then it would return false.
Fixes: #5599