Code:
/**
** Add an entry to the EPG
**
** @param pChan Pointer to the entry in the channel list
** @param szStart The start time
** @param szStop The end time
** @param szTitle The program name
** @param szSubtitle The specific program
** @param szDesc A description of the program
**
** @return HX_STATUS - HX_OK if successful
**/
HX_STATUS addEPGEntry(struct channel_st *pChan, char *szStart, char *szStop,
char *szTitle, char *szSubtitle, char *szDesc) {
struct eit_info_st eitInfo; /* EPG info data */
/* Initialize */
bzero(&eitInfo, sizeof(struct eit_info_st));
/* Get the start time & duration */
eitInfo.start_time = formatDate(szStart);
eitInfo.duration = formatDate(szStop) - eitInfo.start_time;
/* Logging */
verbosedebugn(TEST_DBG_ID, "Entered addEPGEntry(%s, %s, %s, %s) - %s\n",
pChan->channel_name_list.name[0].data, szTitle, szStart, szStop,
ctime(&eitInfo.start_time));
/* We're only interested in the entries from Now until Then */
if (eitInfo.start_time < Then) { /* It can't be later than this! */
if (eitInfo.start_time + eitInfo.duration > Now) { /* And it can't be already over */
struct eit_info_st EpgList[256];
short epg_count;
eitInfo.net_index = pChan->net_index;
eitInfo.freq = pChan->freq;
eitInfo.polar = pChan->polarisation;
eitInfo.service_id = pChan->service_id;
eitInfo.net_id = pChan->original_network_id;
eitInfo.ts_id = pChan->ts_id;
eitInfo.event_id = EPGCount;
eitInfo.parental_rating = 12; /* If 18 causes password */
eitInfo.channel_index = pChan->user_ch_num;
stTVSDKChannelKey ChannelKey = TVSDK_MakeKeyByChannel(pChan);
epg_count = TVSDK_Geteit_info(&ChannelKey, eitInfo.start_time, (eitInfo.duration -300), EpgList);
// fprintf(stderr, "%s=> epg_count#%d(%d), ChannelKey: ni=%d, on_id=%d, ts_id=%d, freq=%ld, polar=%d, service_id=%d\n", pChan->channel_name_list.name[0].data, epg_count, EpgList[0].channel_index,
// ChannelKey.net_index, ChannelKey.net_id, ChannelKey.ts_id, ChannelKey.freq, ChannelKey.polar, ChannelKey.service_id );
if (epg_count == 0) {
/* Not strictly correct - it might not be English */
strcpy(eitInfo.event_lang,"eng");
/* Copy, but make sure there's no overflow */
if (szTitle && strlen(szTitle)) {
strncpy(eitInfo.event_name, szTitle, EIT_EVENT_NAME_LAN);
eitInfo.event_name[EIT_EVENT_NAME_LAN] = 0;
eitInfo.event_name_len = strlen(eitInfo.event_name);
}
if (szDesc && strlen(szDesc)) {
strncpy(eitInfo.event_text, szDesc,EIT_EVENT_TEXT_LAN);
eitInfo.event_text[EIT_EVENT_TEXT_LAN] = 0;
eitInfo.event_text_len = strlen(eitInfo.event_text);
}
// TODO : actually not used
strcpy(eitInfo.event_detail,"ED NU");
eitInfo.event_detail[maxTextLen] = 0;
eitInfo.event_detail_len = strlen(eitInfo.event_detail);
/*
* TODO
* uncomment when the means of eitInfo.event_text and eitInfo.event_detail will be cleared from Opensat!
if (szSubtitle && strlen(szSubtitle)) {
strncpy(eitInfo.event_text, szSubtitle, EIT_EVENT_TEXT_LAN);
eitInfo.event_text[EIT_EVENT_TEXT_LAN] = 0;
eitInfo.event_text_len = strlen(eitInfo.event_text);
}
if (szDesc && strlen(szDesc)) {
strncpy(eitInfo.event_detail, szDesc,maxTextLen);
eitInfo.event_detail[maxTextLen] = 0;
eitInfo.event_detail_len = strlen(eitInfo.event_detail);
}
*/
// fprintf(stderr, "Added#%d: %s, %s_%s %d_%s\n", EPGCount, pChan->channel_name_list.name[0].data, szStart, szStop, eitInfo.duration, ctime(&eitInfo.start_time));
/* Now add to the EPG */
addEITToTable(&eitInfo);
EPGCount++;
if (persistData && write(fdPersist, (void *) &eitInfo, sizeof(struct eit_info_st)) < 0) {
fprintf(stderr, "Error %d when writing to %s\n", errno, SAVED_DATA);
}
debugn(TEST_DBG_ID, "Added #%d: %s: %s, %s-%s (%s-%ld)\n", EPGCount, pChan->channel_name_list.name[0].data,
szTitle, szStart, szStop, ctime(&eitInfo.start_time), eitInfo.duration);
}
}
}
/* Logging */
verbosedebugn(TEST_DBG_ID, "Leaving addEPGEntry - %s\n", (EPGCount<maxEPGCount) ? "OK" : "ERROR");
return (EPGCount < maxEPGCount) ? HX_OK : HX_ERROR;
}
if I'm not mistaken in the last 2 firmware releases something has changed in view of the detailed description of events: it seems that following the recent EPG section changes, two fields have been reversed.
Code:
#!/bin/bash
# set -x # Uncomment for debugging
##################################################
# Messages from here - make it easier to translate
ERR_USAGE="Usage: $0 [-a] [-l] [-s YYMMDD] [-d 99] [-n 9999] [-o mmmm] [-p] [-t] [-m 9999]"
ERR_CHSEL="No channel selections specified"
ERR_SOURCE="Can't find the sources file - please specify a date"
ERR_BADSRC="The sources file is corrupt."
ERR_CHFILE="Can't find the 'rytec.channels.xml' file"
##################################################
# Usage:
# -a Automatically detect if the data are to be loaded
# -l Force download the data from rytec
# -m Maximum text length (default=4096)
# -s Specify the sources date (default = 20100319)
# -d Specify the number of days to load
# -h Specify the number of hours to load
# -n Specify the number of events to process
# -p Persist the EIT data in epgdata.dat
# -v Verbose output (for debugging)
# -o Time offset in minutes - no default.
# -t Specify daylight savings time
# -c Specify an user channels file ( -c ./channels.xml )
usage() {
echo $ERR_USAGE >&2
exit 1
}
##################################################
# Initialise the variables
LOAD=0 # Download data? Zero = NO
DAYS= # Number of days? Default = 2
NUM= # Number of events? Default = ALL in the time
DATA= # Persist the data? Default = NO
DATE=20100421 # Sources date in format YYYYMMDD
AUTO= # Don't automaticaly download
DEBUG= # Debugging? Default = NO
OFFSET= # Offset from UTC in minutes
DST= # Daylight savings time
MAXTEXT= # Maximum length of description
# Patterns to manage tests
PATDATE="201[0-9][01][0-9][0-3][0-9]"
# Process command-line arguments
until [ -z "$1" ]
do
if [ ${1:0:1} = '-' ]
then
case "${1:1}" in
"A" | "a" ) AUTO=1
;;
"L" | "l" ) LOAD=1
;;
"P" | "p" ) DATA="-p"
;;
"S" | "s" ) [ $# -gt 1 ] || usage
[ -z "${2#$PATDATE}" ] || usage
DATE=$2
shift
;;
"T" | "t" ) DST="-t"
;;
"D" | "d" ) [ $# -gt 1 ] || usage
[ $2 -gt 0 -a $2 -lt 8 ] || usage
DAYS="-d $2"
shift
;;
"M" | "m" ) [ $# -gt 1 ] || usage
MAXTEXT="-m $2"
shift
;;
"N" | "n" ) [ $# -gt 1 ] || usage
NUM="-n $2"
shift
;;
"O" | "o" ) [ $# -gt 1 ] || usage
OFFSET=$2
shift
;;
"V" | "v" ) DEBUG="-v -v -v"
;;
* ) usage
;;
esac
fi
shift
done
# Do we need to auto-download the data?
if [ $LOAD -eq 0 -a ! -z "$AUTO" ]
then
if [ ! -f epgdata.xml ]
then
LOAD=1
else
# Thanks to rcranium for a cleaner algorithm
nowSecs=`date +%s`
fileSecs=`date -r epgdata.xml +%s`
fileAgeSecs=`expr $nowSecs - $fileSecs`
fileAgeDays=`expr $fileAgeSecs / 86400`
if [ $fileAgeDays -gt 3 ]
then
date '+Loading xmltv - $fileAgeDays old'
LOAD=1
fi
fi
fi
date '+Start %c'
if [ $LOAD -gt 0 ]
then
#####################################################
# 1. Verify parameters in conf file
CONF_FILE=azepgmgr.conf
SATLIST=`sed -e "s/#.*$//" $CONF_FILE | grep -v "^[ ]*$"`
if [ -z "$SATLIST" ]
then
echo $CH_SEL >&2
exit 1
fi
#####################################################
# 2. Download the sources and channel information
RYT_URL=http://www.rytec.be/tools
RYT_SOURCES=rytec.sources.xml
RYT_CHANNELS=rytec.channels.xml
RYT_CHANNELS_ZIP=$RYT_CHANNELS.gz
if [ -z "$DATE" ]
then
# Extract the filename from the HTML
# - thanks to rcranium for the idea
RYT_SOURCES_ZIP=`wget -q -O - http://www.rytec.be/ \
| grep "Download : $RYT_SOURCES" \
| sed -e "s/^.*\($RYT_SOURCES\.[0-9]*\.zip\).*$/\1/"`
else
# Param = date in YYYYMMDD format
RYT_SOURCES_ZIP=$RYT_SOURCES.$DATE.zip
fi
if [ -z "$RYT_SOURCES_ZIP" ]
then
echo $ERR_SOURCE >&2
usage
fi
wget -q $RYT_URL/$RYT_SOURCES_ZIP
if [ ! -f $RYT_SOURCES_ZIP ]
then
echo $ERR_SOURCE >&2
usage
fi
unzip -q $RYT_SOURCES_ZIP
if [ ! -f $RYT_SOURCES ]
then
echo $ERR_BADSRC >&2
exit 1
fi
wget -q $RYT_URL/$RYT_CHANNELS_ZIP
if [ ! -f $RYT_CHANNELS_ZIP ]
then
echo $ERR_CHFILE >&2
exit 1
fi
gunzip $RYT_CHANNELS_ZIP
#####################################################
# 3. Extract the correct information from the sources
# and download the EPG data.
for SAT in $SATLIST
do
awk -v SAT=$SAT '
{
if ($0 ~/<description>/) {
DESC=substr($0, 21, length($0)-41);
gsub(/[ \t]/,"",DESC);
}
if ($0 ~/<url>/) {
URL=substr($0, 7, length($0)-13);
}
if (DESC == SAT && $0 ~ /<\/source>/) {
system( "wget -q " URL);
}
}' $RYT_SOURCES
done
#####################################################
# 4. Extract the xmltv file(s), and process the data
for F in rytecxmltv*.gz
do
gunzip -d $F
dos2unix `basename $F '.gz'`
done
##################################################################
# Extract the XML content into a single XML file
echo '<?xml version="1.0" encoding="UTF-8" ?>' >epgdata.xml
echo '<!DOCTYPE tv SYSTEM "xmltv.dtd">' ****epgdata.xml
echo '<tv generator-info-name="azepgmgr">' ****epgdata.xml
for F in rytecxmltv*
do
ENCODING=`head -1 $F | sed -e 's/^.*encoding="\([^"]*\).*$/\1/'`
iconv --from-code=$ENCODING --to-code=UTF-8 $F \
| grep -v "<?xml" \
| grep -v "<!DOCTYPE" \
| grep -v "<tv" \
| grep -v "</tv>" ****epgdata.xml
done
echo "</tv>" ****epgdata.xml
fi
############################################
# See if the offset & DST can be accessed from the system
if [ -z "$OFFSET" ]
then
OFFSET=`grep timezonegap /DISK2/selene.conf \
| sed -e "s/^ *timezonegap *= *//"`
fi
if [ -z "$DST" ]
then
DST=`grep time_daylight_saving_time /DISK2/selene.conf \
| sed -e "s/^[^=]*= *//"`
if [ "$DST" == "1" ]
then
DST="-t"
else
DST=
fi
fi
# We don't need to specify Offset and DST because values defined into xml rytec epgdata file are already updated!
OFFSET=0
DST=
#
# Process the XML files, only if the data file's missing
# or if it's older than the XML data.
date '+Start xml extract at %c'
LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
echo ./_azepgmgr $DST $DATA $DAYS $NUM $DEBUG -o $OFFSET $MAXTEXT
./_azepgmgr $DST $DATA $DAYS $NUM $DEBUG -o $OFFSET $MAXTEXT
date '+End xml extract at %c'
Bookmarks