return de;
}
+/**
+ * Used to notify the DVR that an event has been removed from the EPG
+ */
+void
+dvr_event_cancelled(event_t *e)
+{
+ dvr_entry_t *de;
+
+ de = dvr_entry_find_by_event(e);
+ if (de != NULL) {
+ if (de->de_sched_state == DVR_SCHEDULED)
+ dvr_entry_cancel(de);
+ }
+
+
+}
+
/**
*
*/
}
/**
- * Find event with same title starting and ending around same time
- * on same channel
+ * Find dvr entry using 'fuzzy' search
*/
dvr_entry_t *
dvr_entry_find_by_event_fuzzy(event_t *e)
dvr_entry_t *de;
LIST_FOREACH(de, &e->e_channel->ch_dvrs, de_channel_link)
- if(strcmp(de->de_title, e->e_title) == 0) {
- if ((abs(de->de_start - e->e_start) < 600) && (abs(de->de_stop - e->e_stop) < 600))
- return de;
- }
+ if (abs(de->de_start - e->e_start) < 600 && abs(de->de_stop - e->e_stop) < 600)
+ return de;
return NULL;
}
static void epg_expire_event_from_channel(void *opauqe);
static void epg_ch_check_current_event(void *aux);
+/* helper function to fuzzy compare two events */
+static int epg_event_cmp_overlap(event_t *e1, event_t *e2);
+static void epg_erase_duplicates(event_t *e, channel_t *ch);
static int
int *created)
{
static event_t *skel;
- event_t *e, *p, *n;
+ event_t *e;
static int tally;
if(created != NULL)
}
}
+ epg_erase_duplicates(e, ch);
+ return e;
+}
+
+static void
+epg_erase_duplicates(event_t *e, channel_t *ch) {
+
+ event_t *p, *n;
+ int dvb_id = e->e_dvb_id;
if(dvb_id != -1) {
- /* Erase any close events with the same DVB event id */
+ /* Erase any close events with the same DVB event id or are very similar*/
if((p = RB_PREV(e, e_channel_link)) != NULL) {
- if(p->e_dvb_id == dvb_id) {
+ if(p->e_dvb_id == dvb_id || epg_event_cmp_overlap(p, e)) {
+ tvhlog(LOG_DEBUG, "epg",
+ "Removing overlapping event instance %s from EPG", p->e_title);
+ dvr_event_cancelled(p);
epg_remove_event_from_channel(ch, p);
} else if((p = RB_PREV(p, e_channel_link)) != NULL) {
- if(p->e_dvb_id == dvb_id)
+ if(p->e_dvb_id == dvb_id || epg_event_cmp_overlap(p, e)) {
+ tvhlog(LOG_DEBUG, "epg",
+ "Removing overlapping event instance %s from EPG", p->e_title);
+ dvr_event_cancelled(p);
epg_remove_event_from_channel(ch, p);
+ }
}
}
if((n = RB_NEXT(e, e_channel_link)) != NULL) {
- if(n->e_dvb_id == dvb_id) {
+ if(n->e_dvb_id == dvb_id || epg_event_cmp_overlap(n, e)) {
+ tvhlog(LOG_DEBUG, "epg",
+ "Removing overlapping event instance %s from EPG", n->e_title);
+ dvr_event_cancelled(n);
epg_remove_event_from_channel(ch, n);
} else if((n = RB_NEXT(n, e_channel_link)) != NULL) {
- if(n->e_dvb_id == dvb_id)
+ if(n->e_dvb_id == dvb_id || epg_event_cmp_overlap(n, e)) {
+ tvhlog(LOG_DEBUG, "epg",
+ "Removing overlapping event instance %s from EPG", n->e_title);
+ dvr_event_cancelled(n);
epg_remove_event_from_channel(ch, n);
+ }
}
}
}
- return e;
+
}
+static int
+epg_event_cmp_overlap(event_t *e1, event_t *e2)
+{
+ if ((e1->e_title == NULL) || (e2->e_title == NULL))
+ return 0;
+
+ if ((e1->e_stop < e2->e_start) || (e2->e_stop < e1->e_start)) {
+ return 0;
+ } else {
+ if ((e1->e_start < e2->e_stop) && (e2->e_start < e1->e_stop)) {
+ if ((e1->e_stop - e2->e_start) > 60 || (e2->e_stop - e1->e_start) > 60)
+ return 1;
+ }
+ }
+
+ return 0;
+}
/**
*