Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR autorec: change start_window meaning to start up to
  • Loading branch information
perexg committed Dec 25, 2014
1 parent 56d8c8f commit e2bd233
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
14 changes: 6 additions & 8 deletions docs/html/dvr_autorec.html
Expand Up @@ -79,15 +79,13 @@
<dd>
On which specific days of the week to find matching programmes.
<p>
<dt><b>Starting Around</b>
<dt><b>Start Time</b>
<dd>
An approximate starting time for matching programmes.
<br>
<br>
I'd need to check the code to see how this works to expand on this any further. It used to be:
<br>
<br>
Only record events if they are scheduled +-15 minutes from this given time.
An event which starts between this "start time" and "start time up to" will be matched (including).
<p>
<dt><b>Start Up To</b>
<dd>
The start up to limit.
<p>
<dt><b>Priority</b>
<dd>
Expand Down
10 changes: 7 additions & 3 deletions src/config.c
Expand Up @@ -1128,16 +1128,20 @@ config_dvr_autorec_start_set(const char *s, int *tm)
static void
config_modify_dvrauto( htsmsg_t *c )
{
int tm = -1;
int tm = -1, tw = -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;
tw = tm + 30;
if (tw >= 24 * 60)
tw -= 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);
htsmsg_set_str(c, "start", buf);
snprintf(buf, sizeof(buf), "%02d:%02d", tw / 60, tw % 60);
htsmsg_set_str(c, "start_window", buf);
} else {
htsmsg_delete_field(c, "start");
}
Expand Down
50 changes: 36 additions & 14 deletions src/dvr/dvr_autorec.c
Expand Up @@ -126,17 +126,29 @@ autorec_cmp(dvr_autorec_entry_t *dae, epg_broadcast_t *e)
return 0;
}

if(dae->dae_start >= 0 && dae->dae_start_window >= 0) {
if(dae->dae_start >= 0 && dae->dae_start_window >= 0 &&
dae->dae_start < 24*60 && dae->dae_start_window < 24*60) {
struct tm a_time, ev_time;
time_t ta, te;
time_t ta, te, tad;
localtime_r(&e->start, &a_time);
ev_time = a_time;
a_time.tm_min = dae->dae_start % 60;
a_time.tm_hour = dae->dae_start / 60;
ta = mktime(&a_time);
te = mktime(&ev_time);
if(ta > te || te > ta + dae->dae_start_window * 60)
return 0;
if(dae->dae_start > dae->dae_start_window) {
ta -= 24 * 3600; /* 24 hours */
tad = ((24 * 60) - dae->dae_start + dae->dae_start_window) * 60;
if(ta > te || te > ta + tad) {
ta += 24 * 3600;
if(ta > te || te > ta + tad)
return 0;
}
} else {
tad = (dae->dae_start_window - dae->dae_start) * 60;
if(ta > te || te > ta + tad)
return 0;
}
}

duration = difftime(e->stop,e->start);
Expand Down Expand Up @@ -499,6 +511,13 @@ dvr_autorec_entry_class_start_set(void *o, const void *v)
return dvr_autorec_entry_class_time_set(o, v, &dae->dae_start);
}

static int
dvr_autorec_entry_class_start_window_set(void *o, const void *v)
{
dvr_autorec_entry_t *dae = (dvr_autorec_entry_t *)o;
return dvr_autorec_entry_class_time_set(o, v, &dae->dae_start_window);
}

static const void *
dvr_autorec_entry_class_time_get(void *o, int tm)
{
Expand All @@ -519,6 +538,13 @@ dvr_autorec_entry_class_start_get(void *o)
return dvr_autorec_entry_class_time_get(o, dae->dae_start);
}

static const void *
dvr_autorec_entry_class_start_window_get(void *o)
{
dvr_autorec_entry_t *dae = (dvr_autorec_entry_t *)o;
return dvr_autorec_entry_class_time_get(o, dae->dae_start_window);
}

