diff --git a/src/config2.c b/src/config2.c
index cfeeb12..ebd0472 100644
--- a/src/config2.c
+++ b/src/config2.c
@@ -87,3 +87,23 @@ int config_set_muxconfpath ( const char *path )
{
return _config_set_str("muxconfpath", path);
}
+
+const char *config_get_subscript_pre_command ( void )
+{
+ return htsmsg_get_str(config, "subpreproccommand");
+}
+
+int config_set_subscript_pre_command ( const char *str )
+{
+ return _config_set_str("subpreproccommand", str);
+}
+
+const char *config_get_subscript_post_command ( void )
+{
+ return htsmsg_get_str(config, "subpostproccommand");
+}
+
+int config_set_subscript_post_command ( const char *str )
+{
+ return _config_set_str("subpostproccommand", str);
+}
diff --git a/src/config2.h b/src/config2.h
index cd68e30..b0d7c93 100644
--- a/src/config2.h
+++ b/src/config2.h
@@ -36,4 +36,12 @@ const char *config_get_language ( void );
int config_set_language ( const char *str )
__attribute__((warn_unused_result));
+const char *config_get_subscript_pre_command ( void );
+int config_set_subscript_pre_command ( const char *str )
+ __attribute__((warn_unused_result));
+
+const char *config_get_subscript_post_command ( void );
+int config_set_subscript_post_command ( const char *str )
+ __attribute__((warn_unused_result));
+
#endif /* __TVH_CONFIG__H__ */
diff --git a/src/subscriptions.c b/src/subscriptions.c
index 548fa7e..e9cefe4 100644
--- a/src/subscriptions.c
+++ b/src/subscriptions.c
@@ -1,6 +1,6 @@
/*
* tvheadend, transport and subscription functions
- * Copyright (C) 2007 Andreas Öman
+ * Copyright (C) 2007 Andreas �man
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -41,6 +41,11 @@
#include "atomic.h"
#include "dvb/dvb.h"
+#include "config2.h"
+
+#include "htsstr.h"
+#include "spawn.h"
+
struct th_subscription_list subscriptions;
static gtimer_t subscription_reschedule_timer;
@@ -106,6 +111,9 @@ subscription_link_service(th_subscription_t *s, service_t *t)
streaming_target_deliver(s->ths_output, sm);
}
+ // process pre-command
+ do_pre_command(s);
+
pthread_mutex_unlock(&t->s_stream_mutex);
}
@@ -134,9 +142,31 @@ subscription_unlink_service(th_subscription_t *s, int reason)
pthread_mutex_unlock(&t->s_stream_mutex);
LIST_REMOVE(s, ths_service_link);
+
+ do_post_command(s);
+
s->ths_service = NULL;
}
+/*
+ * Process pre-command before linking subscription
+ */
+void do_pre_command(th_subscription_t *s) {
+ if (subscriptions_active() && config_get_subscript_pre_command()) {
+ char **args = htsstr_argsplit(config_get_subscript_pre_command());
+ spawnv(args[0], (void *) args);
+ }
+}
+
+/*
+ * Process post-command after unlinking subscription
+ */
+void do_post_command(th_subscription_t *s) {
+ if (!subscriptions_active() && config_get_subscript_post_command()) {
+ char **args = htsstr_argsplit(config_get_subscript_post_command());
+ spawnv(args[0], (void *) args);
+ }
+}
/**
*
diff --git a/src/subscriptions.h b/src/subscriptions.h
index 28b84af..432f547 100644
--- a/src/subscriptions.h
+++ b/src/subscriptions.h
@@ -1,6 +1,6 @@
/*
* tvheadend, subscription functions
- * Copyright (C) 2007 Andreas Öman
+ * Copyright (C) 2007 Andreas �man
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -125,6 +125,10 @@ void subscription_dummy_join(const char *id, int first);
int subscriptions_active(void);
+void do_pre_command(th_subscription_t *s);
+
+void do_post_command(th_subscription_t *s);
+
struct htsmsg;
struct htsmsg *subscription_create_msg(th_subscription_t *s);
diff --git a/src/webui/extjs.c b/src/webui/extjs.c
index 00d157e..646d449 100644
--- a/src/webui/extjs.c
+++ b/src/webui/extjs.c
@@ -2006,6 +2006,12 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)
save |= config_set_muxconfpath(str);
if ((str = http_arg_get(&hc->hc_req_args, "language")))
save |= config_set_language(str);
+ if ((str = http_arg_get(&hc->hc_req_args, "subpreproccommand")))
+ save |= config_set_subscript_pre_command(str);
+ if ((str = http_arg_get(&hc->hc_req_args, "subpostproccommand")))
+ save |= config_set_subscript_post_command(str);
+ if (save)
+
if (save)
config_save();
diff --git a/src/webui/static/app/config.js b/src/webui/static/app/config.js
index a7d84bb..acb7142 100644
--- a/src/webui/static/app/config.js
+++ b/src/webui/static/app/config.js
@@ -41,7 +41,10 @@ tvheadend.miscconf = function() {
'imagecache_enabled', 'imagecache_ok_period',
'imagecache_fail_period', 'imagecache_ignore_sslcert',
'tvhtime_update_enabled', 'tvhtime_ntp_enabled',
- 'tvhtime_tolerance']);
+ 'tvhtime_tolerance',
+ 'subpreproccommand',
+ 'subpostproccommand'
+ ]);
/* ****************************************************************
* Form Fields
@@ -134,10 +137,43 @@ tvheadend.miscconf = function() {
items : [ imagecacheEnabled, imagecacheOkPeriod, imagecacheFailPeriod,
imagecacheIgnoreSSLCert ]
});
+
if (tvheadend.capabilities.indexOf('imagecache') == -1)
imagecachePanel.hide();
+
+ var preProcCommand = new Ext.form.TextField({
+ name: 'subpreproccommand',
+ fieldLabel: 'Command to process before new subscription starts
(e.g. /home/user/preprocess.sh)',
+ width: 400
+ });
- /* ****************************************************************
+ var postProcCommand = new Ext.form.TextField({
+ name: 'subpostproccommand',
+ fieldLabel: 'Command to process after last subscription ends
(e.g. /home/user/postprocess.sh)',
+ width: 400
+ });
+
+ var subProcessPanel = new Ext.form.FieldSet({
+ title: 'Extra processing for subscriptions',
+ width: 700,
+ autoHeight: true,
+ collapsible: true,
+ animCollapse: true,
+ items: [preProcCommand, postProcCommand]
+ });
+
+ var subProcessPanel_form = new Ext.form.FormPanel({
+ border: false,
+ labelAlign: 'left',
+ labelWidth: 200,
+ waitMsgTarget: true,
+ layout: 'form',
+ defaultType: 'textfield',
+ autoHeight: true,
+ items: [subProcessPanel]
+ });
+
+ /* ****************************************************************
* Form
* ***************************************************************/
@@ -167,7 +203,7 @@ tvheadend.miscconf = function() {
layout : 'form',
defaultType : 'textfield',
autoHeight : true,
- items : [ language, dvbscanPath,
+ items : [ language, dvbscanPath, subProcessPanel,
imagecachePanel, tvhtimePanel ],
tbar : [ saveButton, '->', helpButton ]
});