Skip to content
Permalink
Browse files

implementation for daemon with recording and epg finished

  • Loading branch information...
jankammerath committed Jan 13, 2018
1 parent 579f6c9 commit 5105484eaebc5ce386433d483974f121e8d5c8e7
Showing with 80 additions and 8 deletions.
  1. BIN bin/iptvx
  2. BIN data/db
  3. +60 −3 src/daemon.c
  4. +14 −5 src/db.c
  5. +3 −0 src/epg.c
  6. +3 −0 src/recording.h
BIN +752 Bytes (100%) bin/iptvx
Binary file not shown.
BIN +4 KB (120%) data/db 100644 → 100755
Binary file not shown.
@@ -149,6 +149,8 @@ GString* iptvx_daemon_get_recordlist_json(){
json_object* j_rec = json_object_new_object();
json_object_object_add(j_rec,"channel",
json_object_new_string(rec->channel->str));
json_object_object_add(j_rec,"title",
json_object_new_string(rec->title->str));
json_object_object_add(j_rec,"filename",
json_object_new_string(rec->filename->str));
json_object_object_add(j_rec,"start",
@@ -237,20 +239,65 @@ GString* iptvx_daemon_get_filename(recording rec){
/* generate the date for the filename */
time_t starttime_struct = rec.start;
char startdate_text[50];
strftime(startdate_text, 50, "%Y-%m-%d_%H:%M:%S",
strftime(startdate_text, 50, "%Y-%m-%d %H:%M:%S",
gmtime(&(starttime_struct)));

/* generate the filename */
char filename[265];
sprintf(filename,"%s/%s_%s.ts",record_dir->str,
startdate_text,rec.channel->str);
sprintf(filename,"%s/%s %s - %s.ts",record_dir->str,
startdate_text,rec.channel->str,rec.title->str);

/* push filename into result */
result = g_string_new(filename);

return result;
}

/*
Gets the title for a specific recording by checking the epg data
@param rec recording to get title for
@return a string with the title of the show
*/
GString* iptvx_daemon_get_recording_title(recording* rec){
/* the default title, if no programme can be found, is 'Live' */
GString* result = g_string_new("Live");

if(iptvx_daemon_epg_data != NULL){
int c = 0;
long max_prog_len = 0;
for(c = 0; c < iptvx_daemon_epg_data->len; c++){
channel* chan = &g_array_index(iptvx_daemon_epg_data,channel,c);

/* check if this is the recording's channel */
if(g_strcmp0(chan->name->str,rec->channel->str) == 0){
/* Check which programme matches the recording schedule.
If there are multiple programmes during the recording
period than the programme with the longest duration during
the recording period will represent the recording */
if(chan->programmeList != NULL){
int p = 0;
for(p = 0; p < chan->programmeList->len; p++){
programme* prog = &g_array_index(chan->programmeList,programme,p);

/* calculate the duration of the programme */
long prog_len = prog->stop - prog->start;

if(prog->start >= rec->start && prog->stop <= rec->stop && prog_len > max_prog_len){
/* this programme runs during the recording */
result = g_string_new(prog->title->str);

/* increase the max len */
max_prog_len = prog_len;
}
}
}
}
}
}

return result;
}

/*
Creates a new recording struct from given data
@param channel name of channel to record
@@ -269,6 +316,9 @@ recording iptvx_daemon_create_recording(char* channel, long start, long stop){
result.filesize = 0;
result.tolerance = iptvx_daemon_record_tolerance*60;

/* generate the title for this recording */
result.title = iptvx_daemon_get_recording_title(&result);

/* generate the filename for this recording */
result.filename = iptvx_daemon_get_filename(result);

@@ -570,6 +620,13 @@ void iptvx_daemon_init_recordlist(){
}
}

/*
Updates epg if necessary
*/
void iptvx_daemon_check_epg_update(){

}

/*
Runs the daemon loop, checks for signals
and performs the necessary operations.
@@ -209,8 +209,16 @@ void iptvx_db_insert_channel(channel* chan){
if(channel_exists == false){
char* errmsg;
char* insert_sql = sqlite3_mprintf("INSERT INTO channel "
"(channelname) VALUES ('%q')" ,chan->name->str);
"(channelname, channelepgupdated) "
"VALUES ('%q',%lld)", chan->name->str, chan->lastUpdated);
sqlite3_exec(db,insert_sql,NULL,NULL,&errmsg);
}else{
/* update when channel already exists */
char* update_sql = sqlite3_mprintf("UPDATE channel "
"SET channelepgupdated = %lld "
"WHERE channelname = '%q'",
chan->lastUpdated, chan->name->str);
sqlite3_exec(db,update_sql,NULL,NULL,NULL);
}

/* get the id of the channel */
@@ -289,9 +297,9 @@ void iptvx_db_insert_recording(recording* rec){
/* insert the recording into the database */
long channelid = iptvx_db_get_channel_id(rec->channel->str);
char* insert_sql = sqlite3_mprintf("INSERT INTO record "
"(recordstart, recordstop, recordchannelid) "
"VALUES (%lld, %lld, %lld)" ,
rec->start,rec->stop,channelid);
"(recordstart, recordstop, recordchannelid, recordtitle) "
"VALUES (%lld, %lld, %lld, '%q')" ,
rec->start,rec->stop,channelid,rec->title->str);
sqlite3_exec(db,insert_sql,NULL,NULL,NULL);
}
}
@@ -316,7 +324,7 @@ GArray* iptvx_db_get_recording_list(){
GArray* result = g_array_new(false,false,sizeof(recording));

char* get_recording_sql = "SELECT c.channelname, r.recordstart, "
"r.recordstop FROM record r, channel c "
"r.recordstop, r.recordtitle FROM record r, channel c "
"WHERE c.channelid = r.recordchannelid";

sqlite3_stmt *getrec_stmt;
@@ -326,6 +334,7 @@ GArray* iptvx_db_get_recording_list(){
rec.channel = g_string_new(sqlite3_column_text(getrec_stmt,0));
rec.start = sqlite3_column_int64(getrec_stmt,1);
rec.stop = sqlite3_column_int64(getrec_stmt,2);
rec.title = g_string_new(sqlite3_column_text(getrec_stmt,3));
g_array_append_val(result,rec);
}

@@ -612,6 +612,9 @@ void iptvx_epg_load_channel(channel* current, time_t epg_time, bool overwrite_ca
}
}

/* update the channel last updated value with the current time */
current->lastUpdated = (long)time(NULL);

/* free the temporary programme array */
g_array_free(plist,true);

@@ -28,6 +28,9 @@ struct recording{
/* the url of the channel */
GString* url;

/* title of the recording */
GString* title;

/* start and stop timings */
long start;
long stop;

0 comments on commit 5105484

Please sign in to comment.
You can’t perform that action at this time.