]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Add country and authority to HTPS messages containing rating labels.
authorDeltaMikeCharlie <127641886+DeltaMikeCharlie@users.noreply.github.com>
Mon, 2 Sep 2024 05:02:52 +0000 (15:02 +1000)
committerFlole <Flole998@users.noreply.github.com>
Fri, 6 Sep 2024 09:04:39 +0000 (11:04 +0200)
src/dvr/dvr.h
src/dvr/dvr_db.c
src/htsp_server.c
src/ratinglabels.c

index 05cceabfc87b221a54ca0dd6606c63bf7ceda78e..b6a27db0eeb853bd46c078c1a9d92364b71dac09 100644 (file)
@@ -249,8 +249,10 @@ typedef struct dvr_entry {
   //may have changed, so keep an absolute copy of the values at
   //the time of recording rather than pointing to a rating label
   //object that may no longer exist many years later.
-  char *de_rating_label_saved;    /* Saved rating label for once the recording has been completed*/
-  char *de_rating_icon_saved;     /* Saved rating icon full path (not image cache) for once the recording has been completed*/
+  char *de_rating_label_saved;       /* Saved rating label for after the recording has been completed*/
+  char *de_rating_icon_saved;        /* Saved rating icon full path (not image cache) for after the recording has been completed*/
+  char *de_rating_country_saved;     /* Saved rating country code for after the recording has been completed*/
+  char *de_rating_authority_saved;   /* Saved rating authority for after the recording has been completed*/
   ratinglabel_t *de_rating_label; /* 'Live' rating label object */
 
   int de_pri;
index fd45b975115372114835fd42f211d27b501ccd99..82e473f5158d34fe6855c82219b654ee21cad981 100644 (file)
@@ -1221,6 +1221,15 @@ dvr_entry_create_from_htsmsg(htsmsg_t *conf, epg_broadcast_t *e)
         if(e->rating_label->rl_icon){
           htsmsg_add_str(conf, "rating_icon_saved", imagecache_get_propstr(e->rating_label->rl_icon, tbuf, sizeof(tbuf)));
         }
+
+        if(e->rating_label->rl_country){
+          htsmsg_add_str(conf, "rating_country_saved", e->rating_label->rl_country);
+        }
+
+        if(e->rating_label->rl_authority){
+          htsmsg_add_str(conf, "rating_authority_saved", e->rating_label->rl_authority);
+        }
+
       }
     }//END rating labels enabled.
 
@@ -3465,6 +3474,22 @@ dvr_entry_class_rating_set(void *o, const void *v)
         de->de_rating_icon_saved = strdup(rl->rl_icon);
     }
 
+    if(de->de_rating_authority_saved){
+        free(de->de_rating_authority_saved);
+    }
+
+    if(rl->rl_authority){
+        de->de_rating_authority_saved = strdup(rl->rl_authority);
+    }
+
+    if(de->de_rating_country_saved){
+        free(de->de_rating_country_saved);
+    }
+
+    if(rl->rl_country){
+        de->de_rating_country_saved = strdup(rl->rl_country);
+    }
+
     return 1;
   }//END we got an RL object.
 
@@ -4074,6 +4099,53 @@ dvr_entry_class_rating_label_get(void *o)
   return &prop_ptr;
 }
 
