Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: implement post-remove command (see PR#762)
  • Loading branch information
perexg committed Nov 24, 2015
1 parent b9882fe commit 0fda5ef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/dvr/dvr.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/dvr/dvr_config.c
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/dvr/dvr_db.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/dvr/dvr_rec.c
Expand Up @@ -1480,28 +1480,29 @@ dvr_thread(void *aux)
/**
*
*/
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));
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 0fda5ef

Please sign in to comment.