Skip to content
Permalink
Browse files

implementing sqlite database for issue #62

  • Loading branch information...
jankammerath committed Dec 30, 2017
1 parent 96a19bc commit 337e07593cf6dc6023ca39912a765318590569b4
Showing with 165 additions and 6 deletions.
  1. +1 −1 Makefile
  2. BIN bin/iptvx
  3. +4 −0 cfg/iptvx.conf
  4. +1 −1 debian.control
  5. +1 −1 iptvx.dsc
  6. +2 −0 iptvx.spec
  7. +1 −1 src/args.c
  8. +106 −0 src/db.c
  9. +35 −0 src/db.h
  10. +14 −2 src/main.c
@@ -1,5 +1,5 @@
CC = gcc
CFLAGS = `pkg-config --cflags --libs glib-2.0 webkit2gtk-4.0 libconfig libmicrohttpd libvlc libcurl libxml-2.0 sdl SDL_image json-c`
CFLAGS = `pkg-config --cflags --libs sqlite3 glib-2.0 webkit2gtk-4.0 libconfig libmicrohttpd libvlc libcurl libxml-2.0 sdl SDL_image json-c`

# this makes the binary
all:
BIN +133 KB (270%) bin/iptvx
Binary file not shown.
@@ -5,6 +5,10 @@
app = "/var/iptvx/app/app.html"
data = "/var/iptvx/data"

# defines the path of the database
# file to store epg and recordings
db = "/var/iptvx/db"

# defines where recorded video should
# be stored on the local disk
record = "/var/iptvx/video"
@@ -1,7 +1,7 @@
Source: iptvx
Section: unknown
Maintainer: Jan Kammerath <dev@iptvx.org>
Build-Depends: debhelper (>= 9), pkg-config, gcc, cmake, libglib2.0-dev, libwebkit2gtk-4.0-dev, libconfig-dev, libvlc-dev, libcurl4-openssl-dev, libxml2-dev, libsdl1.2-dev, libsdl-image1.2-dev, libjson-c-dev, libmicrohttpd-dev
Build-Depends: debhelper (>= 9), pkg-config, gcc, cmake, libglib2.0-dev, libwebkit2gtk-4.0-dev, libconfig-dev, libvlc-dev, libcurl4-openssl-dev, libxml2-dev, libsdl1.2-dev, libsdl-image1.2-dev, libjson-c-dev, libmicrohttpd-dev, libsqlite3-dev

Package: iptvx
Architecture: any
@@ -5,6 +5,6 @@ Binary: iptvx
Maintainer: Jan Kammerath <jankammerath@gmail.com>
Homepage: http://iptvx.org
Architecture: any
Build-Depends: debhelper (>= 9), pkg-config, gcc, cmake, libglib2.0-dev, libwebkit2gtk-4.0-dev, libconfig-dev, libvlc-dev, libcurl4-openssl-dev, libxml2-dev, libsdl1.2-dev, libsdl-image1.2-dev, libjson-c-dev, libmicrohttpd-dev
Build-Depends: debhelper (>= 9), pkg-config, gcc, cmake, libglib2.0-dev, libwebkit2gtk-4.0-dev, libconfig-dev, libvlc-dev, libcurl4-openssl-dev, libxml2-dev, libsdl1.2-dev, libsdl-image1.2-dev, libjson-c-dev, libmicrohttpd-dev, libsqlite3-dev
Files:
279759717efddc76bbd2e8911cecba66 284683 %{name}-%{version}.tar.gz
@@ -34,6 +34,7 @@ BuildRequires: pkgconfig(sdl)
BuildRequires: pkgconfig(SDL_image)
BuildRequires: pkgconfig(json-c)
BuildRequires: pkgconfig(libmicrohttpd)
BuildRequires: pkgconfig(sqlite3)

# Runtime requirements
Requires: pkgconfig(glib-2.0)
@@ -46,6 +47,7 @@ Requires: pkgconfig(sdl)
Requires: pkgconfig(SDL_image)
Requires: pkgconfig(json-c)
Requires: pkgconfig(libmicrohttpd)
Requires: pkgconfig(sqlite3)

%description
IPTV player and streamer for Linux that allows to play any stream that LibVLC can play, offers an overlay based on WebKit using HTML5, JavaScript and CSS and uses XMLTV data for EPG information. It allows the playback of URLs, files and can grab URLs from shell scripts. XMLTV EPG data can be downloaded directly from URLs or grabbed from shell scripts.
@@ -19,7 +19,7 @@
#include <argp.h>
#include <stdbool.h>

