]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
eit: Also scrape eit episode information from title and description (#4592)
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Thu, 21 Sep 2017 00:20:05 +0000 (01:20 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sun, 24 Sep 2017 07:05:51 +0000 (09:05 +0200)
Previously we only searched the summary for scraping episode information,
but several countries also put the information in the title or description.
So we search each one in turn with the same regex and merge the results.

Issue: #4592

src/epggrab/module/eit.c

index 814b859ef5086a6a1a46100f6260c94b1a3e8fdf..ed403ea5252fad6e3a92d411d4ede0c197d35af4 100644 (file)
@@ -430,6 +430,58 @@ static int _eit_desc_crid
   return 0;
 }
 
+/* Scrape episode data from the broadcast data.
+ * @param text - string from broadcaster to search.
+ * @param eit_mod - our module with regex to use.
+ * @param en - [out] episode data
+ * @param first_aired - [out] airdate
+ * @return Bitmask of changed fields.
+ */
+static uint32_t
+_eit_scrape_episode(const char *str,
+                    eit_module_t *eit_mod,
+                    epg_episode_num_t *en,
+                    time_t *first_aired)
+{
+  if (!str) return 0;
+
+  uint32_t changed = 0;
+  /* search for season number */
+  char buffer[2048];
+  if (eit_pattern_apply_list(buffer, sizeof(buffer), str, &eit_mod->p_snum))
+    if ((en->s_num = atoi(buffer))) {
+      tvhtrace(LS_TBL_EIT,"  extract season number %d using %s", en->s_num, eit_mod->id);
+      changed |= EPG_CHANGED_EPSER_NUM;
+    }
+
+  /* ...for episode number */
+  if (eit_pattern_apply_list(buffer, sizeof(buffer), str, &eit_mod->p_enum))
+    if ((en->e_num = atoi(buffer))) {
+      tvhtrace(LS_TBL_EIT,"  extract episode number %d using %s", en->e_num, eit_mod->id);
+      changed |= EPG_CHANGED_EPNUM_NUM;
+    }
+
+  /* Extract original air date year */
+  if (eit_pattern_apply_list(buffer, sizeof(buffer), str, &eit_mod->p_airdate)) {
+    if (strlen(buffer) == 4) {
+      /* Year component only */
+      const int year = atoi(buffer);
+      if (year) {
+        struct tm airdate;
+        memset(&airdate, 0, sizeof(airdate));
+        airdate.tm_year = year - 1900;
+        /* Remaining fields in airdate can all remain at zero but day
+         * of month is one-based
+         */
+        airdate.tm_mday = 1;
+        *first_aired = mktime(&airdate);
+        changed |= EPG_CHANGED_FIRST_AIRED;
+      }
+    }
+  }
+  return changed;
+}
+
 
 /* ************************************************************************
  * EIT Event
@@ -601,45 +653,28 @@ static int _eit_process_event_one
     ee = epg_episode_find_by_broadcast(ebc, mod, 1, save, &changes4);
   }
 
+  /* Scrape episode from within broadcast data */
   epg_episode_num_t en;
   memset(&en, 0, sizeof(en));
-  /* We use a separate "first_aired_set" variable otherwise
-   * we don't know the difference between a null date and a
-   * programme that happened to start in 1974.
-   */
   time_t first_aired = 0;
-  int    first_aired_set = 0;
-
-  if (ev.summary && eit_mod->scrape_episode) {
-    /* search for season number */
-    char buffer[2048];
-    const char* summary = lang_str_get(ev.summary, ev.default_charset);
-    if (eit_pattern_apply_list(buffer, sizeof(buffer), summary, &eit_mod->p_snum))
-      if ((en.s_num = atoi(buffer)))
-        tvhtrace(LS_TBL_EIT,"  extract season number %d using %s", en.s_num, mod->id);
-    /* ...for episode number */
-    if (eit_pattern_apply_list(buffer, sizeof(buffer), summary, &eit_mod->p_enum))
-      if ((en.e_num = atoi(buffer)))
-        tvhtrace(LS_TBL_EIT,"  extract episode number %d using %s", en.e_num, mod->id);
-
-    /* Extract original air date year */
-    if (eit_pattern_apply_list(buffer, sizeof(buffer), summary, &eit_mod->p_airdate)) {
-      if (strlen(buffer) == 4) {
-        /* Year component only */
-        const int year = atoi(buffer);
-        if (year) {
-          struct tm airdate;
-          memset(&airdate, 0, sizeof(airdate));
-          airdate.tm_year = year - 1900;
-          /* Remaining fields in airdate can all remain at zero but day
-           * of month is one-based
-           */
-          airdate.tm_mday = 1;
-          first_aired = mktime(&airdate);
-          first_aired_set = 1;
-        }
-      }
-    }
+  uint32_t scraped = 0;
+
+  /* We search across all the main fields using the same regex and
+   * merge the results with the last match taking precendence.  So if
+   * EIT has episode in title and a different one in the description
+   * then we use the one from the description.
+   */
+  if (eit_mod->scrape_episode) {
+    if (ev.title)
+      scraped |=  _eit_scrape_episode(lang_str_get(ev.title, ev.default_charset),
+                                      eit_mod, &en, &first_aired);
+    if (ev.desc)
+      scraped |=  _eit_scrape_episode(lang_str_get(ev.desc, ev.default_charset),
+                                      eit_mod, &en, &first_aired);
+
+    if (ev.summary)
+      scraped |= _eit_scrape_episode(lang_str_get(ev.summary, ev.default_charset),
+                                     eit_mod, &en, &first_aired);
   }
 
   /* Update Episode */
@@ -682,7 +717,7 @@ static int _eit_process_event_one
     /* save any found episode number */
     if (en.s_num || en.e_num || en.p_num)
       *save |= epg_episode_set_epnum(ee, &en, &changes4);
-    if (first_aired_set)
+    if (scraped & EPG_CHANGED_FIRST_AIRED)
       *save |= epg_episode_set_first_aired(ee, first_aired, &changes4);
 
     *save |= epg_episode_change_finish(ee, changes4, 0);