From: E.Smith <31170571+azlm8t@users.noreply.github.com> Date: Wed, 6 Sep 2017 00:14:03 +0000 (+0100) Subject: eit: Allow EIT scraping of season/episode to be disabled at GUI. (#4287). X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d0cb77b13b9a0981bfbde9812a8387f94a70ae80;p=thirdparty%2Ftvheadend.git eit: Allow EIT scraping of season/episode to be disabled at GUI. (#4287). We now have a tick box in the OTA configuration to enable/disable the scraping of season/episode numbers from the eit grabbers. This will allow us to add other scrapers and tidy-ups in the future (such as removing "Also in HD" from the summary data or "New:" from the title), and allow the user to disable ones they do not want for very low-spec machines or due to their duplicate rules relying on pre-tidy data. To achieve this configuration, we now derive our eit grabbers to be a "...scraper" type and hook in to the activate callback to load/unload the regular expressions. The loading of the config also had to be moved to the activate rather than in the module create to allow us to access the "scrape enabled" boolean. Issue: #4287 --- diff --git a/src/epggrab.h b/src/epggrab.h index e6fff9a0a..d9e9602fd 100644 --- a/src/epggrab.h +++ b/src/epggrab.h @@ -31,6 +31,7 @@ typedef struct epggrab_module epggrab_module_t; typedef struct epggrab_module_int epggrab_module_int_t; typedef struct epggrab_module_ext epggrab_module_ext_t; typedef struct epggrab_module_ota epggrab_module_ota_t; +typedef struct epggrab_module_ota_scraper epggrab_module_ota_scraper_t; typedef struct epggrab_ota_mux epggrab_ota_mux_t; typedef struct epggrab_ota_map epggrab_ota_map_t; typedef struct epggrab_ota_svc_link epggrab_ota_svc_link_t; @@ -260,6 +261,15 @@ struct epggrab_module_ota void *opaque; }; +/* + * Over the air grabber that supports configurable scraping of data. + */ +struct epggrab_module_ota_scraper +{ + epggrab_module_ota_t ; ///< Parent object + int scrape_episode; ///< Scrape season/episode from EIT summary +}; + /* * */ diff --git a/src/epggrab/module.c b/src/epggrab/module.c index 73d9a0c50..f8bc015e9 100644 --- a/src/epggrab/module.c +++ b/src/epggrab/module.c @@ -221,6 +221,23 @@ const idclass_t epggrab_mod_ota_class = { } }; +const idclass_t epggrab_mod_ota_scraper_class = { + .ic_super = &epggrab_mod_ota_class, + .ic_class = "epggrab_mod_ota_scraper", + .ic_caption = N_("Over-the-air EPG grabber with scraping"), + .ic_properties = (const property_t[]){ + { + .type = PT_BOOL, + .id = "scrape_episode", + .name = N_("Scrape Episode"), + .desc = N_("Enable/disable scraping episode from the grabber."), + .off = offsetof(epggrab_module_ota_scraper_t, scrape_episode), + .group = 1, + }, + {} + } +}; + /* ************************************************************************** * Generic module routines * *************************************************************************/ @@ -591,14 +608,15 @@ epggrab_module_ext_t *epggrab_module_ext_create epggrab_module_ota_t *epggrab_module_ota_create ( epggrab_module_ota_t *skel, const char *id, int subsys, const char *saveid, - const char *name, int priority, + const char *name, int priority, int with_scraper, epggrab_ota_module_ops_t *ops ) { if (!skel) skel = calloc(1, sizeof(epggrab_module_ota_t)); /* Pass through */ epggrab_module_create((epggrab_module_t*)skel, - &epggrab_mod_ota_class, + with_scraper ? + &epggrab_mod_ota_scraper_class : &epggrab_mod_ota_class, id, subsys, saveid, name, priority); /* Setup */ diff --git a/src/epggrab/module/eit.c b/src/epggrab/module/eit.c index 8fc8fafe7..e9b6fb8f8 100644 --- a/src/epggrab/module/eit.c +++ b/src/epggrab/module/eit.c @@ -49,7 +49,7 @@ typedef struct eit_private /* Provider configuration */ typedef struct eit_module_t { - epggrab_module_ota_t ; ///< Base struct + epggrab_module_ota_scraper_t ; ///< Base struct eit_pattern_list_t p_snum; eit_pattern_list_t p_enum; } eit_module_t; @@ -81,6 +81,13 @@ typedef struct eit_event } eit_event_t; + +/* + * Forward declarations + */ +static void _eit_module_load_config(eit_module_t *mod); + + /* ************************************************************************ * Diagnostics * ***********************************************************************/ @@ -894,6 +901,30 @@ static int _eit_start return 0; } +static int _eit_activate(void *m, int e) +{ + eit_module_t *mod = m; + tvhtrace(LS_TBL_EIT, "_eit_activate %s change to %d from %d with scrape_episode of %d", mod->id, e, mod->active, mod->scrape_episode); + const int original_status = mod->active; + + /* We expect to be activated/deactivated infrequently so free up the + * lists read from the config files and reload when the scraper is + * activated. This allows user to modify the config files and get + * them re-read easily. + */ + eit_pattern_free_list(&mod->p_snum); + eit_pattern_free_list(&mod->p_enum); + + mod->active = e; + + if (e) { + _eit_module_load_config(mod); + } + + /* Return save if value has changed */ + return e != original_status; +} + static int _eit_tune ( epggrab_ota_map_t *map, epggrab_ota_mux_t *om, mpegts_mux_t *mm ) { @@ -936,18 +967,15 @@ static int _eit_fixup_load_one ( htsmsg_t *m, eit_module_t* mod ) return 1; } -static eit_module_t *eit_module_ota_create - ( const char *id, int subsys, const char *saveid, - const char *name, int priority, - epggrab_ota_module_ops_t *ops ) +static void _eit_module_load_config(eit_module_t *mod) { - eit_module_t * mod = (eit_module_t *) - epggrab_module_ota_create(calloc(1, sizeof(eit_module_t)), - id, subsys, saveid, - name, priority, ops); + if (!mod->scrape_episode) { + tvhinfo(LS_TBL_EIT, "module %s - scraper disabled by config", mod->id); + return; + } const char config_path[] = "epggrab/eit/fixup/%s"; - const char *config_file = id; + const char *config_file = mod->id; /* Attempt to load config file based on grabber id such as * uk_freeview. @@ -960,7 +988,7 @@ static eit_module_t *eit_module_ota_create * be "uk". This allows config for a country to be shared across * two grabbers such as DVB-T and DVB-S. */ - generic_name = strdup(id); + generic_name = strdup(mod->id); if (generic_name) { char *underscore = strstr(generic_name, "_"); if (underscore) { @@ -975,17 +1003,27 @@ static eit_module_t *eit_module_ota_create if (m) { const int r = _eit_fixup_load_one(m, mod); if (r > 0) - tvhinfo(LS_TBL_EIT, "fixup %s loaded %s", id, config_file); + tvhinfo(LS_TBL_EIT, "scraper %s loaded config %s", mod->id, config_file); else - tvhwarn(LS_TBL_EIT, "fixup %s failed", id); + tvhwarn(LS_TBL_EIT, "scraper %s failed to load", mod->id); htsmsg_destroy(m); } else { - tvhinfo(LS_TBL_EIT, "no fixup config files loaded for %s", id); + tvhinfo(LS_TBL_EIT, "no scraper config files loaded for %s", mod->id); } if (generic_name) free(generic_name); +} +static eit_module_t *eit_module_ota_create + ( const char *id, int subsys, const char *saveid, + const char *name, int priority, + epggrab_ota_module_ops_t *ops ) +{ + eit_module_t * mod = (eit_module_t *) + epggrab_module_ota_create(calloc(1, sizeof(eit_module_t)), + id, subsys, saveid, + name, priority, 1, ops); return mod; } @@ -997,6 +1035,7 @@ static eit_module_t *eit_module_ota_create }; \ static epggrab_ota_module_ops_t name = { \ .start = _eit_start, \ + .activate = _eit_activate, \ .tune = _eit_tune, \ .opaque = &opaque_##name, \ } diff --git a/src/epggrab/module/opentv.c b/src/epggrab/module/opentv.c index 3740ebd25..b5978c264 100644 --- a/src/epggrab/module/opentv.c +++ b/src/epggrab/module/opentv.c @@ -918,7 +918,7 @@ static int _opentv_prov_load_one ( const char *id, htsmsg_t *m ) sprintf(nbuf, "OpenTV: %s", name); mod = (opentv_module_t *) epggrab_module_ota_create(calloc(1, sizeof(opentv_module_t)), - ibuf, LS_OPENTV, NULL, nbuf, 2, &ops); + ibuf, LS_OPENTV, NULL, nbuf, 2, 0, &ops); /* Add provider details */ mod->dict = dict; diff --git a/src/epggrab/module/psip.c b/src/epggrab/module/psip.c index 68c56f74b..45cf2d6ef 100644 --- a/src/epggrab/module/psip.c +++ b/src/epggrab/module/psip.c @@ -775,7 +775,7 @@ void psip_init ( void ) .tune = _psip_tune, }; - epggrab_module_ota_create(NULL, "psip", LS_PSIP, NULL, "PSIP: ATSC Grabber", 1, &ops); + epggrab_module_ota_create(NULL, "psip", LS_PSIP, NULL, "PSIP: ATSC Grabber", 1, 0, &ops); } void psip_done ( void ) diff --git a/src/epggrab/private.h b/src/epggrab/private.h index 2e9effcb3..98eeec038 100644 --- a/src/epggrab/private.h +++ b/src/epggrab/private.h @@ -110,7 +110,7 @@ typedef struct epggrab_ota_module_ops { epggrab_module_ota_t *epggrab_module_ota_create ( epggrab_module_ota_t *skel, const char *id, int subsys, const char *saveid, - const char *name, int priority, + const char *name, int priority, int with_scraper, epggrab_ota_module_ops_t *ops ); /* **************************************************************************