]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
api: Alternative showings match on title if no series link, fixes #5402
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Sun, 9 Dec 2018 14:12:03 +0000 (14:12 +0000)
committerJaroslav Kysela <perex@perex.cz>
Wed, 2 Jan 2019 14:53:39 +0000 (15:53 +0100)
Some broadcasts do not have series link, so alternative showings returned
an empty list.

Instead, if we have no series link then we do a grid query to find
entries that match by title.

Fixes: #5402
src/api/api_epg.c
src/epg.c
src/epg.h

index 8a2709cb11d0a2bdfdaca0a599eb77634f2ed88f..61b9e77dfabb28630f2810117361d862046168cc 100644 (file)
@@ -628,8 +628,9 @@ api_epg_related
   uint32_t id, entries = 0;
   htsmsg_t *l = htsmsg_create_list();
   epg_broadcast_t *e;
-  char *lang;
-  epg_set_t *serieslink;
+  char *lang, *title_esc, *title_anchor;
+  epg_set_t *serieslink = NULL;
+  const char *title = NULL;
   
   if (htsmsg_get_u32(args, "eventId", &id))
     return -EINVAL;
@@ -638,9 +639,34 @@ api_epg_related
   lang = access_get_lang(perm, htsmsg_get_str(args, "lang"));
   tvh_mutex_lock(&global_lock);
   e = epg_broadcast_find_by_id(id);
-  serieslink = e->serieslink;
-  if (serieslink)
+  /* e might not exist if it is a dvr entry that does not exist in the epg */
+  if (e)
+    serieslink = e->serieslink;
+  if (serieslink) {
     entries = api_epg_episode_sorted(serieslink, perm, l, lang, e);
+  } else {
+    /* Ensure we have a title in the query we are generating.  If no
+     * title, then we return a dummy message.
+     */
+    title = epg_broadcast_get_title(e, lang);
+    if (title) {
+      /* Need to escape/anchor the search, otherwise the film "elf"
+       *  matches titles containing "self".
+       */
+      title_esc = regexp_escape(title);
+      title_anchor = alloca(strlen(title_esc) + 3);
+      sprintf(title_anchor, "^%s$", title_esc);
+      htsmsg_add_str(args, "title", title_anchor);
+      free(title_esc);
+
+      /* Have to unlock here since grid will re-lock */
+      tvh_mutex_unlock(&global_lock);
+      free(lang);
+      /* And let the grid do the query for us */
+      return api_epg_grid(perm, opaque, op, args, resp);
+    }
+    /*FALLTHRU*/
+  }
 
   tvh_mutex_unlock(&global_lock);
   free(lang);
index 7fca87c043db15e7d930273d3c63683fd6bee612..093cc1a633befeb45dbb55aa03d16177b0d36964 100644 (file)
--- a/src/epg.c
+++ b/src/epg.c
@@ -1466,7 +1466,7 @@ epg_broadcast_t *epg_broadcast_get_next ( epg_broadcast_t *b )
   return RB_NEXT(b, sched_link);
 }
 
-const char *epg_broadcast_get_title ( epg_broadcast_t *b, const char *lang )
+const char *epg_broadcast_get_title ( const epg_broadcast_t *b, const char *lang )
 {
   if (!b || !b->title) return NULL;
   return lang_str_get(b->title, lang);
index 84d872c4b743e98de666cf998509303da0886949..b81589c869b6ae11483dbbbfc91f5ff6912c6462 100644 (file)
--- a/src/epg.h
+++ b/src/epg.h
@@ -420,7 +420,7 @@ int epg_broadcast_set_age_rating
 epg_broadcast_t *epg_broadcast_get_prev( epg_broadcast_t *b );
 epg_broadcast_t *epg_broadcast_get_next( epg_broadcast_t *b );
 const char *epg_broadcast_get_title 
-  ( epg_broadcast_t *b, const char *lang );
+  ( const epg_broadcast_t *b, const char *lang );
 const char *epg_broadcast_get_subtitle
   ( epg_broadcast_t *b, const char *lang );
 const char *epg_broadcast_get_summary