From: E.Smith <31170571+azlm8t@users.noreply.github.com> Date: Fri, 22 Sep 2017 13:31:18 +0000 (+0100) Subject: dvr: Allow autorec by star rating. (#4665) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2cb85bf4437918fcacb84b18515e771ae98f496a;p=thirdparty%2Ftvheadend.git dvr: Allow autorec by star rating. (#4665) This allows limited an autorec to "movies rated better than 80%". Issue: #4655 --- diff --git a/src/dvr/dvr.h b/src/dvr/dvr.h index 603e2b7de..946bab73c 100644 --- a/src/dvr/dvr.h +++ b/src/dvr/dvr.h @@ -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) */ diff --git a/src/dvr/dvr_autorec.c b/src/dvr/dvr_autorec.c index 726aa9fdb..d10f2f5fc 100644 --- a/src/dvr/dvr_autorec.c +++ b/src/dvr/dvr_autorec.c @@ -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", diff --git a/src/webui/static/app/dvr.js b/src/webui/static/app/dvr.js index 20853b48e..c5bb7bd1e 100644 --- a/src/webui/static/app/dvr.js +++ b/src/webui/static/app/dvr.js @@ -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'