]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
dvr: Allow autorec by star rating. (#4665)
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Fri, 22 Sep 2017 13:31:18 +0000 (14:31 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 16 Oct 2017 16:11:08 +0000 (18:11 +0200)
This allows limited an autorec to "movies rated better than 80%".

Issue: #4655

src/dvr/dvr.h
src/dvr/dvr_autorec.c
src/webui/static/app/dvr.js

index 603e2b7de8360639daeb1672bc45784d02f334f3..946bab73c4627b45d148bb097e1f8af9f224c3cc 100644 (file)
@@ -354,6 +354,7 @@ typedef struct dvr_autorec_entry {
   char *dae_cat1;                 /** Simple single category from drop-down selection boxes */
   char *dae_cat2;                 /** Simple single category from drop-down selection boxes */
   char *dae_cat3;                 /** Simple single category from drop-down selection boxes */
+  uint16_t dae_star_rating;       /** Minimum star rating: we use u16 instead of u8 since no PT_U8 type */
 
   int dae_start;        /* Minutes from midnight */
   int dae_start_window; /* Minutes (duration) */
index 726aa9fdb80cb12269e99edf81baf726b00e06bb..d10f2f5fc066ebfc2591d5b632e227b1b6af451c 100644 (file)
@@ -266,6 +266,16 @@ autorec_cmp(dvr_autorec_entry_t *dae, epg_broadcast_t *e)
       return 0;
   }
 
+  /* If we have a dae_star_rating but the episode has no star
+   * rating (zero) then it will not be recorded.  So we do not
+   * have "&& e->episode->star_rating" here.  Conversely, if
+   * dae_star_rating is zero then that means "do not check
+   * star rating of episode".
+   */
+  if (e->episode && dae->dae_star_rating)
+    if (e->episode->star_rating < dae->dae_star_rating)
+      return 0;
+
   /* Do not check title if the event is from the serieslink group */
   if(dae->dae_serieslink == NULL &&
      dae->dae_title != NULL && dae->dae_title[0] != '\0') {
@@ -907,6 +917,47 @@ dvr_autorec_entry_class_season_get(void *o)
   return &prop_ptr;
 }
 
+/** Validate star rating is in range */
+static int
+dvr_autorec_entry_class_star_rating_set(void *o, const void *v)
+{
+  dvr_autorec_entry_t *dae = (dvr_autorec_entry_t *)o;
+  const uint16_t *val = (uint16_t*)v;
+  if (*val < 0 || *val > 100)
+    return 0;
+  dae->dae_star_rating = *val;
+  return 1;
+}
+
+static htsmsg_t *
+dvr_autorec_entry_class_star_rating_list ( void *o, const char *lang )
+{
+  htsmsg_t *m = htsmsg_create_list();
+  htsmsg_t *e = htsmsg_create_map();
+  /* No htsmsg_add_u16 so use htsmsg_add_u32 instead */
+  htsmsg_add_u32(e, "key", 0);
+  /* Instead of "Any" we use "No rating needed" since "Any" could
+   * suggest that the programme needs a rating that could be anything,
+   * whereas many programmes have no rating at all.
+   */
+  htsmsg_add_str(e, "val", tvh_gettext_lang(lang, N_("No rating needed")));
+  htsmsg_add_msg(m, NULL, e);
+
+  uint32_t i;
+  /* We create the list from highest to lowest since you're more
+   * likely to want to record something with a high rating than scroll
+   * through the list to find programmes with a poor rating.
+   */
+  for (i = 100; i > 0 ; i-=5) {
+    e = htsmsg_create_map();
+    htsmsg_add_u32(e, "key", i);
+    htsmsg_add_u32(e, "val", i);
+    htsmsg_add_msg(m, NULL, e);
+  }
+  return m;
+}
+
+
 static int
 dvr_autorec_entry_class_series_link_set(void *o, const void *v)
 {
@@ -1159,6 +1210,18 @@ const idclass_t dvr_autorec_entry_class = {
       .off      = offsetof(dvr_autorec_entry_t, dae_content_type),
       .opts     = PO_ADVANCED,
     },
+    {
+      .type     = PT_U16,
+      .id       = "star_rating",
+      .name     = N_("Star rating"),
+      .desc     = N_("The minimum number of stars the broadcast should have - in "
+                     "other words, only match programs that have at "
+                     "least this rating."),
+      .set      = dvr_autorec_entry_class_star_rating_set,
+      .list     = dvr_autorec_entry_class_star_rating_list,
+      .off      = offsetof(dvr_autorec_entry_t, dae_star_rating),
+      .opts     = PO_EXPERT | PO_DOC_NLIST,
+    },
     {
       .type     = PT_STR,
       .id       = "start",
index 20853b48eda33de6cc70d811a05dabe1837d0ebf..c5bb7bd1e455c8791327236ab065f6d376d56c12 100644 (file)
@@ -746,7 +746,7 @@ tvheadend.autorec_editor = function(panel, index) {
 
     var list = 'name,title,fulltext,channel,start,start_window,weekdays,' +
                'record,tag,btype,content_type,cat1,cat2,cat3,minduration,maxduration,' +
-               'dedup,directory,config_name,comment';
+               'star_rating,dedup,directory,config_name,comment';
     var elist = 'enabled,start_extra,stop_extra,' +
                 (tvheadend.accessUpdate.admin ?
                 list + ',owner,creator' : list) + ',pri,retention,removal,maxcount,maxsched';
@@ -787,6 +787,7 @@ tvheadend.autorec_editor = function(panel, index) {
             removal:      { width: 80 },
             maxcount:     { width: 80 },
             maxsched:     { width: 80 },
+            star_rating:  { width: 80 },
             config_name:  { width: 120 },
             owner:        { width: 100 },
             creator:      { width: 200 },
@@ -807,7 +808,7 @@ tvheadend.autorec_editor = function(panel, index) {
         del: true,
         list: 'enabled,name,title,fulltext,channel,tag,start,start_window,' +
               'weekdays,minduration,maxduration,btype,content_type,cat1,cat2,cat3' +
-              'pri,dedup,directory,config_name,owner,creator,comment',
+              'star_rating,pri,dedup,directory,config_name,owner,creator,comment',
         sort: {
           field: 'name',
           direction: 'ASC'