Bug #5797

"Automatically map epg source" bug

Added by Antony B over 1 year ago. Updated 9 months ago.

EPG - Grabbers
Target version:
Start date:
Due date:
% Done:


Estimated time:
Found in version:
Affected Versions:


here the steps to reproduce problem:
- I mapped 266 dvb-t channels trough a bouquet (with "auto-map to channel" option enabled). All is ok at this point, epg sources are blank.
- Then i push to external socket (using socat) my XMLTV file 2 times consecutively: first to have epg sources automatically mapped to channels; second to import broadcasts.
- Some epggrab channels are mapped correctly to channels, BUT others are inexplicably NOT mapped to channels; and some are mapped to only one channel when should instead be mapped to more (having same name).

The only way to fix it is mapping again channels (trough disabling and re-enabling bouquet). After this opearation, all epggrab channels are mapped correctly to channels, and i have to socat again xmltv file to import broadcasts of newly mapped channels.
BUT remapping channels is not a route, we lose custom settings made to channels, like custom numbers, custom epg etc.

Look around in the code, i saw "epggrab_channel_autolink()" is called by:
- epggrab_channel_add(), called when channels structure is created or changed (and this seems to work ok)
- epggrab_channel_updated(), calls tre: _xmltv_parse_tv() -> epggrab_channel_end_scan() -> epggrab_channel_updated() -> epggrab_channel_autolink().

So, it seems something is broken or not correct in epggrab_channel_end_scan(), preventing epggrab_channel_updated() to be called.

Any idea?


gitdiff.txt (3.62 KB) gitdiff.txt Antony B, 2019-12-21 05:42
gitdiff.txt (3.95 KB) gitdiff.txt Antony B, 2020-01-03 02:20



Updated by Antony B over 1 year ago

Looking forward, the problem seems that when parsing xmltv file coming from sock, each epggrab channel is mapped to first channel found, the ESC. If there are more channels with the same name, these are not mapped.
Maybe there?

/* Autolink EPG channel to channel */
static int
epggrab_channel_autolink( epggrab_channel_t *ec ) {
channel_t *ch;

if (epggrab_channel_match_epgid(ec, ch))
if (epggrab_channel_link(ec, ch, NULL))
return 1;
if (epggrab_channel_match_name(ec, ch))
if (epggrab_channel_link(ec, ch, NULL))
return 1;
if (epggrab_channel_match_number(ec, ch))
if (epggrab_channel_link(ec, ch, NULL))
return 1;
return 0;

Don't understand here why return on the first channel found. Shoudn't be checked all channels?

While, when we create/change channel structure, all channels are tried to be mapped to an epggrab channel.

void epggrab_channel_add ( channel_t *ch ) {
epggrab_module_t *mod;
epggrab_channel_t *ec;

LIST_FOREACH(mod, &epggrab_modules, link)
RB_FOREACH(ec, &mod->channels, link) {
if (!is_paired(ec))
epggrab_channel_autolink_one(ec, ch);

Updated by Antony B over 1 year ago

I formatted bad the source code above, cannot edit the post, why?!?!


Updated by Antony B over 1 year ago

i was able to fix the problem.
Now all epggrab channels are mapped to channels when xmltv import.
More i tweak a bit the fuzzy logic about "merge same channels", excluding SD, 4k and 8k suffix. More i excluded these characters ;,.:-_
Also, I used the same fuzzy function to merge epg with name matching. Really good EPG mapping now! I think it would need an option in the web interface, but this is too much for me, i don't know tvheaded code so good.

Let me know what do you think about these changes.



Updated by Antony B over 1 year ago

I also note that in m3u lists sometime tag "tvg-id" is like a "channel name normalized", while channel name (the one after ",") contains different suffix that cause missing epg link.
So i added the possibility to match epg id tag with epg grabber channel name and names. This improve a lot epg linking with iptv m3u channels.

The best would be a new tag, maybe named tvh-epg-name="" so that here we can specify the value for matching epg grabber channels by name, instead of using channel name.

Also available in: Atom PDF