diff -Naur --exclude '*,v' tv_grab_dvb-0.9/langidents tv_grab_dvb-0.9.new/langidents --- tv_grab_dvb-0.9/langidents 1970-01-01 02:00:00.000000000 +0200 +++ tv_grab_dvb-0.9.new/langidents 2004-12-11 19:17:33.000000000 +0200 @@ -0,0 +1,3 @@ +fin fi +swe sv + diff -Naur --exclude '*,v' tv_grab_dvb-0.9/tv_grab_dvb.c tv_grab_dvb-0.9.new/tv_grab_dvb.c --- tv_grab_dvb-0.9/tv_grab_dvb.c 2004-09-07 22:11:13.000000000 +0300 +++ tv_grab_dvb-0.9.new/tv_grab_dvb.c 2004-12-15 13:28:56.000000000 +0200 @@ -26,7 +26,7 @@ */ -static char *id="@(#) $Id: tv_grab_dvb.c,v 1.10 2004/09/07 19:11:13 mhb Exp $"; +static char *id="@(#) $Id: tv_grab_dvb.c,v 1.6 2004/12/09 20:09:58 msuonio Exp msuonio $"; #include #include @@ -56,6 +56,7 @@ /* FIXME: put these as options */ #define CHANNELS_CONF "channels.conf" #define CHANIDENTS "chanidents" +#define LANGIDENTS "langidents" #define DEMUX "/dev/dvb/adapter0/demux0" char *ProgName; @@ -73,6 +74,7 @@ bool ignore_updates = true; bool use_chanidents = false; bool silent = false; +bool use_langidents = false; typedef struct chninfo { @@ -96,11 +98,12 @@ void usage() { - errmsg ("tv_grab_dvb - Version 0.9\n\n usage: %s [-d] [-u] [-c] [-n|m|p] [-s] [-t timeout] [-o offset] > dump.xmltv\n\n" + errmsg ("tv_grab_dvb - Version 0.9\n\n usage: %s [-d] [-u] [-c] [-l] [-n|m|p] [-s] [-t timeout] [-o offset] > dump.xmltv\n\n" "\t\t-t timeout - Stop after timeout seconds of no new data\n" "\t\t-o offset - time offset in hours from -12 to 12\n" "\t\t-c - Use Channel Identifiers from file 'chanidents'\n" "\t\t (rather than sidnumber.dvb.guide)\n" + "\t\t-l - convert language codes according to 'langidents'\n" "\t\t-d - output invalid dates\n" "\t\t-n - now next info only\n" "\t\t-m - current multiplex now_next only\n" @@ -129,7 +132,7 @@ int Option_Index = 0; while (1) { - c = getopt_long(arg_count, arg_strings, "udscmpnht:o:", Long_Options, &Option_Index); + c = getopt_long(arg_count, arg_strings, "udsclmpnht:o:", Long_Options, &Option_Index); if (c == EOF) break; switch (c) { @@ -156,6 +159,9 @@ case 'c': use_chanidents = true; break; + case 'l': + use_langidents = true; + break; case 'n': chan_filter=0x4e; chan_filter_mask=0xfe; @@ -206,6 +212,34 @@ } +char *get_languageident(char *lang3) { + static char lang2[256]; + char lang3match[256]; + FILE *fd_li; + char buf2[256]; + + lang3match[0]=0; + if (use_langidents) + { + fd_li = fopen(LANGIDENTS, "r"); + while (fgets(buf2,256,fd_li)) + { + sscanf(buf2,"%s %s",lang3match,lang2); + if (strncmp(lang3match,lang3,3) == 0) + break; + + } + fclose(fd_li); + } + if (strncmp(lang3match,lang3,3) != 0) + { + strncpy(lang2,lang3,3); + lang2[3]=0; + } + return lang2; +} + + /* Add text to the end of string, returning a pointer to the end of string */ /* Added by Nick Craig-Wood - nick craig-wood com */ @@ -264,7 +298,7 @@ return xml; } -void parseEventDescription(char *evtdesc) +void parseEventDescription(char *evtdesc, int title) { int evtlen,dsclen; char lang[3]; @@ -280,9 +314,13 @@ evt[evtlen]=0; dsc[dsclen]=0; - printf("\t%s\n",lang,xmlify(evt)); - if (*dsc) - printf("\t%s\n",lang,xmlify(dsc)); + if (title) + printf("\t%s\n", + get_languageident(lang),xmlify(evt)); + else + if (*dsc) + printf("\t%s\n", + get_languageident(lang),xmlify(dsc)); } @@ -376,50 +414,75 @@ void parseDescription(char *desc,int len) { - int i,round,tag,taglen,seen; - for (round=0;round<4;round++) + int i,tag,taglen,seen; + + // [title] + seen = 0; + for (i=0;i0) { - - tag=*(desc+i) &0xff; - taglen=*(desc+i+1) &0xff; - if (taglen>0) + switch (tag) { - switch (tag) - { - case 0: - break;; - case 0x4D: //short evt desc, [title] [desc] - if (round == 0) - parseEventDescription(desc+i); - break;; - case 0x4E: //long evt descriptor - if (round == 0) - printf("\t\n"); - break;; - case 0x50: //component desc [video] [audio] - if (round == 2) - parseComponentDescription(CastComponentDescriptor(desc+i), 1, &seen); - else if (round == 3) - parseComponentDescription(CastComponentDescriptor(desc+i), 0, &seen); - break;; - case 0x54: //content desc [category] - if (round == 1) - parseContentDescription(CastContentDescriptor(desc+i)); - break;; - case 0x64: //Data broadcast desc - Text Desc for Data components - break;; - default: - if (round == 0) - printf("\t\n",tag,taglen); - } + case 0: + break;; + case 0x4D: //short evt desc, [title] [desc] + seen = 1; + parseEventDescription(desc+i,1); + break;; + case 0x4E: //long evt descriptor + printf("\t\n"); + break;; + case 0x50: //component desc [video] [audio] + case 0x54: //content desc [category] + case 0x64: //Data broadcast desc - Text Desc for Data components + break;; + default: + printf("\t\n",tag,taglen); } - - i=i+taglen+2; } } + if (!seen) + printf("\tNo title given\n"); + + // [desc] + for (i=0;i0 && tag == 0x4D) //short evt desc, [title] [desc] + parseEventDescription(desc+i,0); + } + + // [category] + for (i=0;i0 && tag == 0x54) //content desc [category] + parseContentDescription(CastContentDescriptor(desc+i)); + } + + // [video] + for (i=0,seen=0; i0 && tag == 0x50) //component desc [video] [audio] + parseComponentDescription(CastComponentDescriptor(desc+i), 1, &seen); + } + + // [audio] + for (i=0, seen=0; i0 && tag == 0x50) //component desc [video] [audio] + parseComponentDescription(CastComponentDescriptor(desc+i), 0, &seen); + } + } void parseeit(char *eitbuf, int len)