2003-12-22 13:29:24 +01:00
|
|
|
/*
|
|
|
|
* epg.c: Electronic Program Guide
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
|
|
|
* Original version (as used in VDR before 1.3.0) written by
|
|
|
|
* Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>.
|
|
|
|
*
|
2012-09-29 14:30:48 +02:00
|
|
|
* $Id: epg.c 2.21 2012/09/29 14:29:49 kls Exp $
|
2003-12-22 13:29:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "epg.h"
|
|
|
|
#include <ctype.h>
|
2008-02-16 16:12:21 +01:00
|
|
|
#include <limits.h>
|
2003-12-22 13:29:24 +01:00
|
|
|
#include <time.h>
|
2006-03-26 14:12:08 +02:00
|
|
|
#include "libsi/si.h"
|
|
|
|
#include "timers.h"
|
2003-12-22 13:29:24 +01:00
|
|
|
|
2006-01-29 14:04:37 +01:00
|
|
|
#define RUNNINGSTATUSTIMEOUT 30 // seconds before the running status is considered unknown
|
2012-09-24 13:41:54 +02:00
|
|
|
#define EPGDATAWRITEDELTA 600 // seconds between writing the epg.data file
|
2006-01-29 14:04:37 +01:00
|
|
|
|
2005-01-02 15:11:44 +01:00
|
|
|
// --- tComponent ------------------------------------------------------------
|
|
|
|
|
|
|
|
cString tComponent::ToString(void)
|
|
|
|
{
|
|
|
|
char buffer[256];
|
2006-02-18 15:59:43 +01:00
|
|
|
snprintf(buffer, sizeof(buffer), "%X %02X %s %s", stream, type, language, description ? description : "");
|
2005-01-02 15:11:44 +01:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tComponent::FromString(const char *s)
|
|
|
|
{
|
|
|
|
unsigned int Stream, Type;
|
2006-02-18 15:59:43 +01:00
|
|
|
int n = sscanf(s, "%X %02X %7s %a[^\n]", &Stream, &Type, language, &description); // 7 = MAXLANGCODE2 - 1
|
2005-05-05 12:41:21 +02:00
|
|
|
if (n != 4 || isempty(description)) {
|
2005-01-02 15:11:44 +01:00
|
|
|
free(description);
|
|
|
|
description = NULL;
|
|
|
|
}
|
|
|
|
stream = Stream;
|
|
|
|
type = Type;
|
|
|
|
return n >= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cComponents -----------------------------------------------------------
|
|
|
|
|
2005-05-16 14:45:11 +02:00
|
|
|
cComponents::cComponents(void)
|
2005-01-02 15:11:44 +01:00
|
|
|
{
|
2005-05-16 14:45:11 +02:00
|
|
|
numComponents = 0;
|
|
|
|
components = NULL;
|
2005-01-02 15:11:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cComponents::~cComponents(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < numComponents; i++)
|
|
|
|
free(components[i].description);
|
|
|
|
free(components);
|
|
|
|
}
|
|
|
|
|
2011-02-25 15:25:42 +01:00
|
|
|
bool cComponents::Realloc(int Index)
|
2005-01-02 15:11:44 +01:00
|
|
|
{
|
2005-05-16 14:45:11 +02:00
|
|
|
if (Index >= numComponents) {
|
2011-02-25 15:25:42 +01:00
|
|
|
Index++;
|
|
|
|
if (tComponent *NewBuffer = (tComponent *)realloc(components, Index * sizeof(tComponent))) {
|
|
|
|
int n = numComponents;
|
|
|
|
numComponents = Index;
|
|
|
|
components = NewBuffer;
|
|
|
|
memset(&components[n], 0, sizeof(tComponent) * (numComponents - n));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
esyslog("ERROR: out of memory");
|
|
|
|
return false;
|
|
|
|
}
|
2005-05-16 14:45:11 +02:00
|
|
|
}
|
2011-02-25 15:25:42 +01:00
|
|
|
return true;
|
2005-01-02 15:11:44 +01:00
|
|
|
}
|
|
|
|
|
2005-05-16 14:45:11 +02:00
|
|
|
void cComponents::SetComponent(int Index, const char *s)
|
2005-01-02 15:11:44 +01:00
|
|
|
{
|
2011-02-25 15:25:42 +01:00
|
|
|
if (Realloc(Index))
|
|
|
|
components[Index].FromString(s);
|
2005-05-16 14:45:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cComponents::SetComponent(int Index, uchar Stream, uchar Type, const char *Language, const char *Description)
|
|
|
|
{
|
2011-02-25 15:25:42 +01:00
|
|
|
if (!Realloc(Index))
|
|
|
|
return;
|
2005-05-16 14:45:11 +02:00
|
|
|
tComponent *p = &components[Index];
|
|
|
|
p->stream = Stream;
|
|
|
|
p->type = Type;
|
|
|
|
strn0cpy(p->language, Language, sizeof(p->language));
|
2006-02-19 11:15:44 +01:00
|
|
|
char *q = strchr(p->language, ',');
|
|
|
|
if (q)
|
|
|
|
*q = 0; // strips rest of "normalized" language codes
|
2005-05-16 14:45:11 +02:00
|
|
|
p->description = strcpyrealloc(p->description, !isempty(Description) ? Description : NULL);
|
2005-01-02 15:11:44 +01:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:27:51 +01:00
|
|
|
tComponent *cComponents::GetComponent(int Index, uchar Stream, uchar Type)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < numComponents; i++) {
|
2008-05-01 15:41:04 +02:00
|
|
|
if (components[i].stream == Stream && (
|
|
|
|
Type == 0 || // don't care about the actual Type
|
|
|
|
Stream == 2 && (components[i].type < 5) == (Type < 5) // fallback "Dolby" component according to the "Premiere pseudo standard"
|
|
|
|
)) {
|
2006-02-19 13:27:51 +01:00
|
|
|
if (!Index--)
|
|
|
|
return &components[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
// --- cEvent ----------------------------------------------------------------
|
|
|
|
|
2006-02-26 14:13:30 +01:00
|
|
|
cEvent::cEvent(tEventID EventID)
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
2005-05-28 13:17:20 +02:00
|
|
|
schedule = NULL;
|
2003-12-22 13:29:24 +01:00
|
|
|
eventID = EventID;
|
2012-03-10 15:10:43 +01:00
|
|
|
tableID = 0xFF; // actual table ids are 0x4E..0x60
|
2003-12-25 12:50:22 +01:00
|
|
|
version = 0xFF; // actual version numbers are 0..31
|
2006-03-26 13:53:58 +02:00
|
|
|
runningStatus = SI::RunningStatusUndefined;
|
2003-12-22 13:29:24 +01:00
|
|
|
title = NULL;
|
|
|
|
shortText = NULL;
|
|
|
|
description = NULL;
|
2005-01-02 15:11:44 +01:00
|
|
|
components = NULL;
|
2010-01-03 12:20:37 +01:00
|
|
|
memset(contents, 0, sizeof(contents));
|
2010-01-03 14:28:33 +01:00
|
|
|
parentalRating = 0;
|
2003-12-22 13:29:24 +01:00
|
|
|
startTime = 0;
|
|
|
|
duration = 0;
|
2004-02-22 13:33:20 +01:00
|
|
|
vps = 0;
|
2004-11-07 10:43:52 +01:00
|
|
|
SetSeen();
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cEvent::~cEvent()
|
|
|
|
{
|
|
|
|
free(title);
|
|
|
|
free(shortText);
|
|
|
|
free(description);
|
2005-01-02 15:11:44 +01:00
|
|
|
delete components;
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
2004-11-01 10:40:38 +01:00
|
|
|
int cEvent::Compare(const cListObject &ListObject) const
|
2004-02-21 13:56:20 +01:00
|
|
|
{
|
|
|
|
cEvent *e = (cEvent *)&ListObject;
|
2004-11-01 10:40:38 +01:00
|
|
|
return startTime - e->startTime;
|
2004-02-21 13:56:20 +01:00
|
|
|
}
|
|
|
|
|
2005-05-28 10:09:06 +02:00
|
|
|
tChannelID cEvent::ChannelID(void) const
|
|
|
|
{
|
|
|
|
return schedule ? schedule->ChannelID() : tChannelID();
|
|
|
|
}
|
|
|
|
|
2006-02-26 14:13:30 +01:00
|
|
|
void cEvent::SetEventID(tEventID EventID)
|
2003-12-25 12:50:22 +01:00
|
|
|
{
|
2005-05-28 13:17:20 +02:00
|
|
|
if (eventID != EventID) {
|
|
|
|
if (schedule)
|
|
|
|
schedule->UnhashEvent(this);
|
|
|
|
eventID = EventID;
|
|
|
|
if (schedule)
|
|
|
|
schedule->HashEvent(this);
|
|
|
|
}
|
2003-12-25 12:50:22 +01:00
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
void cEvent::SetTableID(uchar TableID)
|
|
|
|
{
|
|
|
|
tableID = TableID;
|
|
|
|
}
|
|
|
|
|
2003-12-25 12:50:22 +01:00
|
|
|
void cEvent::SetVersion(uchar Version)
|
|
|
|
{
|
|
|
|
version = Version;
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:01:05 +01:00
|
|
|
void cEvent::SetRunningStatus(int RunningStatus, cChannel *Channel)
|
2004-02-21 12:28:17 +01:00
|
|
|
{
|
2006-02-28 14:00:28 +01:00
|
|
|
if (Channel && runningStatus != RunningStatus && (RunningStatus > SI::RunningStatusNotRunning || runningStatus > SI::RunningStatusUndefined) && Channel->HasTimer())
|
2006-03-25 12:51:29 +01:00
|
|
|
isyslog("channel %d (%s) event %s status %d", Channel->Number(), Channel->Name(), *ToDescr(), RunningStatus);
|
2004-02-21 12:28:17 +01:00
|
|
|
runningStatus = RunningStatus;
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
void cEvent::SetTitle(const char *Title)
|
|
|
|
{
|
|
|
|
title = strcpyrealloc(title, Title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEvent::SetShortText(const char *ShortText)
|
|
|
|
{
|
|
|
|
shortText = strcpyrealloc(shortText, ShortText);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEvent::SetDescription(const char *Description)
|
|
|
|
{
|
|
|
|
description = strcpyrealloc(description, Description);
|
|
|
|
}
|
|
|
|
|
2005-01-02 15:11:44 +01:00
|
|
|
void cEvent::SetComponents(cComponents *Components)
|
|
|
|
{
|
|
|
|
delete components;
|
|
|
|
components = Components;
|
|
|
|
}
|
|
|
|
|
2010-01-03 12:20:37 +01:00
|
|
|
void cEvent::SetContents(uchar *Contents)
|
|
|
|
{
|
2010-01-08 15:23:34 +01:00
|
|
|
for (int i = 0; i < MaxEventContents; i++)
|
2010-01-03 12:20:37 +01:00
|
|
|
contents[i] = Contents[i];
|
|
|
|
}
|
|
|
|
|
2010-01-03 14:28:33 +01:00
|
|
|
void cEvent::SetParentalRating(int ParentalRating)
|
|
|
|
{
|
|
|
|
parentalRating = ParentalRating;
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
void cEvent::SetStartTime(time_t StartTime)
|
|
|
|
{
|
2005-05-28 13:17:20 +02:00
|
|
|
if (startTime != StartTime) {
|
|
|
|
if (schedule)
|
|
|
|
schedule->UnhashEvent(this);
|
|
|
|
startTime = StartTime;
|
|
|
|
if (schedule)
|
|
|
|
schedule->HashEvent(this);
|
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cEvent::SetDuration(int Duration)
|
|
|
|
{
|
|
|
|
duration = Duration;
|
|
|
|
}
|
|
|
|
|
2004-02-22 13:33:20 +01:00
|
|
|
void cEvent::SetVps(time_t Vps)
|
|
|
|
{
|
|
|
|
vps = Vps;
|
|
|
|
}
|
|
|
|
|
2004-10-24 15:01:50 +02:00
|
|
|
void cEvent::SetSeen(void)
|
|
|
|
{
|
|
|
|
seen = time(NULL);
|
|
|
|
}
|
|
|
|
|
2006-03-25 12:51:29 +01:00
|
|
|
cString cEvent::ToDescr(void) const
|
|
|
|
{
|
|
|
|
char vpsbuf[64] = "";
|
|
|
|
if (Vps())
|
|
|
|
sprintf(vpsbuf, "(VPS: %s) ", *GetVpsString());
|
|
|
|
return cString::sprintf("%s %s-%s %s'%s'", *GetDateString(), *GetTimeString(), *GetEndTimeString(), vpsbuf, Title());
|
|
|
|
}
|
|
|
|
|
2004-02-29 14:21:22 +01:00
|
|
|
bool cEvent::HasTimer(void) const
|
|
|
|
{
|
|
|
|
for (cTimer *t = Timers.First(); t; t = Timers.Next(t)) {
|
|
|
|
if (t->Event() == this)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-03-06 11:27:08 +01:00
|
|
|
bool cEvent::IsRunning(bool OrAboutToStart) const
|
|
|
|
{
|
2006-05-25 14:59:33 +02:00
|
|
|
return runningStatus >= (OrAboutToStart ? SI::RunningStatusStartsInAFewSeconds : SI::RunningStatusPausing);
|
2004-03-06 11:27:08 +01:00
|
|
|
}
|
|
|
|
|
2010-01-03 12:20:37 +01:00
|
|
|
const char *cEvent::ContentToString(uchar Content)
|
|
|
|
{
|
|
|
|
switch (Content & 0xF0) {
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgMovieDrama:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$Movie/Drama");
|
|
|
|
case 0x01: return tr("Content$Detective/Thriller");
|
|
|
|
case 0x02: return tr("Content$Adventure/Western/War");
|
|
|
|
case 0x03: return tr("Content$Science Fiction/Fantasy/Horror");
|
|
|
|
case 0x04: return tr("Content$Comedy");
|
|
|
|
case 0x05: return tr("Content$Soap/Melodrama/Folkloric");
|
|
|
|
case 0x06: return tr("Content$Romance");
|
|
|
|
case 0x07: return tr("Content$Serious/Classical/Religious/Historical Movie/Drama");
|
|
|
|
case 0x08: return tr("Content$Adult Movie/Drama");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgNewsCurrentAffairs:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$News/Current Affairs");
|
|
|
|
case 0x01: return tr("Content$News/Weather Report");
|
|
|
|
case 0x02: return tr("Content$News Magazine");
|
|
|
|
case 0x03: return tr("Content$Documentary");
|
|
|
|
case 0x04: return tr("Content$Discussion/Inverview/Debate");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgShow:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$Show/Game Show");
|
|
|
|
case 0x01: return tr("Content$Game Show/Quiz/Contest");
|
|
|
|
case 0x02: return tr("Content$Variety Show");
|
|
|
|
case 0x03: return tr("Content$Talk Show");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgSports:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$Sports");
|
|
|
|
case 0x01: return tr("Content$Special Event");
|
|
|
|
case 0x02: return tr("Content$Sport Magazine");
|
|
|
|
case 0x03: return tr("Content$Football/Soccer");
|
|
|
|
case 0x04: return tr("Content$Tennis/Squash");
|
|
|
|
case 0x05: return tr("Content$Team Sports");
|
|
|
|
case 0x06: return tr("Content$Athletics");
|
|
|
|
case 0x07: return tr("Content$Motor Sport");
|
|
|
|
case 0x08: return tr("Content$Water Sport");
|
|
|
|
case 0x09: return tr("Content$Winter Sports");
|
|
|
|
case 0x0A: return tr("Content$Equestrian");
|
|
|
|
case 0x0B: return tr("Content$Martial Sports");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgChildrenYouth:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$Children's/Youth Programme");
|
|
|
|
case 0x01: return tr("Content$Pre-school Children's Programme");
|
|
|
|
case 0x02: return tr("Content$Entertainment Programme for 6 to 14");
|
|
|
|
case 0x03: return tr("Content$Entertainment Programme for 10 to 16");
|
|
|
|
case 0x04: return tr("Content$Informational/Educational/School Programme");
|
|
|
|
case 0x05: return tr("Content$Cartoons/Puppets");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgMusicBalletDance:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$Music/Ballet/Dance");
|
|
|
|
case 0x01: return tr("Content$Rock/Pop");
|
|
|
|
case 0x02: return tr("Content$Serious/Classical Music");
|
|
|
|
case 0x03: return tr("Content$Folk/Tradional Music");
|
|
|
|
case 0x04: return tr("Content$Jazz");
|
|
|
|
case 0x05: return tr("Content$Musical/Opera");
|
|
|
|
case 0x06: return tr("Content$Ballet");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgArtsCulture:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$Arts/Culture");
|
|
|
|
case 0x01: return tr("Content$Performing Arts");
|
|
|
|
case 0x02: return tr("Content$Fine Arts");
|
|
|
|
case 0x03: return tr("Content$Religion");
|
|
|
|
case 0x04: return tr("Content$Popular Culture/Traditional Arts");
|
|
|
|
case 0x05: return tr("Content$Literature");
|
|
|
|
case 0x06: return tr("Content$Film/Cinema");
|
|
|
|
case 0x07: return tr("Content$Experimental Film/Video");
|
|
|
|
case 0x08: return tr("Content$Broadcasting/Press");
|
|
|
|
case 0x09: return tr("Content$New Media");
|
|
|
|
case 0x0A: return tr("Content$Arts/Culture Magazine");
|
|
|
|
case 0x0B: return tr("Content$Fashion");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgSocialPoliticalEconomics:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$Social/Political/Economics");
|
|
|
|
case 0x01: return tr("Content$Magazine/Report/Documentary");
|
|
|
|
case 0x02: return tr("Content$Economics/Social Advisory");
|
|
|
|
case 0x03: return tr("Content$Remarkable People");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgEducationalScience:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$Education/Science/Factual");
|
|
|
|
case 0x01: return tr("Content$Nature/Animals/Environment");
|
|
|
|
case 0x02: return tr("Content$Technology/Natural Sciences");
|
|
|
|
case 0x03: return tr("Content$Medicine/Physiology/Psychology");
|
|
|
|
case 0x04: return tr("Content$Foreign Countries/Expeditions");
|
|
|
|
case 0x05: return tr("Content$Social/Spiritual Sciences");
|
|
|
|
case 0x06: return tr("Content$Further Education");
|
|
|
|
case 0x07: return tr("Content$Languages");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgLeisureHobbies:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
default:
|
|
|
|
case 0x00: return tr("Content$Leisure/Hobbies");
|
|
|
|
case 0x01: return tr("Content$Tourism/Travel");
|
|
|
|
case 0x02: return tr("Content$Handicraft");
|
|
|
|
case 0x03: return tr("Content$Motoring");
|
|
|
|
case 0x04: return tr("Content$Fitness & Health");
|
|
|
|
case 0x05: return tr("Content$Cooking");
|
|
|
|
case 0x06: return tr("Content$Advertisement/Shopping");
|
|
|
|
case 0x07: return tr("Content$Gardening");
|
|
|
|
}
|
|
|
|
break;
|
2010-01-08 15:23:34 +01:00
|
|
|
case ecgSpecial:
|
2010-01-03 12:20:37 +01:00
|
|
|
switch (Content & 0x0F) {
|
|
|
|
case 0x00: return tr("Content$Original Language");
|
|
|
|
case 0x01: return tr("Content$Black & White");
|
|
|
|
case 0x02: return tr("Content$Unpublished");
|
|
|
|
case 0x03: return tr("Content$Live Broadcast");
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2010-01-03 14:28:33 +01:00
|
|
|
cString cEvent::GetParentalRatingString(void) const
|
|
|
|
{
|
|
|
|
if (parentalRating)
|
|
|
|
return cString::sprintf(tr("ParentalRating$from %d"), parentalRating);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-12-26 12:45:22 +01:00
|
|
|
cString cEvent::GetDateString(void) const
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
2005-05-16 14:45:11 +02:00
|
|
|
return DateString(startTime);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
2004-12-26 12:45:22 +01:00
|
|
|
cString cEvent::GetTimeString(void) const
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
2005-05-16 14:45:11 +02:00
|
|
|
return TimeString(startTime);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
2004-12-26 12:45:22 +01:00
|
|
|
cString cEvent::GetEndTimeString(void) const
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
2005-05-16 14:45:11 +02:00
|
|
|
return TimeString(startTime + duration);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
2004-12-26 12:45:22 +01:00
|
|
|
cString cEvent::GetVpsString(void) const
|
2004-02-22 13:33:20 +01:00
|
|
|
{
|
2004-12-26 12:45:22 +01:00
|
|
|
char buf[25];
|
2004-02-22 13:33:20 +01:00
|
|
|
struct tm tm_r;
|
2012-02-13 15:00:24 +01:00
|
|
|
strftime(buf, sizeof(buf), "%d.%m. %R", localtime_r(&vps, &tm_r));
|
2004-02-22 13:33:20 +01:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2005-05-16 14:45:11 +02:00
|
|
|
void cEvent::Dump(FILE *f, const char *Prefix, bool InfoOnly) const
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
2005-05-16 14:45:11 +02:00
|
|
|
if (InfoOnly || startTime + duration + Setup.EPGLinger * 60 >= time(NULL)) {
|
2006-02-25 12:39:23 +01:00
|
|
|
fprintf(f, "%sE %u %ld %d %X %X\n", Prefix, eventID, startTime, duration, tableID, version);
|
2003-12-22 13:29:24 +01:00
|
|
|
if (!isempty(title))
|
|
|
|
fprintf(f, "%sT %s\n", Prefix, title);
|
|
|
|
if (!isempty(shortText))
|
|
|
|
fprintf(f, "%sS %s\n", Prefix, shortText);
|
2004-03-13 12:41:24 +01:00
|
|
|
if (!isempty(description)) {
|
|
|
|
strreplace(description, '\n', '|');
|
2003-12-22 13:29:24 +01:00
|
|
|
fprintf(f, "%sD %s\n", Prefix, description);
|
2004-03-13 12:41:24 +01:00
|
|
|
strreplace(description, '|', '\n');
|
|
|
|
}
|
2010-01-03 12:20:37 +01:00
|
|
|
if (contents[0]) {
|
|
|
|
fprintf(f, "%sG", Prefix);
|
|
|
|
for (int i = 0; Contents(i); i++)
|
|
|
|
fprintf(f, " %02X", Contents(i));
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
2010-01-03 14:28:33 +01:00
|
|
|
if (parentalRating)
|
|
|
|
fprintf(f, "%sR %d\n", Prefix, parentalRating);
|
2005-01-02 15:11:44 +01:00
|
|
|
if (components) {
|
|
|
|
for (int i = 0; i < components->NumComponents(); i++) {
|
|
|
|
tComponent *p = components->Component(i);
|
|
|
|
fprintf(f, "%sX %s\n", Prefix, *p->ToString());
|
|
|
|
}
|
|
|
|
}
|
2006-02-25 12:39:23 +01:00
|
|
|
if (vps)
|
2004-02-22 13:33:20 +01:00
|
|
|
fprintf(f, "%sV %ld\n", Prefix, vps);
|
2005-05-16 14:45:11 +02:00
|
|
|
if (!InfoOnly)
|
|
|
|
fprintf(f, "%se\n", Prefix);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-16 14:45:11 +02:00
|
|
|
bool cEvent::Parse(char *s)
|
|
|
|
{
|
|
|
|
char *t = skipspace(s + 1);
|
|
|
|
switch (*s) {
|
|
|
|
case 'T': SetTitle(t);
|
|
|
|
break;
|
|
|
|
case 'S': SetShortText(t);
|
|
|
|
break;
|
|
|
|
case 'D': strreplace(t, '|', '\n');
|
|
|
|
SetDescription(t);
|
|
|
|
break;
|
2010-01-03 12:20:37 +01:00
|
|
|
case 'G': {
|
|
|
|
memset(contents, 0, sizeof(contents));
|
2010-01-08 15:23:34 +01:00
|
|
|
for (int i = 0; i < MaxEventContents; i++) {
|
2010-01-03 12:20:37 +01:00
|
|
|
char *tail = NULL;
|
|
|
|
int c = strtol(t, &tail, 16);
|
|
|
|
if (0x00 < c && c <= 0xFF) {
|
|
|
|
contents[i] = c;
|
|
|
|
t = tail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-01-03 14:28:33 +01:00
|
|
|
case 'R': SetParentalRating(atoi(t));
|
|
|
|
break;
|
2005-05-16 14:45:11 +02:00
|
|
|
case 'X': if (!components)
|
|
|
|
components = new cComponents;
|
|
|
|
components->SetComponent(components->NumComponents(), t);
|
|
|
|
break;
|
|
|
|
case 'V': SetVps(atoi(t));
|
|
|
|
break;
|
|
|
|
default: esyslog("ERROR: unexpected tag while reading EPG data: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
bool cEvent::Read(FILE *f, cSchedule *Schedule)
|
|
|
|
{
|
|
|
|
if (Schedule) {
|
|
|
|
cEvent *Event = NULL;
|
|
|
|
char *s;
|
2005-10-09 13:13:36 +02:00
|
|
|
int line = 0;
|
2004-12-26 12:45:22 +01:00
|
|
|
cReadLine ReadLine;
|
|
|
|
while ((s = ReadLine.Read(f)) != NULL) {
|
2005-10-09 13:13:36 +02:00
|
|
|
line++;
|
2003-12-22 13:29:24 +01:00
|
|
|
char *t = skipspace(s + 1);
|
|
|
|
switch (*s) {
|
|
|
|
case 'E': if (!Event) {
|
|
|
|
unsigned int EventID;
|
|
|
|
time_t StartTime;
|
|
|
|
int Duration;
|
|
|
|
unsigned int TableID = 0;
|
2006-03-26 13:45:17 +02:00
|
|
|
unsigned int Version = 0xFF; // actual value is ignored
|
2005-12-25 11:13:33 +01:00
|
|
|
int n = sscanf(t, "%u %ld %d %X %X", &EventID, &StartTime, &Duration, &TableID, &Version);
|
|
|
|
if (n >= 3 && n <= 5) {
|
2003-12-22 13:29:24 +01:00
|
|
|
Event = (cEvent *)Schedule->GetEvent(EventID, StartTime);
|
2005-05-28 13:17:20 +02:00
|
|
|
cEvent *newEvent = NULL;
|
2005-07-30 14:53:29 +02:00
|
|
|
if (Event)
|
|
|
|
DELETENULL(Event->components);
|
2006-05-07 09:13:36 +02:00
|
|
|
if (!Event) {
|
2005-05-28 13:17:20 +02:00
|
|
|
Event = newEvent = new cEvent(EventID);
|
2006-05-07 09:13:36 +02:00
|
|
|
Event->seen = 0;
|
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
if (Event) {
|
|
|
|
Event->SetTableID(TableID);
|
|
|
|
Event->SetStartTime(StartTime);
|
|
|
|
Event->SetDuration(Duration);
|
2005-05-28 13:17:20 +02:00
|
|
|
if (newEvent)
|
|
|
|
Schedule->AddEvent(newEvent);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-02-03 13:19:15 +01:00
|
|
|
case 'e': if (Event && !Event->Title())
|
2006-01-27 13:42:10 +01:00
|
|
|
Event->SetTitle(tr("No title"));
|
|
|
|
Event = NULL;
|
2003-12-22 13:29:24 +01:00
|
|
|
break;
|
|
|
|
case 'c': // to keep things simple we react on 'c' here
|
|
|
|
return true;
|
2005-10-09 13:13:36 +02:00
|
|
|
default: if (Event && !Event->Parse(s)) {
|
|
|
|
esyslog("ERROR: EPG data problem in line %d", line);
|
2005-05-16 14:45:11 +02:00
|
|
|
return false;
|
2005-10-09 13:13:36 +02:00
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
esyslog("ERROR: unexpected end of file while reading EPG data");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-06-05 12:19:50 +02:00
|
|
|
#define MAXEPGBUGFIXSTATS 13
|
2003-12-22 13:29:24 +01:00
|
|
|
#define MAXEPGBUGFIXCHANS 100
|
|
|
|
struct tEpgBugFixStats {
|
|
|
|
int hits;
|
|
|
|
int n;
|
|
|
|
tChannelID channelIDs[MAXEPGBUGFIXCHANS];
|
|
|
|
tEpgBugFixStats(void) { hits = n = 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
tEpgBugFixStats EpgBugFixStats[MAXEPGBUGFIXSTATS];
|
|
|
|
|
|
|
|
static void EpgBugFixStat(int Number, tChannelID ChannelID)
|
|
|
|
{
|
|
|
|
if (0 <= Number && Number < MAXEPGBUGFIXSTATS) {
|
|
|
|
tEpgBugFixStats *p = &EpgBugFixStats[Number];
|
|
|
|
p->hits++;
|
|
|
|
int i = 0;
|
|
|
|
for (; i < p->n; i++) {
|
|
|
|
if (p->channelIDs[i] == ChannelID)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == p->n && p->n < MAXEPGBUGFIXCHANS)
|
|
|
|
p->channelIDs[p->n++] = ChannelID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 13:41:54 +02:00
|
|
|
void ReportEpgBugFixStats(bool Force)
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
|
|
|
if (Setup.EPGBugfixLevel > 0) {
|
2012-09-24 13:41:54 +02:00
|
|
|
static time_t LastReport = 0;
|
|
|
|
time_t now = time(NULL);
|
|
|
|
if (now - LastReport > 3600 || Force) {
|
|
|
|
LastReport = now;
|
|
|
|
struct tm tm_r;
|
|
|
|
struct tm *ptm = localtime_r(&now, &tm_r);
|
|
|
|
if (ptm->tm_hour != 5)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
2003-12-22 13:29:24 +01:00
|
|
|
bool GotHits = false;
|
|
|
|
char buffer[1024];
|
|
|
|
for (int i = 0; i < MAXEPGBUGFIXSTATS; i++) {
|
2012-02-13 14:54:42 +01:00
|
|
|
const char *delim = " ";
|
2003-12-22 13:29:24 +01:00
|
|
|
tEpgBugFixStats *p = &EpgBugFixStats[i];
|
|
|
|
if (p->hits) {
|
|
|
|
bool PrintedStats = false;
|
|
|
|
char *q = buffer;
|
|
|
|
*buffer = 0;
|
|
|
|
for (int c = 0; c < p->n; c++) {
|
|
|
|
cChannel *channel = Channels.GetByChannelID(p->channelIDs[c], true);
|
|
|
|
if (channel) {
|
|
|
|
if (!GotHits) {
|
|
|
|
dsyslog("=====================");
|
|
|
|
dsyslog("EPG bugfix statistics");
|
|
|
|
dsyslog("=====================");
|
|
|
|
dsyslog("IF SOMEBODY WHO IS IN CHARGE OF THE EPG DATA FOR ONE OF THE LISTED");
|
|
|
|
dsyslog("CHANNELS READS THIS: PLEASE TAKE A LOOK AT THE FUNCTION cEvent::FixEpgBugs()");
|
|
|
|
dsyslog("IN VDR/epg.c TO LEARN WHAT'S WRONG WITH YOUR DATA, AND FIX IT!");
|
|
|
|
dsyslog("=====================");
|
2012-02-13 14:54:42 +01:00
|
|
|
dsyslog("Fix Hits Channels");
|
2003-12-22 13:29:24 +01:00
|
|
|
GotHits = true;
|
|
|
|
}
|
|
|
|
if (!PrintedStats) {
|
2012-02-13 14:54:42 +01:00
|
|
|
q += snprintf(q, sizeof(buffer) - (q - buffer), "%-3d %-4d", i, p->hits);
|
2003-12-22 13:29:24 +01:00
|
|
|
PrintedStats = true;
|
|
|
|
}
|
|
|
|
q += snprintf(q, sizeof(buffer) - (q - buffer), "%s%s", delim, channel->Name());
|
|
|
|
delim = ", ";
|
2004-01-04 15:20:42 +01:00
|
|
|
if (q - buffer > 80) {
|
|
|
|
q += snprintf(q, sizeof(buffer) - (q - buffer), "%s...", delim);
|
|
|
|
break;
|
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*buffer)
|
|
|
|
dsyslog("%s", buffer);
|
|
|
|
}
|
2012-09-24 13:41:54 +02:00
|
|
|
p->hits = p->n = 0;
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
if (GotHits)
|
|
|
|
dsyslog("=====================");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-29 14:30:48 +02:00
|
|
|
static void StripControlCharacters(char *s)
|
|
|
|
{
|
|
|
|
if (s) {
|
|
|
|
int len = strlen(s);
|
|
|
|
while (len > 0) {
|
|
|
|
int l = Utf8CharLen(s);
|
|
|
|
uchar *p = (uchar *)s;
|
|
|
|
if (l == 2 && *p == 0xC2) // UTF-8 sequence
|
|
|
|
p++;
|
|
|
|
if (*p == 0x86 || *p == 0x87) {
|
|
|
|
memmove(s, p + 1, len - l + 1); // we also copy the terminating 0!
|
|
|
|
len -= l;
|
|
|
|
l = 0;
|
|
|
|
}
|
|
|
|
s += l;
|
|
|
|
len -= l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
void cEvent::FixEpgBugs(void)
|
|
|
|
{
|
2006-04-22 12:03:55 +02:00
|
|
|
if (isempty(title)) {
|
2006-01-20 14:15:27 +01:00
|
|
|
// we don't want any "(null)" titles
|
|
|
|
title = strcpyrealloc(title, tr("No title"));
|
|
|
|
EpgBugFixStat(12, ChannelID());
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
if (Setup.EPGBugfixLevel == 0)
|
2006-07-22 10:48:22 +02:00
|
|
|
goto Final;
|
2003-12-22 13:29:24 +01:00
|
|
|
|
|
|
|
// Some TV stations apparently have their own idea about how to fill in the
|
|
|
|
// EPG data. Let's fix their bugs as good as we can:
|
|
|
|
|
2006-01-20 14:15:27 +01:00
|
|
|
// Some channels put the ShortText in quotes and use either the ShortText
|
|
|
|
// or the Description field, depending on how long the string is:
|
|
|
|
//
|
|
|
|
// Title
|
|
|
|
// "ShortText". Description
|
|
|
|
//
|
|
|
|
if ((shortText == NULL) != (description == NULL)) {
|
|
|
|
char *p = shortText ? shortText : description;
|
|
|
|
if (*p == '"') {
|
|
|
|
const char *delim = "\".";
|
|
|
|
char *e = strstr(p + 1, delim);
|
|
|
|
if (e) {
|
|
|
|
*e = 0;
|
|
|
|
char *s = strdup(p + 1);
|
|
|
|
char *d = strdup(e + strlen(delim));
|
|
|
|
free(shortText);
|
|
|
|
free(description);
|
|
|
|
shortText = s;
|
|
|
|
description = d;
|
|
|
|
EpgBugFixStat(1, ChannelID());
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
2006-01-20 14:15:27 +01:00
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
|
2006-01-20 14:15:27 +01:00
|
|
|
// Some channels put the Description into the ShortText (preceded
|
|
|
|
// by a blank) if there is no actual ShortText and the Description
|
|
|
|
// is short enough:
|
|
|
|
//
|
|
|
|
// Title
|
|
|
|
// Description
|
|
|
|
//
|
|
|
|
if (shortText && !description) {
|
|
|
|
if (*shortText == ' ') {
|
|
|
|
memmove(shortText, shortText + 1, strlen(shortText));
|
|
|
|
description = shortText;
|
2003-12-22 13:29:24 +01:00
|
|
|
shortText = NULL;
|
2006-01-20 14:15:27 +01:00
|
|
|
EpgBugFixStat(2, ChannelID());
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
2006-01-20 14:15:27 +01:00
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
|
2006-01-20 14:15:27 +01:00
|
|
|
// Sometimes they repeat the Title in the ShortText:
|
|
|
|
//
|
|
|
|
// Title
|
|
|
|
// Title
|
|
|
|
//
|
|
|
|
if (shortText && strcmp(title, shortText) == 0) {
|
|
|
|
free(shortText);
|
|
|
|
shortText = NULL;
|
|
|
|
EpgBugFixStat(3, ChannelID());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some channels put the ShortText between double quotes, which is nothing
|
|
|
|
// but annoying (some even put a '.' after the closing '"'):
|
|
|
|
//
|
|
|
|
// Title
|
|
|
|
// "ShortText"[.]
|
|
|
|
//
|
|
|
|
if (shortText && *shortText == '"') {
|
|
|
|
int l = strlen(shortText);
|
|
|
|
if (l > 2 && (shortText[l - 1] == '"' || (shortText[l - 1] == '.' && shortText[l - 2] == '"'))) {
|
|
|
|
memmove(shortText, shortText + 1, l);
|
|
|
|
char *p = strrchr(shortText, '"');
|
|
|
|
if (p)
|
|
|
|
*p = 0;
|
|
|
|
EpgBugFixStat(4, ChannelID());
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
2006-01-20 14:15:27 +01:00
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
|
2006-01-20 14:15:27 +01:00
|
|
|
if (Setup.EPGBugfixLevel <= 1)
|
2006-07-22 10:48:22 +02:00
|
|
|
goto Final;
|
2003-12-22 13:29:24 +01:00
|
|
|
|
2006-01-20 14:15:27 +01:00
|
|
|
// Some channels apparently try to do some formatting in the texts,
|
|
|
|
// which is a bad idea because they have no way of knowing the width
|
|
|
|
// of the window that will actually display the text.
|
|
|
|
// Remove excess whitespace:
|
|
|
|
title = compactspace(title);
|
|
|
|
shortText = compactspace(shortText);
|
|
|
|
description = compactspace(description);
|
2003-12-22 13:29:24 +01:00
|
|
|
|
|
|
|
#define MAX_USEFUL_EPISODE_LENGTH 40
|
2006-01-20 14:15:27 +01:00
|
|
|
// Some channels put a whole lot of information in the ShortText and leave
|
|
|
|
// the Description totally empty. So if the ShortText length exceeds
|
|
|
|
// MAX_USEFUL_EPISODE_LENGTH, let's put this into the Description
|
|
|
|
// instead:
|
|
|
|
if (!isempty(shortText) && isempty(description)) {
|
|
|
|
if (strlen(shortText) > MAX_USEFUL_EPISODE_LENGTH) {
|
|
|
|
free(description);
|
|
|
|
description = shortText;
|
|
|
|
shortText = NULL;
|
|
|
|
EpgBugFixStat(6, ChannelID());
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
2006-01-20 14:15:27 +01:00
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
|
2006-01-20 14:15:27 +01:00
|
|
|
// Some channels put the same information into ShortText and Description.
|
|
|
|
// In that case we delete one of them:
|
|
|
|
if (shortText && description && strcmp(shortText, description) == 0) {
|
|
|
|
if (strlen(shortText) > MAX_USEFUL_EPISODE_LENGTH) {
|
|
|
|
free(shortText);
|
|
|
|
shortText = NULL;
|
2004-02-14 11:00:00 +01:00
|
|
|
}
|
2006-01-20 14:15:27 +01:00
|
|
|
else {
|
|
|
|
free(description);
|
|
|
|
description = NULL;
|
|
|
|
}
|
|
|
|
EpgBugFixStat(7, ChannelID());
|
|
|
|
}
|
2004-02-14 11:00:00 +01:00
|
|
|
|
2006-01-20 14:15:27 +01:00
|
|
|
// Some channels use the ` ("backtick") character, where a ' (single quote)
|
|
|
|
// would be normally used. Actually, "backticks" in normal text don't make
|
|
|
|
// much sense, so let's replace them:
|
|
|
|
strreplace(title, '`', '\'');
|
|
|
|
strreplace(shortText, '`', '\'');
|
|
|
|
strreplace(description, '`', '\'');
|
2005-01-02 15:11:44 +01:00
|
|
|
|
2006-01-20 14:15:27 +01:00
|
|
|
if (Setup.EPGBugfixLevel <= 2)
|
2006-07-22 10:48:22 +02:00
|
|
|
goto Final;
|
2005-01-02 15:11:44 +01:00
|
|
|
|
2006-01-20 14:15:27 +01:00
|
|
|
// The stream components have a "description" field which some channels
|
|
|
|
// apparently have no idea of how to set correctly:
|
|
|
|
if (components) {
|
|
|
|
for (int i = 0; i < components->NumComponents(); i++) {
|
|
|
|
tComponent *p = components->Component(i);
|
|
|
|
switch (p->stream) {
|
|
|
|
case 0x01: { // video
|
|
|
|
if (p->description) {
|
|
|
|
if (strcasecmp(p->description, "Video") == 0 ||
|
|
|
|
strcasecmp(p->description, "Bildformat") == 0) {
|
|
|
|
// Yes, we know it's video - that's what the 'stream' code
|
|
|
|
// is for! But _which_ video is it?
|
|
|
|
free(p->description);
|
|
|
|
p->description = NULL;
|
|
|
|
EpgBugFixStat(8, ChannelID());
|
2005-01-02 15:11:44 +01:00
|
|
|
}
|
|
|
|
}
|
2006-01-20 14:15:27 +01:00
|
|
|
if (!p->description) {
|
|
|
|
switch (p->type) {
|
|
|
|
case 0x01:
|
|
|
|
case 0x05: p->description = strdup("4:3"); break;
|
|
|
|
case 0x02:
|
|
|
|
case 0x03:
|
|
|
|
case 0x06:
|
|
|
|
case 0x07: p->description = strdup("16:9"); break;
|
|
|
|
case 0x04:
|
|
|
|
case 0x08: p->description = strdup(">16:9"); break;
|
|
|
|
case 0x09:
|
|
|
|
case 0x0D: p->description = strdup("HD 4:3"); break;
|
|
|
|
case 0x0A:
|
|
|
|
case 0x0B:
|
|
|
|
case 0x0E:
|
|
|
|
case 0x0F: p->description = strdup("HD 16:9"); break;
|
|
|
|
case 0x0C:
|
|
|
|
case 0x10: p->description = strdup("HD >16:9"); break;
|
2009-12-06 12:57:45 +01:00
|
|
|
default: ;
|
2006-01-20 14:15:27 +01:00
|
|
|
}
|
|
|
|
EpgBugFixStat(9, ChannelID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x02: { // audio
|
|
|
|
if (p->description) {
|
|
|
|
if (strcasecmp(p->description, "Audio") == 0) {
|
|
|
|
// Yes, we know it's audio - that's what the 'stream' code
|
|
|
|
// is for! But _which_ audio is it?
|
|
|
|
free(p->description);
|
|
|
|
p->description = NULL;
|
|
|
|
EpgBugFixStat(10, ChannelID());
|
2005-01-02 15:11:44 +01:00
|
|
|
}
|
|
|
|
}
|
2006-01-20 14:15:27 +01:00
|
|
|
if (!p->description) {
|
|
|
|
switch (p->type) {
|
|
|
|
case 0x05: p->description = strdup("Dolby Digital"); break;
|
2009-12-06 12:57:45 +01:00
|
|
|
default: ; // all others will just display the language
|
2006-01-20 14:15:27 +01:00
|
|
|
}
|
|
|
|
EpgBugFixStat(11, ChannelID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-12-06 12:57:45 +01:00
|
|
|
default: ;
|
2006-01-20 14:15:27 +01:00
|
|
|
}
|
|
|
|
}
|
2005-06-05 12:19:50 +02:00
|
|
|
}
|
2006-07-22 10:48:22 +02:00
|
|
|
|
|
|
|
Final:
|
|
|
|
|
2012-01-08 15:40:17 +01:00
|
|
|
// VDR can't usefully handle newline characters in the title, shortText or component description of EPG
|
2006-07-22 10:48:22 +02:00
|
|
|
// data, so let's always convert them to blanks (independent of the setting of EPGBugfixLevel):
|
|
|
|
strreplace(title, '\n', ' ');
|
|
|
|
strreplace(shortText, '\n', ' ');
|
2012-01-08 15:40:17 +01:00
|
|
|
if (components) {
|
|
|
|
for (int i = 0; i < components->NumComponents(); i++) {
|
|
|
|
tComponent *p = components->Component(i);
|
|
|
|
if (p->description)
|
|
|
|
strreplace(p->description, '\n', ' ');
|
|
|
|
}
|
|
|
|
}
|
2006-07-22 10:48:22 +02:00
|
|
|
// Same for control characters:
|
2012-09-29 14:30:48 +02:00
|
|
|
StripControlCharacters(title);
|
|
|
|
StripControlCharacters(shortText);
|
|
|
|
StripControlCharacters(description);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- cSchedule -------------------------------------------------------------
|
|
|
|
|
|
|
|
cSchedule::cSchedule(tChannelID ChannelID)
|
|
|
|
{
|
|
|
|
channelID = ChannelID;
|
2006-08-05 10:15:34 +02:00
|
|
|
hasRunning = false;
|
2004-10-24 15:01:50 +02:00
|
|
|
modified = 0;
|
2005-03-20 13:12:07 +01:00
|
|
|
presentSeen = 0;
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cEvent *cSchedule::AddEvent(cEvent *Event)
|
|
|
|
{
|
|
|
|
events.Add(Event);
|
2005-05-28 13:17:20 +02:00
|
|
|
Event->schedule = this;
|
|
|
|
HashEvent(Event);
|
2003-12-22 13:29:24 +01:00
|
|
|
return Event;
|
|
|
|
}
|
|
|
|
|
2005-05-28 13:17:20 +02:00
|
|
|
void cSchedule::DelEvent(cEvent *Event)
|
|
|
|
{
|
|
|
|
if (Event->schedule == this) {
|
2006-10-28 09:16:24 +02:00
|
|
|
if (hasRunning && Event->IsRunning())
|
|
|
|
ClrRunningStatus();
|
2005-05-28 13:17:20 +02:00
|
|
|
UnhashEvent(Event);
|
|
|
|
events.Del(Event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSchedule::HashEvent(cEvent *Event)
|
|
|
|
{
|
|
|
|
eventsHashID.Add(Event, Event->EventID());
|
2005-05-29 10:26:54 +02:00
|
|
|
if (Event->StartTime() > 0) // 'StartTime < 0' is apparently used with NVOD channels
|
|
|
|
eventsHashStartTime.Add(Event, Event->StartTime());
|
2005-05-28 13:17:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cSchedule::UnhashEvent(cEvent *Event)
|
|
|
|
{
|
|
|
|
eventsHashID.Del(Event, Event->EventID());
|
2005-05-29 10:26:54 +02:00
|
|
|
if (Event->StartTime() > 0) // 'StartTime < 0' is apparently used with NVOD channels
|
|
|
|
eventsHashStartTime.Del(Event, Event->StartTime());
|
2005-05-28 13:17:20 +02:00
|
|
|
}
|
|
|
|
|
2006-01-29 14:04:37 +01:00
|
|
|
const cEvent *cSchedule::GetPresentEvent(void) const
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
|
|
|
const cEvent *pe = NULL;
|
|
|
|
time_t now = time(NULL);
|
|
|
|
for (cEvent *p = events.First(); p; p = events.Next(p)) {
|
2006-03-25 11:43:05 +01:00
|
|
|
if (p->StartTime() <= now)
|
2003-12-22 13:29:24 +01:00
|
|
|
pe = p;
|
2006-03-25 11:43:05 +01:00
|
|
|
else if (p->StartTime() > now + 3600)
|
|
|
|
break;
|
2006-01-29 14:04:37 +01:00
|
|
|
if (p->SeenWithin(RUNNINGSTATUSTIMEOUT) && p->RunningStatus() >= SI::RunningStatusPausing)
|
2004-02-21 14:52:37 +01:00
|
|
|
return p;
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
2006-01-29 14:04:37 +01:00
|
|
|
const cEvent *cSchedule::GetFollowingEvent(void) const
|
2004-02-21 14:52:37 +01:00
|
|
|
{
|
2006-01-29 14:04:37 +01:00
|
|
|
const cEvent *p = GetPresentEvent();
|
2004-02-21 14:52:37 +01:00
|
|
|
if (p)
|
|
|
|
p = events.Next(p);
|
2006-04-17 12:19:31 +02:00
|
|
|
else {
|
2006-02-26 15:10:02 +01:00
|
|
|
time_t now = time(NULL);
|
|
|
|
for (p = events.First(); p; p = events.Next(p)) {
|
|
|
|
if (p->StartTime() >= now)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-02-21 14:52:37 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2006-02-26 14:13:30 +01:00
|
|
|
const cEvent *cSchedule::GetEvent(tEventID EventID, time_t StartTime) const
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
2006-05-12 13:28:22 +02:00
|
|
|
// Returns the event info with the given StartTime or, if no actual StartTime
|
|
|
|
// is given, the one with the given EventID.
|
|
|
|
if (StartTime > 0) // 'StartTime < 0' is apparently used with NVOD channels
|
|
|
|
return eventsHashStartTime.Get(StartTime);
|
|
|
|
else
|
|
|
|
return eventsHashID.Get(EventID);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const cEvent *cSchedule::GetEventAround(time_t Time) const
|
|
|
|
{
|
|
|
|
const cEvent *pe = NULL;
|
|
|
|
time_t delta = INT_MAX;
|
|
|
|
for (cEvent *p = events.First(); p; p = events.Next(p)) {
|
|
|
|
time_t dt = Time - p->StartTime();
|
2004-03-06 11:27:08 +01:00
|
|
|
if (dt >= 0 && dt < delta && p->EndTime() >= Time) {
|
2003-12-22 13:29:24 +01:00
|
|
|
delta = dt;
|
|
|
|
pe = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
2004-03-06 14:33:22 +01:00
|
|
|
void cSchedule::SetRunningStatus(cEvent *Event, int RunningStatus, cChannel *Channel)
|
2004-02-21 12:28:17 +01:00
|
|
|
{
|
2006-08-05 10:15:34 +02:00
|
|
|
hasRunning = false;
|
2004-02-21 12:28:17 +01:00
|
|
|
for (cEvent *p = events.First(); p; p = events.Next(p)) {
|
2006-03-26 13:53:58 +02:00
|
|
|
if (p == Event) {
|
2006-10-28 09:16:24 +02:00
|
|
|
if (p->RunningStatus() > SI::RunningStatusNotRunning || RunningStatus > SI::RunningStatusNotRunning) {
|
2006-03-26 13:53:58 +02:00
|
|
|
p->SetRunningStatus(RunningStatus, Channel);
|
2006-10-28 09:16:24 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-03-26 13:53:58 +02:00
|
|
|
}
|
|
|
|
else if (RunningStatus >= SI::RunningStatusPausing && p->StartTime() < Event->StartTime())
|
2004-02-21 12:28:17 +01:00
|
|
|
p->SetRunningStatus(SI::RunningStatusNotRunning);
|
2006-08-05 10:15:34 +02:00
|
|
|
if (p->RunningStatus() >= SI::RunningStatusPausing)
|
|
|
|
hasRunning = true;
|
2004-02-21 12:28:17 +01:00
|
|
|
}
|
2004-03-13 15:01:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cSchedule::ClrRunningStatus(cChannel *Channel)
|
|
|
|
{
|
|
|
|
if (hasRunning) {
|
|
|
|
for (cEvent *p = events.First(); p; p = events.Next(p)) {
|
|
|
|
if (p->RunningStatus() >= SI::RunningStatusPausing) {
|
|
|
|
p->SetRunningStatus(SI::RunningStatusNotRunning, Channel);
|
|
|
|
hasRunning = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-02-21 12:28:17 +01:00
|
|
|
}
|
|
|
|
|
2004-01-09 15:53:59 +01:00
|
|
|
void cSchedule::ResetVersions(void)
|
|
|
|
{
|
|
|
|
for (cEvent *p = events.First(); p; p = events.Next(p))
|
|
|
|
p->SetVersion(0xFF);
|
|
|
|
}
|
|
|
|
|
2004-02-21 13:56:20 +01:00
|
|
|
void cSchedule::Sort(void)
|
|
|
|
{
|
|
|
|
events.Sort();
|
2006-07-22 09:20:32 +02:00
|
|
|
// Make sure there are no RunningStatusUndefined before the currently running event:
|
|
|
|
if (hasRunning) {
|
|
|
|
for (cEvent *p = events.First(); p; p = events.Next(p)) {
|
2006-08-05 10:15:34 +02:00
|
|
|
if (p->RunningStatus() >= SI::RunningStatusPausing)
|
2006-07-22 09:20:32 +02:00
|
|
|
break;
|
|
|
|
p->SetRunningStatus(SI::RunningStatusNotRunning);
|
|
|
|
}
|
|
|
|
}
|
2004-02-21 13:56:20 +01:00
|
|
|
}
|
|
|
|
|
2005-12-26 14:44:28 +01:00
|
|
|
void cSchedule::DropOutdated(time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version)
|
|
|
|
{
|
|
|
|
if (SegmentStart > 0 && SegmentEnd > 0) {
|
|
|
|
for (cEvent *p = events.First(); p; p = events.Next(p)) {
|
2005-12-27 10:26:38 +01:00
|
|
|
if (p->EndTime() > SegmentStart) {
|
|
|
|
if (p->StartTime() < SegmentEnd) {
|
|
|
|
// The event overlaps with the given time segment.
|
|
|
|
if (p->TableID() > TableID || p->TableID() == TableID && p->Version() != Version) {
|
|
|
|
// The segment overwrites all events from tables with higher ids, and
|
|
|
|
// within the same table id all events must have the same version.
|
|
|
|
// We can't delete the event right here because a timer might have
|
|
|
|
// a pointer to it, so let's set its id and start time to 0 to have it
|
|
|
|
// "phased out":
|
2006-10-28 09:16:24 +02:00
|
|
|
if (hasRunning && p->IsRunning())
|
|
|
|
ClrRunningStatus();
|
2005-12-27 10:26:38 +01:00
|
|
|
UnhashEvent(p);
|
|
|
|
p->eventID = 0;
|
|
|
|
p->startTime = 0;
|
|
|
|
}
|
2005-12-26 14:44:28 +01:00
|
|
|
}
|
2005-12-27 10:26:38 +01:00
|
|
|
else
|
|
|
|
break;
|
2005-12-26 14:44:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
void cSchedule::Cleanup(void)
|
|
|
|
{
|
|
|
|
Cleanup(time(NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSchedule::Cleanup(time_t Time)
|
|
|
|
{
|
|
|
|
cEvent *Event;
|
2005-12-26 15:09:21 +01:00
|
|
|
while ((Event = events.First()) != NULL) {
|
|
|
|
if (!Event->HasTimer() && Event->EndTime() + Setup.EPGLinger * 60 + 3600 < Time) // adding one hour for safety
|
|
|
|
DelEvent(Event);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
2004-02-22 15:36:36 +01:00
|
|
|
void cSchedule::Dump(FILE *f, const char *Prefix, eDumpMode DumpMode, time_t AtTime) const
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
|
|
|
cChannel *channel = Channels.GetByChannelID(channelID, true);
|
|
|
|
if (channel) {
|
2004-12-26 12:45:22 +01:00
|
|
|
fprintf(f, "%sC %s %s\n", Prefix, *channel->GetChannelID().ToString(), channel->Name());
|
2004-02-22 15:36:36 +01:00
|
|
|
const cEvent *p;
|
|
|
|
switch (DumpMode) {
|
|
|
|
case dmAll: {
|
|
|
|
for (p = events.First(); p; p = events.Next(p))
|
|
|
|
p->Dump(f, Prefix);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dmPresent: {
|
|
|
|
if ((p = GetPresentEvent()) != NULL)
|
|
|
|
p->Dump(f, Prefix);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dmFollowing: {
|
|
|
|
if ((p = GetFollowingEvent()) != NULL)
|
|
|
|
p->Dump(f, Prefix);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dmAtTime: {
|
|
|
|
if ((p = GetEventAround(AtTime)) != NULL)
|
|
|
|
p->Dump(f, Prefix);
|
|
|
|
}
|
|
|
|
break;
|
2009-12-06 12:57:45 +01:00
|
|
|
default: esyslog("ERROR: unknown DumpMode %d (%s %d)", DumpMode, __FUNCTION__, __LINE__);
|
2004-02-22 15:36:36 +01:00
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
fprintf(f, "%sc\n", Prefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cSchedule::Read(FILE *f, cSchedules *Schedules)
|
|
|
|
{
|
|
|
|
if (Schedules) {
|
2004-12-26 12:45:22 +01:00
|
|
|
cReadLine ReadLine;
|
2003-12-22 13:29:24 +01:00
|
|
|
char *s;
|
2004-12-26 12:45:22 +01:00
|
|
|
while ((s = ReadLine.Read(f)) != NULL) {
|
2003-12-22 13:29:24 +01:00
|
|
|
if (*s == 'C') {
|
|
|
|
s = skipspace(s + 1);
|
|
|
|
char *p = strchr(s, ' ');
|
|
|
|
if (p)
|
|
|
|
*p = 0; // strips optional channel name
|
|
|
|
if (*s) {
|
|
|
|
tChannelID channelID = tChannelID::FromString(s);
|
|
|
|
if (channelID.Valid()) {
|
|
|
|
cSchedule *p = Schedules->AddSchedule(channelID);
|
|
|
|
if (p) {
|
|
|
|
if (!cEvent::Read(f, p))
|
|
|
|
return false;
|
2004-02-21 13:56:20 +01:00
|
|
|
p->Sort();
|
2004-10-24 15:01:50 +02:00
|
|
|
Schedules->SetModified(p);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2005-12-30 15:43:21 +01:00
|
|
|
esyslog("ERROR: invalid channel ID: %s", s);
|
2003-12-22 13:29:24 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
esyslog("ERROR: unexpected tag while reading EPG data: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-24 13:41:54 +02:00
|
|
|
// --- cEpgDataWriter ---------------------------------------------------------
|
|
|
|
|
|
|
|
class cEpgDataWriter : public cThread {
|
2012-09-29 11:49:11 +02:00
|
|
|
private:
|
|
|
|
cMutex mutex;
|
2012-09-24 13:41:54 +02:00
|
|
|
protected:
|
|
|
|
virtual void Action(void);
|
|
|
|
public:
|
|
|
|
cEpgDataWriter(void);
|
|
|
|
void Perform(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
cEpgDataWriter::cEpgDataWriter(void)
|
|
|
|
:cThread("epg data writer")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgDataWriter::Action(void)
|
|
|
|
{
|
|
|
|
SetPriority(19);
|
|
|
|
SetIOPriority(7);
|
|
|
|
Perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgDataWriter::Perform(void)
|
|
|
|
{
|
2012-09-29 11:49:11 +02:00
|
|
|
cMutexLock MutexLock(&mutex); // to make sure fore- and background calls don't cause parellel dumps!
|
2012-09-24 13:41:54 +02:00
|
|
|
{
|
|
|
|
cSchedulesLock SchedulesLock(true, 1000);
|
|
|
|
cSchedules *s = (cSchedules *)cSchedules::Schedules(SchedulesLock);
|
|
|
|
if (s) {
|
|
|
|
time_t now = time(NULL);
|
|
|
|
for (cSchedule *p = s->First(); p; p = s->Next(p))
|
|
|
|
p->Cleanup(now);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cSchedules::Dump();
|
|
|
|
}
|
|
|
|
|
|
|
|
static cEpgDataWriter EpgDataWriter;
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
// --- cSchedulesLock --------------------------------------------------------
|
|
|
|
|
|
|
|
cSchedulesLock::cSchedulesLock(bool WriteLock, int TimeoutMs)
|
|
|
|
{
|
|
|
|
locked = cSchedules::schedules.rwlock.Lock(WriteLock, TimeoutMs);
|
|
|
|
}
|
|
|
|
|
|
|
|
cSchedulesLock::~cSchedulesLock()
|
|
|
|
{
|
|
|
|
if (locked)
|
|
|
|
cSchedules::schedules.rwlock.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cSchedules ------------------------------------------------------------
|
|
|
|
|
|
|
|
cSchedules cSchedules::schedules;
|
2012-05-13 13:46:56 +02:00
|
|
|
char *cSchedules::epgDataFileName = NULL;
|
2003-12-22 13:29:24 +01:00
|
|
|
time_t cSchedules::lastDump = time(NULL);
|
2004-10-24 15:01:50 +02:00
|
|
|
time_t cSchedules::modified = 0;
|
2003-12-22 13:29:24 +01:00
|
|
|
|
|
|
|
const cSchedules *cSchedules::Schedules(cSchedulesLock &SchedulesLock)
|
|
|
|
{
|
|
|
|
return SchedulesLock.Locked() ? &schedules : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSchedules::SetEpgDataFileName(const char *FileName)
|
|
|
|
{
|
2012-05-13 13:46:56 +02:00
|
|
|
free(epgDataFileName);
|
2004-12-26 12:45:22 +01:00
|
|
|
epgDataFileName = FileName ? strdup(FileName) : NULL;
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
2004-10-24 15:01:50 +02:00
|
|
|
void cSchedules::SetModified(cSchedule *Schedule)
|
|
|
|
{
|
|
|
|
Schedule->SetModified();
|
|
|
|
modified = time(NULL);
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
void cSchedules::Cleanup(bool Force)
|
|
|
|
{
|
|
|
|
if (Force)
|
|
|
|
lastDump = 0;
|
|
|
|
time_t now = time(NULL);
|
2012-09-24 13:41:54 +02:00
|
|
|
if (now - lastDump > EPGDATAWRITEDELTA) {
|
|
|
|
if (epgDataFileName) {
|
|
|
|
if (Force)
|
|
|
|
EpgDataWriter.Perform();
|
|
|
|
else if (!EpgDataWriter.Active())
|
|
|
|
EpgDataWriter.Start();
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
lastDump = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-09 15:53:59 +01:00
|
|
|
void cSchedules::ResetVersions(void)
|
|
|
|
{
|
|
|
|
cSchedulesLock SchedulesLock(true);
|
|
|
|
cSchedules *s = (cSchedules *)Schedules(SchedulesLock);
|
|
|
|
if (s) {
|
|
|
|
for (cSchedule *Schedule = s->First(); Schedule; Schedule = s->Next(Schedule))
|
|
|
|
Schedule->ResetVersions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
bool cSchedules::ClearAll(void)
|
|
|
|
{
|
|
|
|
cSchedulesLock SchedulesLock(true, 1000);
|
|
|
|
cSchedules *s = (cSchedules *)Schedules(SchedulesLock);
|
|
|
|
if (s) {
|
2006-01-20 13:42:38 +01:00
|
|
|
for (cTimer *Timer = Timers.First(); Timer; Timer = Timers.Next(Timer))
|
|
|
|
Timer->SetEvent(NULL);
|
|
|
|
for (cSchedule *Schedule = s->First(); Schedule; Schedule = s->Next(Schedule))
|
|
|
|
Schedule->Cleanup(INT_MAX);
|
2003-12-22 13:29:24 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-02-22 15:36:36 +01:00
|
|
|
bool cSchedules::Dump(FILE *f, const char *Prefix, eDumpMode DumpMode, time_t AtTime)
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
|
|
|
cSchedulesLock SchedulesLock;
|
|
|
|
cSchedules *s = (cSchedules *)Schedules(SchedulesLock);
|
|
|
|
if (s) {
|
2012-09-24 13:41:54 +02:00
|
|
|
cSafeFile *sf = NULL;
|
|
|
|
if (!f) {
|
|
|
|
sf = new cSafeFile(epgDataFileName);
|
|
|
|
if (sf->Open())
|
|
|
|
f = *sf;
|
|
|
|
else {
|
|
|
|
LOG_ERROR;
|
|
|
|
delete sf;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
for (cSchedule *p = s->First(); p; p = s->Next(p))
|
2004-02-22 15:36:36 +01:00
|
|
|
p->Dump(f, Prefix, DumpMode, AtTime);
|
2012-09-24 13:41:54 +02:00
|
|
|
if (sf) {
|
|
|
|
sf->Close();
|
|
|
|
delete sf;
|
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cSchedules::Read(FILE *f)
|
|
|
|
{
|
|
|
|
cSchedulesLock SchedulesLock(true, 1000);
|
|
|
|
cSchedules *s = (cSchedules *)Schedules(SchedulesLock);
|
|
|
|
if (s) {
|
|
|
|
bool OwnFile = f == NULL;
|
|
|
|
if (OwnFile) {
|
|
|
|
if (epgDataFileName && access(epgDataFileName, R_OK) == 0) {
|
|
|
|
dsyslog("reading EPG data from %s", epgDataFileName);
|
|
|
|
if ((f = fopen(epgDataFileName, "r")) == NULL) {
|
|
|
|
LOG_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool result = cSchedule::Read(f, s);
|
|
|
|
if (OwnFile)
|
|
|
|
fclose(f);
|
2006-01-29 14:17:33 +01:00
|
|
|
if (result) {
|
|
|
|
// Initialize the channels' schedule pointers, so that the first WhatsOn menu will come up faster:
|
|
|
|
for (cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel))
|
|
|
|
s->GetSchedule(Channel);
|
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cSchedule *cSchedules::AddSchedule(tChannelID ChannelID)
|
|
|
|
{
|
|
|
|
ChannelID.ClrRid();
|
|
|
|
cSchedule *p = (cSchedule *)GetSchedule(ChannelID);
|
|
|
|
if (!p) {
|
|
|
|
p = new cSchedule(ChannelID);
|
|
|
|
Add(p);
|
2006-07-29 09:40:41 +02:00
|
|
|
cChannel *channel = Channels.GetByChannelID(ChannelID);
|
|
|
|
if (channel)
|
|
|
|
channel->schedule = p;
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
const cSchedule *cSchedules::GetSchedule(tChannelID ChannelID) const
|
|
|
|
{
|
|
|
|
ChannelID.ClrRid();
|
|
|
|
for (cSchedule *p = First(); p; p = Next(p)) {
|
|
|
|
if (p->ChannelID() == ChannelID)
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-14 15:52:40 +01:00
|
|
|
const cSchedule *cSchedules::GetSchedule(const cChannel *Channel, bool AddIfMissing) const
|
|
|
|
{
|
|
|
|
// This is not very beautiful, but it dramatically speeds up the
|
|
|
|
// "What's on now/next?" menus.
|
|
|
|
static cSchedule DummySchedule(tChannelID::InvalidID);
|
|
|
|
if (!Channel->schedule)
|
|
|
|
Channel->schedule = GetSchedule(Channel->GetChannelID());
|
|
|
|
if (!Channel->schedule)
|
|
|
|
Channel->schedule = &DummySchedule;
|
|
|
|
if (Channel->schedule == &DummySchedule && AddIfMissing) {
|
|
|
|
cSchedule *Schedule = new cSchedule(Channel->GetChannelID());
|
|
|
|
((cSchedules *)this)->Add(Schedule);
|
|
|
|
Channel->schedule = Schedule;
|
|
|
|
}
|
|
|
|
return Channel->schedule != &DummySchedule? Channel->schedule : NULL;
|
|
|
|
}
|
2012-02-11 13:41:29 +01:00
|
|
|
|
|
|
|
// --- cEpgDataReader --------------------------------------------------------
|
|
|
|
|
|
|
|
cEpgDataReader::cEpgDataReader(void)
|
|
|
|
:cThread("epg data reader")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgDataReader::Action(void)
|
|
|
|
{
|
|
|
|
cSchedules::Read();
|
|
|
|
}
|
2012-03-10 15:10:43 +01:00
|
|
|
|
|
|
|
// --- cEpgHandler -----------------------------------------------------------
|
|
|
|
|
|
|
|
cEpgHandler::cEpgHandler(void)
|
|
|
|
{
|
|
|
|
EpgHandlers.Add(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
cEpgHandler::~cEpgHandler()
|
|
|
|
{
|
|
|
|
EpgHandlers.Del(this, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cEpgHandlers ----------------------------------------------------------
|
|
|
|
|
|
|
|
cEpgHandlers EpgHandlers;
|
|
|
|
|
|
|
|
bool cEpgHandlers::IgnoreChannel(const cChannel *Channel)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->IgnoreChannel(Channel))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cEpgHandlers::HandleEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->HandleEitEvent(Schedule, EitEvent, TableID, Version))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-04 10:19:23 +02:00
|
|
|
bool cEpgHandlers::HandledExternally(const cChannel *Channel)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->HandledExternally(Channel))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-25 11:31:35 +02:00
|
|
|
bool cEpgHandlers::IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->IsUpdate(EventID, StartTime, TableID, Version))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-10 15:10:43 +01:00
|
|
|
void cEpgHandlers::SetEventID(cEvent *Event, tEventID EventID)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetEventID(Event, EventID))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetEventID(EventID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::SetTitle(cEvent *Event, const char *Title)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetTitle(Event, Title))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetTitle(Title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::SetShortText(cEvent *Event, const char *ShortText)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetShortText(Event, ShortText))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetShortText(ShortText);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::SetDescription(cEvent *Event, const char *Description)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetDescription(Event, Description))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetDescription(Description);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::SetContents(cEvent *Event, uchar *Contents)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetContents(Event, Contents))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetContents(Contents);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::SetParentalRating(cEvent *Event, int ParentalRating)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetParentalRating(Event, ParentalRating))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetParentalRating(ParentalRating);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::SetStartTime(cEvent *Event, time_t StartTime)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetStartTime(Event, StartTime))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetStartTime(StartTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::SetDuration(cEvent *Event, int Duration)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetDuration(Event, Duration))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetDuration(Duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::SetVps(cEvent *Event, time_t Vps)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetVps(Event, Vps))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetVps(Vps);
|
|
|
|
}
|
|
|
|
|
2012-06-04 10:29:19 +02:00
|
|
|
void cEpgHandlers::SetComponents(cEvent *Event, cComponents *Components)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SetComponents(Event, Components))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->SetComponents(Components);
|
|
|
|
}
|
|
|
|
|
2012-03-10 15:10:43 +01:00
|
|
|
void cEpgHandlers::FixEpgBugs(cEvent *Event)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->FixEpgBugs(Event))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event->FixEpgBugs();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::HandleEvent(cEvent *Event)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->HandleEvent(Event))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::SortSchedule(cSchedule *Schedule)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->SortSchedule(Schedule))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Schedule->Sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEpgHandlers::DropOutdated(cSchedule *Schedule, time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version)
|
|
|
|
{
|
|
|
|
for (cEpgHandler *eh = First(); eh; eh = Next(eh)) {
|
|
|
|
if (eh->DropOutdated(Schedule, SegmentStart, SegmentEnd, TableID, Version))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Schedule->DropOutdated(SegmentStart, SegmentEnd, TableID, Version);
|
|
|
|
}
|