* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <ctype.h>
#include <string.h>
#include <sys/stat.h>
}
}
+static int
+config_dvr_autorec_start_set(const char *s, int *tm)
+{
+ int t;
+
+ if(s == NULL || s[0] == '\0' || !isdigit(s[0]))
+ t = -1;
+ else if(strchr(s, ':') != NULL)
+ // formatted time string - convert
+ t = (atoi(s) * 60) + atoi(s + 3);
+ else {
+ t = atoi(s);
+ }
+ if (t >= 24 * 60)
+ t = -1;
+ if (t != *tm) {
+ *tm = t;
+ return 1;
+ }
+ return 0;
+}
+
+static void
+config_modify_dvrauto( htsmsg_t *c )
+{
+ int tm = -1;
+ char buf[16];
+
+ if (config_dvr_autorec_start_set(htsmsg_get_str(c, "start"), &tm) > 0 && tm >= 0) {
+ tm -= 15;
+ if (tm < 0)
+ tm += 24 * 60;
+ snprintf(buf, sizeof(buf), "%02d:%02d", tm / 60, tm % 60);
+ htsmsg_set_str(c, "start", tm <= 0 ? "Any" : buf);
+ htsmsg_set_u32(c, "start_window", 30);
+ } else {
+ htsmsg_delete_field(c, "start");
+ }
+}
+
+static void
+config_migrate_v16 ( void )
+{
+ htsmsg_t *c, *e;
+ htsmsg_field_t *f;
+
+ if ((c = hts_settings_load("dvr/autorec")) != NULL) {
+ HTSMSG_FOREACH(f, c) {
+ if (!(e = htsmsg_field_get_map(f))) continue;
+ config_modify_dvrauto(e);
+ hts_settings_save(e, "dvr/autorec/%s", f->hmf_name);
+ }
+ htsmsg_destroy(c);
+ }
+}
+
/*
* Perform backup
*/
config_migrate_v12,
config_migrate_v13,
config_migrate_v14,
- config_migrate_v15
+ config_migrate_v15,
+ config_migrate_v16
};
/*
uint32_t dae_content_type;
- int dae_start; /* Minutes from midnight */
+ int dae_start; /* Minutes from midnight */
+ int dae_start_window; /* Minutes (duration) */
uint32_t dae_weekdays;
dvr_autorec_entry_t *
dvr_autorec_create_htsp(const char *dvr_config_name, const char *title,
- channel_t *ch, uint32_t aroundTime, uint32_t days,
- time_t start_extra, time_t stop_extra,
+ channel_t *ch, uint32_t start, uint32_t start_window,
+ uint32_t days, time_t start_extra, time_t stop_extra,
dvr_prio_t pri, int retention,
int min_duration, int max_duration,
const char *creator, const char *comment);
return 0;
}
- if(dae->dae_start >= 0) {
- struct tm a_time;
- struct tm ev_time;
+ if(dae->dae_start >= 0 && dae->dae_start_window >= 0) {
+ struct tm a_time, ev_time;
+ time_t ta, te;
localtime_r(&e->start, &a_time);
- localtime_r(&e->start, &ev_time);
+ ev_time = a_time;
a_time.tm_min = dae->dae_start % 60;
a_time.tm_hour = dae->dae_start / 60;
- if(abs(mktime(&a_time) - mktime(&ev_time)) > 900)
+ ta = mktime(&a_time);
+ te = mktime(&ev_time);
+ if(ta > te || te > ta + dae->dae_start_window * 60)
return 0;
}
dvr_autorec_entry_t*
dvr_autorec_create_htsp(const char *dvr_config_name, const char *title,
- channel_t *ch, uint32_t aroundTime, uint32_t weekdays,
- time_t start_extra, time_t stop_extra,
+ channel_t *ch, uint32_t start, uint32_t start_window,
+ uint32_t weekdays, time_t start_extra, time_t stop_extra,
dvr_prio_t pri, int retention,
int min_duration, int max_duration,
const char *creator, const char *comment)
htsmsg_add_str(conf, "creator", creator ?: "");
htsmsg_add_str(conf, "comment", comment ?: "");
- if (aroundTime)
- htsmsg_add_u32(conf, "start", (aroundTime-1));
+ if (start >= 0)
+ htsmsg_add_u32(conf, "start", start);
+ if (start_window >= 0)
+ htsmsg_add_u32(conf, "start_window", start_window);
if (ch)
htsmsg_add_str(conf, "channel", idnode_uuid_as_str(&ch->ch_id));
return dvr_autorec_entry_class_time_list(o, "Any");
}
+static htsmsg_t *
+dvr_autorec_entry_class_time_window_list(void *o)
+{
+ return dvr_entry_class_duration_list(o, "Exact", 24*60, 60);
+}
+
static htsmsg_t *
dvr_autorec_entry_class_extra_list(void *o)
{
{
.type = PT_STR,
.id = "start",
- .name = "Starting Around",
+ .name = "Start Time",
.set = dvr_autorec_entry_class_start_set,
.get = dvr_autorec_entry_class_start_get,
.list = dvr_autorec_entry_class_time_list_,
.opts = PO_SORTKEY
},
+ {
+ .type = PT_INT,
+ .id = "start_window",
+ .name = "Start Window",
+ .list = dvr_autorec_entry_class_time_window_list,
+ .off = offsetof(dvr_autorec_entry_t, dae_start_window),
+ },
{
.type = PT_TIME,
.id = "start_extra",
htsmsg_add_u32(out, "minDuration", dae->dae_minduration);
htsmsg_add_u32(out, "retention", dae->dae_retention);
htsmsg_add_u32(out, "daysOfWeek", dae->dae_weekdays);
- htsmsg_add_u32(out, "approxTime", dae->dae_start);
+ htsmsg_add_u32(out, "approxTime",
+ dae->dae_start_window == 30 && dae->dae_start >= 0 ?
+ dae->dae_start + 15 : -1);
+ htsmsg_add_u32(out, "start", dae->dae_start);
+ htsmsg_add_u32(out, "startWindow", dae->dae_start_window);
htsmsg_add_u32(out, "priority", dae->dae_pri);
htsmsg_add_s64(out, "startExtra", dae->dae_start_extra);
htsmsg_add_s64(out, "stopExtra", dae->dae_stop_extra);
dvr_autorec_entry_t *dae;
const char *dvr_config_name, *title, *creator, *comment;
int64_t start_extra, stop_extra;
- uint32_t u32, days_of_week, priority, approx_time,
- min_duration, max_duration, retention;
+ uint32_t u32, days_of_week, priority, approx_time, start, start_window,
+ min_duration, max_duration, retention;
channel_t *ch = NULL;
/* Options */
if(htsmsg_get_u32(in, "priority", &priority))
priority = DVR_PRIO_NORMAL;
if(htsmsg_get_u32(in, "approxTime", &approx_time))
- approx_time = 0;
- else
- approx_time++;
+ approx_time = -1;
+ if(htsmsg_get_u32(in, "start", &start))
+ start = -1;
+ if(htsmsg_get_u32(in, "startWindow", &start_window))
+ start_window = -1;
+ if (start < 0 || start_window < 0)
+ start = start_window = -1;
+ if (start < 0 && approx_time >= 0) {
+ start = approx_time - 15;
+ if (start < 0)
+ start += 24 * 60;
+ start_window = 60;
+ }
if(htsmsg_get_s64(in, "startExtra", &start_extra))
start_extra = 0; // 0 = dvr config
if(htsmsg_get_s64(in, "stopExtra", &stop_extra))
if (ch && !htsp_user_access_channel(htsp, ch))
return htsp_error("User does not have access");
- dae = dvr_autorec_create_htsp(dvr_config_name, title, ch, approx_time, days_of_week,
+ dae = dvr_autorec_create_htsp(dvr_config_name, title, ch, start, start_window, days_of_week,
start_extra, stop_extra, priority, retention, min_duration, max_duration, creator, comment);
/* create response */
maxduration: { width: 80 },
weekdays: { width: 160 },
start: { width: 100 },
+ start_window: { width: 100 },
pri: { width: 80 },
config_name: { width: 120 },
creator: { width: 200 },
url: 'api/dvr/autorec',
params: {
list: 'enabled,name,title,channel,tag,content_type,minduration,' +
- 'maxduration,weekdays,start,pri,config_name,comment'
+ 'maxduration,weekdays,start,start_window,pri,config_name,comment'
},
create: { }
},
del: true,
list: 'enabled,name,title,channel,tag,content_type,minduration,' +
- 'maxduration,weekdays,start,pri,config_name,creator,comment',
+ 'maxduration,weekdays,start,start_window,pri,config_name,creator,comment',
columns: {
weekdays: {
renderer: function(st) { return tvheadend.weekdaysRenderer(st); }