Add weekday support to autorecordings

This commit is contained in:
Andreas Öman 2010-02-04 22:50:16 +00:00
parent 9e4464acf5
commit 6e24cea010
3 changed files with 91 additions and 3 deletions

4
debian/changelog vendored
View file

@ -1,3 +1,7 @@
hts-tvheadend (2.11-WIP) hts; urgency=low
* Add support for filtering autorecordings based on weekdays.
hts-tvheadend (2.10) hts; urgency=high
* Fix a crash in HTSP server.

View file

@ -54,6 +54,8 @@ typedef struct dvr_autorec_entry {
epg_content_group_t *dae_ecg;
int dae_weekdays;
channel_t *dae_channel;
LIST_ENTRY(dvr_autorec_entry) dae_channel_link;
@ -67,14 +69,14 @@ static void dvr_autorec_check_just_enabled(dvr_autorec_entry_t *dae);
/**
* return 1 if the event 'e' is matched by the autorec rule 'ar'
* return 1 if the event 'e' is matched by the autorec rule 'dae'
*/
static int
autorec_cmp(dvr_autorec_entry_t *dae, event_t *e)
{
channel_tag_mapping_t *ctm;
if(dae->dae_enabled == 0)
if(dae->dae_enabled == 0 || dae->dae_weekdays == 0)
return 0;
if(dae->dae_channel != NULL &&
@ -100,6 +102,12 @@ autorec_cmp(dvr_autorec_entry_t *dae, event_t *e)
regexec(&dae->dae_title_preg, e->e_title, 0, NULL, 0))
return 0;
if(dae->dae_weekdays != 0x7f) {
struct tm tm;
localtime_r(&e->e_start, &tm);
if(!((1 << ((tm.tm_wday ?: 7) - 1)) & dae->dae_weekdays))
return 0;
}
return 1;
}
@ -131,6 +139,7 @@ autorec_entry_find(const char *id, int create)
} else {
tally = MAX(atoi(id), tally);
}
dae->dae_weekdays = 0x7f;
dae->dae_id = strdup(id);
TAILQ_INSERT_TAIL(&autorec_entries, dae, dae_link);
@ -165,6 +174,36 @@ autorec_entry_destroy(dvr_autorec_entry_t *dae)
free(dae);
}
/**
*
*/
static void
build_weekday_tags(char *buf, size_t buflen, int mask)
{
int i, p = 0;
for(i = 0; i < 7; i++) {
if(mask & (1 << i) && p < buflen - 3) {
if(p != 0)
buf[p++] = ',';
buf[p++] = '1' + i;
}
}
buf[p] = 0;
}
/**
*
*/
static int
build_weekday_mask(const char *str)
{
int r = 0;
for(; *str; str++)
if(*str >= '1' && *str <= '7')
r |= 1 << (*str - '1');
return r;
}
/**
*
@ -172,6 +211,7 @@ autorec_entry_destroy(dvr_autorec_entry_t *dae)
static htsmsg_t *
autorec_record_build(dvr_autorec_entry_t *dae)
{
char str[30];
htsmsg_t *e = htsmsg_create_map();
htsmsg_add_str(e, "id", dae->dae_id);
@ -192,6 +232,9 @@ autorec_record_build(dvr_autorec_entry_t *dae)
htsmsg_add_str(e, "title", dae->dae_title ?: "");
build_weekday_tags(str, sizeof(str), dae->dae_weekdays);
htsmsg_add_str(e, "weekdays", str);
return e;
}
@ -291,6 +334,9 @@ autorec_record_update(void *opaque, const char *id, htsmsg_t *values,
if((s = htsmsg_get_str(values, "contentgrp")) != NULL)
dae->dae_ecg = epg_content_group_find_by_name(s);
if((s = htsmsg_get_str(values, "weekdays")) != NULL)
dae->dae_weekdays = build_weekday_mask(s);
if(!htsmsg_get_u32(values, "enabled", &u32))
dae->dae_enabled = u32;

View file

@ -1,4 +1,17 @@
tvheadend.weekdays = new Ext.data.SimpleStore({
fields: ['identifier', 'name'],
id: 0,
data: [
['1', 'Mon'],
['2', 'Tue'],
['3', 'Wed'],
['4', 'Thu'],
['5', 'Fri'],
['6', 'Sat'],
['7', 'Sun']
]
});
/**
*
@ -320,7 +333,31 @@ tvheadend.autoreceditor = function() {
triggerAction: 'all',
emptyText: 'Only include content...'
})
}, {
header: "Weekdays",
dataIndex: 'weekdays',
renderer: function(value, metadata, record, row, col, store) {
if (typeof value === 'undefined' || value.length < 1)
return 'No days';
if (value == '1,2,3,4,5,6,7')
return 'All days';
ret = [];
tags = value.split(',');
for (var i = 0; i < tags.length; i++) {
var tag = tvheadend.weekdays.getById(tags[i]);
if (typeof tag !== 'undefined')
ret.push(tag.data.name);
}
return ret.join(', ');
},
editor: new Ext.ux.form.LovCombo({
store: tvheadend.weekdays,
mode:'local',
valueField: 'identifier',
displayField: 'name'
})
},{
header: "Created by",
dataIndex: 'creator',
@ -375,7 +412,8 @@ tvheadend.dvr = function() {
tvheadend.autorecRecord = Ext.data.Record.create([
'enabled','title','channel','tag','creator','contentgrp','comment'
'enabled','title','channel','tag','creator','contentgrp','comment',
'weekdays'
]);