]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
eit: Allow EIT scraping of season/episode to be disabled at GUI. (#4287).
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Wed, 6 Sep 2017 00:14:03 +0000 (01:14 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 8 Sep 2017 06:29:45 +0000 (08:29 +0200)
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

src/epggrab.h
src/epggrab/module.c
src/epggrab/module/eit.c
src/epggrab/module/opentv.c
src/epggrab/module/psip.c
src/epggrab/private.h

index e6fff9a0a226b97f4ca3ba664a8d5b7eb5c58c80..d9e9602fd6fcf42b96b757e0b46209a8e299c7cc 100644 (file)
@@ -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
+};
+
 /*
  *
  */
index 73d9a0c50f0edb040b0bdfb33e488de000a992c6..f8bc015e9cd2a0002c10a046b571453f5ffb5d1c 100644 (file)
@@ -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 */
index 8fc8fafe709d754173ebab2533c4028d64273ea1..e9b6fb8f864de6a9df3d977d94fecaa52d2cff4f 100644 (file)
@@ -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, \
   }
index 3740ebd25929cb3c79220f42849f2b7b12cb3d36..b5978c264b804489f7aa9feb76dd46ee58c1e67a 100644 (file)
@@ -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;
index 68c56f74b7a535c631e33165afc63ec213c96b61..45cf2d6ef6175d90219d2cb8fedfec2d7d7d51c0 100644 (file)
@@ -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 )
index 2e9effcb3181327480bc7ded9d8f88a7ea443809..98eeec038ead0fa2dbd617b4de299c71de1a9f48 100644 (file)
@@ -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 );
 
 /* **************************************************************************