Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPG TitanNit #31

Open
sebstud opened this issue Jul 23, 2014 · 0 comments
Open

EPG TitanNit #31

sebstud opened this issue Jul 23, 2014 · 0 comments

Comments

@sebstud
Copy link

sebstud commented Jul 23, 2014

Thank You for great job. Is ther posibility to add to crossepg_dbconverter.c option to export the epg to the titan image format? Here is the structure description:
struct epg
{
int eventid;
int version;
time_t starttime;
time_t endtime;
char* title;
char* subtitle;
char* desc;
int desclen;
int desccomplen;
int parentalrating;
struct epg* prev;
struct epg* next;
};

if desccomplen > 0 then desc is gzip compressed

the function for reading epg.dat into mem

int readepg(const char* filename)
{
debug(1000, "in");
FILE fd = NULL;
struct channel *chnode = channel, *oldchnode = NULL;
struct epg
epgnode = NULL;
int ret = 0, len = 0, count = 0;
time_t epgmaxsec = status.epgdays * 24 * 60 * 60;

fd = fopen(filename, "rb");
if(fd == NULL)
{
perr("can't open %s", filename);
return 1;
}

m_lock(&status.epgmutex, 4);

while(!feof(fd))
{
int serviceid = 0, eventid = 0, version = 0;
uint64_t transponderid = 0;
time_t starttime = 0, endtime = 0;
int desclen = 0, desccomplen = 0, parentalrating = 0;
char* title = NULL, *subtitle = NULL, *desc = NULL;

ret = fread(&serviceid, sizeof(int), 1, fd);
if(feof(fd)) break;
ret = fread(&transponderid, sizeof(uint64_t), 1, fd);
ret = fread(&eventid, sizeof(int), 1, fd);
ret = fread(&version, sizeof(int), 1, fd);
ret = fread(&parentalrating, sizeof(int), 1, fd);
ret = fread(&starttime, sizeof(time_t), 1, fd);
ret = fread(&endtime, sizeof(time_t), 1, fd);

//if epg.dat has an IO Error it runs in endless loop
//this stops the endless loop
if(starttime == 0 && endtime == 0)
count++;
else
count = 0;
if(count > 50) break;

len = 0;
ret = fread(&len, sizeof(int), 1, fd);
if(len > 0 && len <= 4096)
{
title = malloc(len + 1);
if(title == NULL)
{
err("title no mem %d", len);
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
break;
}
ret = fread(title, len, 1, fd);
title[len] = '\0';
}
else if(len != 0)
{
err("epgfile defekt title len=%d", len);
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
break;
}

len = 0;
ret = fread(&len, sizeof(int), 1, fd);
if(len > 0 && len <= 4096)
{
subtitle = malloc(len + 1);
if(subtitle == NULL)
{
err("subtitle no mem %d", len);
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
break;
}
ret = fread(subtitle, len, 1, fd);
subtitle[len] = '\0';
}
else if(len != 0)
{
err("epgfile defekt subtitle len=%d", len);
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
break;
}

ret = fread(&desclen, sizeof(int), 1, fd);
ret = fread(&desccomplen, sizeof(int), 1, fd);

len = desccomplen;
if(len == 0)
len = desclen;
if(len > 0 && len <= 4096)
{
if(desccomplen == 0)
desc = malloc(len + 1);
else
desc = malloc(len);
if(desc == NULL)
{
err("desc no mem %d", len);
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
break;
}
ret = fread(desc, len, 1, fd);
if(desccomplen == 0)
desc[len] = '\0';
}
else if(len != 0)
{
err("epgfile defekt desc len=%d", len);
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
break;
}

if(oldchnode != NULL && oldchnode->serviceid == serviceid && oldchnode->transponderid == transponderid)
chnode = oldchnode;
else
{
chnode = getchannel(serviceid, transponderid);
if(chnode == NULL)
{
debug(1000, "out -> NULL detect");
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
continue;
}
oldchnode = chnode;
epgnode = NULL;
}

ifndef SIMULATE

if(endtime < time(NULL) || starttime > time(NULL) + epgmaxsec)
{
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
continue;
}

endif

epgnode = addepg(chnode, eventid, version, starttime, endtime, epgnode, 1);
if(epgnode == NULL)
{
debug(1000, "out -> NULL detect");
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
continue;
}
epgnode->parentalrating = parentalrating;
epgnode->desclen = desclen;
epgnode->desccomplen = desccomplen;
epgnode->title = title;
epgnode->subtitle = subtitle;
epgnode->desc = desc;
}

fclose(fd);

if(getconfigint("epg_del", NULL) == 1)
unlink(filename);

m_unlock(&status.epgmutex, 4);

//epg.dat seems defekt IO Error
if(count > 50) unlink(filename);

debug(1000, "out");
return 0;
}

And this is the code to read the epg.dat file to the memory:
chnode = getchannel(serviceid, transponderid);

  1. add the data to the epg linked list

epgnode = addepg(chnode, eventid, version, starttime, endtime, NULL, 1);
if(epgnode == NULL)
{
debug(1000, "out -> NULL detect");
free(title); title = NULL;
free(subtitle); subtitle = NULL;
free(desc); desc = NULL;
continue;
}
epgnode->parentalrating = parentalrating;
epgnode->desclen = desclen;
epgnode->desccomplen = desccomplen;
epgnode->title = title;
epgnode->subtitle = subtitle;
epgnode->desc = desc;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant