]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
DVR: implement post-remove command (see PR#762)
authorJaroslav Kysela <perex@perex.cz>
Tue, 24 Nov 2015 11:25:01 +0000 (12:25 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 24 Nov 2015 11:26:54 +0000 (12:26 +0100)
src/dvr/dvr.h
src/dvr/dvr_config.c
src/dvr/dvr_db.c
src/dvr/dvr_rec.c

index 567a71dc7fe016cd6f04d2667cbcc0470eea8bfa..ae3f47e092e84012e872858b204253e7aac37957 100644 (file)
@@ -48,6 +48,7 @@ typedef struct dvr_config {
   char *dvr_charset;
   char *dvr_charset_id;
   char *dvr_postproc;
+  char *dvr_postremove;
   uint32_t dvr_extra_time_pre;
   uint32_t dvr_extra_time_post;
   uint32_t dvr_update_window;
@@ -549,6 +550,8 @@ htsmsg_t *dvr_entry_class_duration_list(void *o, const char *not_set, int max, i
 
 int dvr_entry_verify(dvr_entry_t *de, access_t *a, int readonly);
 
+void dvr_spawn_postcmd(dvr_entry_t *de, const char *postcmd, const char *filename);
+
 void dvr_disk_space_init(void);
 void dvr_disk_space_done(void);
 int dvr_get_disk_space(int64_t *bfree, int64_t *btotal);
index c18c8d274ff5f83e93331ee5fc0364101b7cc7de..7860c087da3533d4a1760dbb3e03fa30a1930cc3 100644 (file)
@@ -891,6 +891,13 @@ const idclass_t dvr_config_class = {
       .off      = offsetof(dvr_config_t, dvr_postproc),
       .group    = 1,
     },
+    {
+      .type     = PT_STR,
+      .id       = "postremove",
+      .name     = N_("Post-remove command"),
+      .off      = offsetof(dvr_config_t, dvr_postremove),
+      .group    = 1,
+    },
     {
       .type     = PT_STR,
       .id       = "storage",
index 0573398d80dc69bcca1a4e9d353039d80b903a7a..ec2366a7e92b2f954d3e02e2b4d12ff341db8ed6 100644 (file)
@@ -3040,7 +3040,7 @@ dvr_entry_delete(dvr_entry_t *de, int no_missed_time_resched)
   time_t t;
   struct tm tm;
   const char *filename;
-  char tbuf[64], *rdir;
+  char tbuf[64], *rdir, *postcmd;
   int r;
 
   t = dvr_entry_get_start_time(de);
@@ -3073,6 +3073,10 @@ dvr_entry_delete(dvr_entry_t *de, int no_missed_time_resched)
       if(r && r != -ENOENT)
         tvhlog(LOG_WARNING, "dvr", "Unable to remove file '%s' from disk -- %s",
               filename, strerror(-errno));
+
+      postcmd = de->de_config->dvr_postremove;
+      if (postcmd && postcmd[0])
+        dvr_spawn_postcmd(de, postcmd, filename);
       htsmsg_delete_field(m, "filename");
     }
   }
index 3ba5278aa365540469e0f85255a01fe9d3656b63..4011a4f1ea7f1e63337356e5670f0bf935a54e04 100644 (file)
@@ -1480,28 +1480,29 @@ fin:
 /**
  *
  */
-static void
-dvr_spawn_postproc(dvr_entry_t *de, const char *dvr_postproc)
+void
+dvr_spawn_postcmd(dvr_entry_t *de, const char *postcmd, const char *filename)
 {
   char buf1[2048], *buf2;
   char tmp[MAX(PATH_MAX, 512)];
-  const char *filename;
   htsmsg_t *info, *e;
   htsmsg_field_t *f;
   char **args;
 
   if ((f = htsmsg_field_last(de->de_files)) != NULL &&
       (e = htsmsg_field_get_map(f)) != NULL) {
-    filename = htsmsg_get_str(e, "filename");
-    if (filename == NULL)
-      return;
+    if (filename == NULL) {
+      filename = htsmsg_get_str(e, "filename");
+      if (filename == NULL)
+        return;
+    }
     info = htsmsg_get_list(e, "info");
   } else {
     return;
   }
 
   /* Substitute DVR entry formatters */
-  htsstr_substitute(dvr_postproc, buf1, sizeof(buf1), '%', dvr_subs_postproc_entry, de, tmp, sizeof(tmp));
+  htsstr_substitute(postcmd, buf1, sizeof(buf1), '%', dvr_subs_postproc_entry, de, tmp, sizeof(tmp));
   buf2 = tvh_strdupa(buf1);
   /* Substitute filename formatters */
   htsstr_substitute(buf2, buf1, sizeof(buf1), '%', dvr_subs_postproc_filename, filename, tmp, sizeof(tmp));
@@ -1531,8 +1532,8 @@ dvr_thread_epilog(dvr_entry_t *de, const char *dvr_postproc)
   muxer_destroy(prch->prch_muxer);
   prch->prch_muxer = NULL;
 
-  if(dvr_postproc)
-    dvr_spawn_postproc(de, dvr_postproc);
+  if(dvr_postproc && dvr_postproc[0])
+    dvr_spawn_postcmd(de, dvr_postproc, NULL);
 }
 
 /**