htsmsg_t *
dvr_autorec_entry_class_time_list(void *o, const char *null)
{
Expand All @@ -539,12 +565,6 @@ dvr_autorec_entry_class_time_list_(void *o)
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, 1);
}

static htsmsg_t *
dvr_autorec_entry_class_extra_list(void *o)
{
Expand Down Expand Up @@ -863,11 +883,13 @@ const idclass_t dvr_autorec_entry_class = {
.opts = PO_SORTKEY
},
{
.type = PT_INT,
.type = PT_STR,
.id = "start_window",
.name = "Start Window",
.list = dvr_autorec_entry_class_time_window_list,
.off = offsetof(dvr_autorec_entry_t, dae_start_window),
.name = "Start Up To",
.set = dvr_autorec_entry_class_start_window_set,
.get = dvr_autorec_entry_class_start_window_get,
.list = dvr_autorec_entry_class_time_list_,
.opts = PO_SORTKEY,
},
{
.type = PT_TIME,
Expand Down
17 changes: 14 additions & 3 deletions src/htsp_server.c
Expand Up @@ -732,16 +732,25 @@ static htsmsg_t *
htsp_build_autorecentry(dvr_autorec_entry_t *dae, const char *method)
{
htsmsg_t *out = htsmsg_create_map();
int tad;

htsmsg_add_str(out, "id", idnode_uuid_as_str(&dae->dae_id));
htsmsg_add_u32(out, "enabled", dae->dae_enabled);
htsmsg_add_u32(out, "maxDuration", dae->dae_maxduration);
htsmsg_add_u32(out, "minDuration", dae->dae_minduration);
htsmsg_add_u32(out, "retention", dae->dae_retention);
htsmsg_add_u32(out, "daysOfWeek", dae->dae_weekdays);
if (dae->dae_start >= 0 && dae->dae_start_window >= 0) {
if (dae->dae_start > dae->dae_start_window)
tad = 24 * 60 - dae->dae_start + dae->dae_start_window;
else
tad = dae->dae_start_window - dae->dae_start;
} else {
tad = -1;
}
htsmsg_add_s32(out, "approxTime",
dae->dae_start_window == 30 && dae->dae_start >= 0 ?
dae->dae_start + 15 : -1);
dae->dae_start >= 0 && tad >= 0 ?
((dae->dae_start + tad / 2) % (24 * 60)) : -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);
Expand Down Expand Up @@ -1563,7 +1572,9 @@ htsp_method_addAutorecEntry(htsp_connection_t *htsp, htsmsg_t *in)
start = approx_time - 15;
if (start < 0)
start += 24 * 60;
start_window = 60;
start_window = start + 30;
if (start_window >= 24 * 60)
start_window -= 24 * 60;
}
if(htsmsg_get_s64(in, "startExtra", &start_extra))
start_extra = 0; // 0 = dvr config
Expand Down

6 comments on commit e2bd233

@ksooo
Copy link
Contributor

@ksooo ksooo commented on e2bd233 Dec 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems completely broken to me. I live in GMT+1 and now have to specify start time in GMT. Start up To seems to do just weird things, but not to select the events it should. Sorry, could not find any "rule" to describe the actual misbehavior. :-(

@perexg
Copy link
Contributor Author

@perexg perexg commented on e2bd233 Dec 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start Up To is not the duration but "end of the time window" now... So if you like to autorec things between 10:00 and 10:30, enter 10:00 as start time and 10:30 as start up to..

@ksooo
Copy link
Contributor

@ksooo ksooo commented on e2bd233 Dec 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course. :-O Thanks for clarifying. It works.

@ProfYaffle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is it better labelled as "Earliest Start" and "Latest Start", "Start after... but before", "Start no earlier than... no later than" or something along those lines?

@perexg
Copy link
Contributor Author

@perexg perexg commented on e2bd233 Dec 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ProfYaffle : I agree. Renamed to "Start After" and "Start Before" to make column headers more descriptive. Thanks. Commit: 75fb7a9

@Glenn-1990
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a real improvement for me :-)

Please sign in to comment.