const char *argp_program_version = "iptvx 0.5 beta";
const char *argp_program_version = "iptvx 0.6 beta";
const char *argp_program_bug_address = "<dev@iptvx.org>";
static char args_doc[] = "";
static char doc[] = "iptvx -- An IPTV player and recorder";
106 src/db.c
@@ -0,0 +1,106 @@
/*
Copyright 2018 Jan Kammerath
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <stdio.h>
#include <stdbool.h>
#include <sqlite3.h>
#include <glib.h>
#include "channel.h"

/* db handle */
sqlite3* db;

/*
Initialises and opens the database
@param filename file path of the db file
*/
void iptvx_db_init(char* filename){
/* open the application database */
int rc = sqlite3_open(filename, &db);

if(rc){
/* print an error message to stderr */
fprintf(stderr, "Database error: %s\n",
sqlite3_errmsg(db));
}
}

/*
Inserts a channel into the db if it doesn't exist
@param chan the channel struct
*/
void iptvx_db_insert_channel(channel* chan){
/* indicates whether channel exists or not */
bool channel_exists;

/* set to false by default */
channel_exists = false;

/* prepare the sql statement */
char* sql = sqlite3_mprintf("SELECT channelname FROM channel "
"WHERE channelname = '%q'",chan->name->str);

sqlite3_stmt *stmt;
sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
while (sqlite3_step(stmt) != SQLITE_DONE) {
int i;
int column_count = sqlite3_column_count(stmt);
for(i = 0; i < column_count; i++){
if(sqlite3_column_type(stmt, i) == SQLITE3_TEXT){
/* check if the column has the channel name */
if(g_strcmp0(sqlite3_column_text(stmt, i),chan->name->str)==0){
/* this means the channel is already there */
channel_exists = true;
}
}
}
}

/* insert if it doesn't exist */
if(channel_exists == false){
char* insert_sql = sqlite3_mprintf("INSERT INTO channel "
"(channelname) VALUES ('%q')" ,chan->name->str);
sqlite3_exec(db,insert_sql,NULL,NULL,NULL);
sqlite3_free(insert_sql);
}

/* finalise statement */
sqlite3_finalize(stmt);
sqlite3_free(sql);
}

/*
Updates the database with epg data
@param epg array with all epg data
*/
void iptvx_db_update(GArray* epg){
/* go through all channels and insert them
into the database if they do not already exist */
int c = 0;
for(c = 0; c < epg->len; c++){
/* get the channel from the list */
channel* chan = &g_array_index(epg,channel,c);
iptvx_db_insert_channel(chan);
}
}

/*
Closes the database
*/
void iptvx_db_close(){
sqlite3_close(db);
}
@@ -0,0 +1,35 @@
/*
Copyright 2018 Jan Kammerath
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <glib.h>

/*
Initialises and opens the database
@param filename file path of the db file
*/
void iptvx_db_init(char* filename);

/*
Updates the database with epg data
@param epg array with all epg data
*/
void iptvx_db_update(GArray* epg);

/*
Closes the database
*/
void iptvx_db_close();
@@ -33,6 +33,7 @@
#include "epg.h"
#include "keycode.h"
#include "daemon.h"
#include "db.h"

/* application status */
bool application_active;
@@ -217,11 +218,14 @@ void epg_status_update(void* progress){

/* mark ready when 100 percent reached */
if(progressVal == 100){
/* get the epg data and flush into db */
GArray* epg_data = iptvx_epg_get_data();
iptvx_db_update(epg_data);

/* check if daemon or client */
if(is_daemon){
/* is daemon, so send epg data in raw and as json */
GString* epg_data_json = iptvx_epg_get_json();
GArray* epg_data = iptvx_epg_get_data();
iptvx_daemon_set_epg_json(epg_data_json);
iptvx_daemon_set_epg_data(epg_data);
}else{
@@ -387,6 +391,10 @@ int main (int argc, char *argv[]){
main_window_ready = false;
main_epg_ready = false;

/* initialise the database */
char* db_file = iptvx_config_get_setting_string("db","/var/iptvx/db");
iptvx_db_init(db_file);

/* get the hours to store in the epg */
int epg_hours = iptvx_config_get_setting_int("epg_hours",48);
iptvx_epg_set_storage_hours(epg_hours);
@@ -417,12 +425,16 @@ int main (int argc, char *argv[]){
iptvx_daemon_set_dir(iptvx_config_get_setting_string
("record","/var/iptvx/video"));

/* daemon mode */
/* daemon mode execution which
will lock the thread */
iptvx_daemon_run();
}else{
/* window or client app mode */
start_window();
}

/* close the database when finished */
iptvx_db_close();
}else{
/* throw an error when config not initialised */
printf("Failed to initialise the configuration\n");

0 comments on commit 337e075

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