+static const void *
+dvr_entry_class_rating_authority_get(void *o)
+{
+  dvr_entry_t *de = (dvr_entry_t *)o;
+  ratinglabel_t *rl = de->de_rating_label;
+  if (rl == NULL) {
+    prop_ptr = "";
+    if(de->de_rating_authority_saved){
+        prop_ptr = de->de_rating_authority_saved;
+    }
+  } else {
+    if(de->de_sched_state == DVR_SCHEDULED){
+      prop_ptr = rl->rl_authority;
+    }
+    else
+    {
+      prop_ptr = de->de_rating_authority_saved;
+    }
+
+  }
+  return &prop_ptr;
+}
+
+static const void *
+dvr_entry_class_rating_country_get(void *o)
+{
+  dvr_entry_t *de = (dvr_entry_t *)o;
+  ratinglabel_t *rl = de->de_rating_label;
+  if (rl == NULL) {
+    prop_ptr = "";
+    if(de->de_rating_country_saved){
+        prop_ptr = de->de_rating_country_saved;
+    }
+  } else {
+    if(de->de_sched_state == DVR_SCHEDULED){
+      prop_ptr = rl->rl_country;
+    }
+    else
+    {
+      prop_ptr = de->de_rating_country_saved;
+    }
+
+  }
+  return &prop_ptr;
+}
+
+
 static const void *
 dvr_entry_class_duplicate_get(void *o)
 {
@@ -4791,6 +4863,22 @@ const idclass_t dvr_entry_class = {
       .off      = offsetof(dvr_entry_t, de_rating_icon_saved),
       .opts     = PO_RDONLY | PO_NOUI,
     },
+    {
+      .type     = PT_STR,
+      .id       = "rating_authority_saved",
+      .name     = N_("Saved Rating Authority"),
+      .desc     = N_("Saved parental rating authority for once recording is complete."),
+      .off      = offsetof(dvr_entry_t, de_rating_authority_saved),
+      .opts     = PO_RDONLY | PO_NOUI,
+    },
+    {
+      .type     = PT_STR,
+      .id       = "rating_country_saved",
+      .name     = N_("Saved Rating Country"),
+      .desc     = N_("Saved parental rating country for once recording is complete."),
+      .off      = offsetof(dvr_entry_t, de_rating_country_saved),
+      .opts     = PO_RDONLY | PO_NOUI,
+    },
     //This needs to go after the 'saved' properties because loading the RL object
     //can refresh the 'saved' objects for scheduled entries.
     {
@@ -4812,6 +4900,22 @@ const idclass_t dvr_entry_class = {
       .get      = dvr_entry_class_rating_icon_url_get,
       .opts     = PO_HIDDEN | PO_RDONLY | PO_NOSAVE | PO_NOUI,
     },
+    {
+      .type     = PT_STR,
+      .id       = "rating_authority",
+      .name     = N_("Rating Authority"),
+      .desc     = N_("Rating Authority."),
+      .get      = dvr_entry_class_rating_authority_get,
+      .opts     = PO_HIDDEN | PO_RDONLY | PO_NOSAVE | PO_NOUI,
+    },
+    {
+      .type     = PT_STR,
+      .id       = "rating_country",
+      .name     = N_("Rating Country"),
+      .desc     = N_("Rating Country."),
+      .get      = dvr_entry_class_rating_country_get,
+      .opts     = PO_HIDDEN | PO_RDONLY | PO_NOSAVE | PO_NOUI,
+    },
     {
       .type     = PT_STR,
       .id       = "rating_label",
index cb5fd646330f1817bd366f7a740d60bf79f8f1ab..3b0c423bf91104ef62bc313d4d0dc2a9f7a17edd 100644 (file)
@@ -51,7 +51,7 @@
 
 static void *htsp_server, *htsp_server_2;
 
-#define HTSP_PROTO_VERSION 40
+#define HTSP_PROTO_VERSION 41
 
 #define HTSP_ASYNC_OFF  0x00
 #define HTSP_ASYNC_ON   0x01
@@ -1049,8 +1049,22 @@ htsp_build_dvrentry(htsp_connection_t *htsp, dvr_entry_t *de, const char *method
                   htsmsg_add_str(out, "ratingIcon", str);
               }//END got an imagecache location
             }//END icon not null
-          }
-        }
+
+            //The authority and country are added for Kodi's parentalRatingSource field.
+            //Kodi looks for the authority first and if that is not present, then it uses the country.
+            //There could be no label, but there could be an age.  The authority &
+            //country could still be useful.
+            if (htsp->htsp_version > 40){
+                if(de->de_rating_label->rl_authority){
+                  htsmsg_add_str(out, "ratingAuthority", de->de_rating_label->rl_authority);
+                }//END authority saved not null
+
+                if(de->de_rating_label->rl_country){
+                  htsmsg_add_str(out, "ratingCountry", de->de_rating_label->rl_country);
+                }//END country saved not null
+            }//END ver > 40
+          }//END rating label not null
+        }//END this is a scheduled recording.
         else
         {
           if(de->de_rating_label_saved){
@@ -1065,8 +1079,19 @@ htsp_build_dvrentry(htsp_connection_t *htsp, dvr_entry_t *de, const char *method
                   htsmsg_add_str(out, "ratingIcon", str);
               }//END got an imagecache location
             }//END icon not null
+
+            if (htsp->htsp_version > 40){
+              if(de->de_rating_authority_saved){
+                htsmsg_add_str(out, "ratingAuthority", de->de_rating_authority_saved);
+              }//END authority saved not null
+
+              if(de->de_rating_country_saved){
+                htsmsg_add_str(out, "ratingCountry", de->de_rating_country_saved);
+              }//END country saved not null
+            }//END version > 40
+
           }
-        }
+        }//END this is not a scheduled recording.
       }//END processing rating labels is enabled
     }
 
@@ -1416,6 +1441,16 @@ htsp_build_event
                 htsmsg_add_str(out, "ratingIcon", str);
             }//END got an imagecache location
           }//END icon not null
+
+          if (htsp->htsp_version > 40){
+              if(e->rating_label->rl_authority){
+                htsmsg_add_str(out, "ratingAuthority", e->rating_label->rl_authority);
+              }//END authority saved not null
+
+              if(e->rating_label->rl_country){
+                htsmsg_add_str(out, "ratingCountry", e->rating_label->rl_country);
+              }//END country saved not null
+          }
         }//END rating label not null
     }//END parental labels enabled.
   }//END HTSP version check
index 1e7bf74351a85cdcfe55763b1f5eef338578e79c..5671a4dd5ccbf27d046254023228d182d2f0acb1 100644 (file)
@@ -533,6 +533,22 @@ ratinglabel_class_save(idnode_t *self, char *filename, size_t fsize)
                 de->de_rating_icon_saved = NULL;
             }
 
+            //If this RL has a country, save that, else, ensure that the recording's RL country is empty.
+            if(rl->rl_icon){
+                de->de_rating_country_saved = strdup(rl->rl_country);
+            }
+            else {
+                de->de_rating_country_saved = NULL;
+            }
+
+            //If this RL has an authority, save that, else, ensure that the recording's RL authority is empty.
+            if(rl->rl_icon){
+                de->de_rating_authority_saved = strdup(rl->rl_authority);
+            }
+            else {
+                de->de_rating_authority_saved = NULL;
+            }
+
             dvr_entry_changed(de);       //Save this recording and push it out to clients.
             foundCount++;
         }//END we matched the RL