14 typedef struct _ContentTYPE{
20 static CONTENT_TYPE ContentCatList[CAT_COUNT] = {
21 { "¥Ë¥å¡¼¥¹¡¦ÊóÆ»", "news" },
22 { "¥¹¥Ý¡¼¥Ä", "sports" },
23 { "¾ðÊó", "information" },
24 { "¥É¥é¥Þ", "drama" },
26 { "¥Ð¥é¥¨¥Æ¥£", "variety" },
28 { "¥¢¥Ë¥á¡¦Æû£", "anime" },
29 { "¥É¥¥å¥á¥ó¥¿¥ê¡¼¡¦¶µÍÜ", "documentary" },
31 { "¼ñÌ£¡¦¼ÂÍÑ", "hobby" },
32 { "Ê¡»ã", "etc" }, //Ê¡»ã
33 { "ͽÈ÷", "etc" }, //ͽÈ÷
34 { "ͽÈ÷", "etc" }, //ͽÈ÷
35 { "ͽÈ÷", "etc" }, //ͽÈ÷
36 { "¤½¤Î¾", "etc" } //¤½¤Î¾
39 SVT_CONTROL *svttop = NULL;
43 char desc[102400] = {0};
45 char ServiceName[1024];
48 void xmlspecialchars(char *str)
50 strrep(str, "&", "&");
51 strrep(str, "'", "'");
52 strrep(str, "\"", """);
53 strrep(str, "<", "<");
54 strrep(str, ">", ">");
59 void GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, int count)
63 while((bsecs = readTS(infile, secs, count)) != NULL) {
65 if((bsecs->pid & 0xFF) == 0x11) {
66 dumpSDT(bsecs->buf, svttop);
70 void GetSDT_chout(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, int count,STATION *station, int * station_count,char *header)
74 while((bsecs = readTS(infile, secs, count)) != NULL) {
76 if((bsecs->pid & 0xFF) == 0x11) {
77 dumpSDT_chout(bsecs->buf,svttop,station,station_count,header);
81 void GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int count)
85 EIT_CONTROL *eitnext ;
86 EIT_CONTROL *eittop = NULL;
98 eittop = calloc(1, sizeof(EIT_CONTROL));
100 fseek(infile, 0, SEEK_SET);
101 while((bsecs = readTS(infile, secs, SECCOUNT)) != NULL) {
103 if((bsecs->pid & 0xFF) == 0x12) {
104 dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
105 }else if((bsecs->pid & 0xFF) == 0x26) {
106 dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
107 }else if((bsecs->pid & 0xFF) == 0x27) {
108 dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
112 while(eitcur != NULL){
114 eitcur = eitcur->next ;
117 if(eitcur->content_type > CAT_COUNT){
118 eitcur->content_type = CAT_COUNT -1 ;
121 memset(title, '\0', sizeof(title));
122 ilen = strlen(eitcur->title);
123 olen = sizeof(title);
124 inptr = eitcur->title;
125 iconv(cd, &inptr, &ilen, &outptr, &olen);
126 xmlspecialchars(title);
128 memset(subtitle, '\0', sizeof(subtitle));
129 ilen = strlen(eitcur->subtitle);
130 olen = sizeof(subtitle);
132 inptr = eitcur->subtitle;
133 iconv(cd, &inptr, &ilen, &outptr, &olen);
134 xmlspecialchars(subtitle);
136 memset(desc, '\0', sizeof(desc));
137 if ( eitcur->desc ) {
138 ilen = strlen(eitcur->desc);
141 inptr = eitcur->desc;
142 iconv(cd, &inptr, &ilen, &outptr, &olen);
143 xmlspecialchars(desc);
146 memset(Category, '\0', sizeof(Category));
147 ilen = strlen(ContentCatList[eitcur->content_type].japanese);
148 olen = sizeof(Category);
150 inptr = ContentCatList[eitcur->content_type].japanese;
151 iconv(cd, &inptr, &ilen, &outptr, &olen);
152 xmlspecialchars(Category);
154 tl.tm_sec = eitcur->ss ;
155 tl.tm_min = eitcur->hm ;
156 tl.tm_hour = eitcur->hh ;
157 tl.tm_mday = eitcur->dd ;
158 tl.tm_mon = (eitcur->mm - 1);
159 tl.tm_year = (eitcur->yy - 1900);
163 l_time = mktime(&tl);
164 if((eitcur->ehh == 0) && (eitcur->emm == 0) && (eitcur->ess == 0)){
166 end_time = l_time + (60 * 5); // £µÊ¬¸å¤ËÀßÄê
167 endtl = localtime(&end_time);
169 end_time = l_time + eitcur->ehh * 3600 + eitcur->emm * 60 + eitcur->ess;
170 endtl = localtime(&end_time);
172 memset(cendtime, '\0', sizeof(cendtime));
173 memset(cstarttime, '\0', sizeof(cstarttime));
174 strftime(cendtime, (sizeof(cendtime) - 1), "%Y%m%d%H%M%S", endtl);
175 strftime(cstarttime, (sizeof(cstarttime) - 1), "%Y%m%d%H%M%S", &tl);
177 fprintf(outfile, " <programme start=\"%s +0900\" stop=\"%s +0900\" channel=\"%s\">\n",
178 cstarttime, cendtime, psta->ontv);
179 fprintf(outfile, " <title lang=\"ja_JP\">%s</title>\n", title);
180 fprintf(outfile, " <desc lang=\"ja_JP\">%s</desc>\n", subtitle);
181 fprintf(outfile, " <longdesc lang=\"ja_JP\">%s</longdesc>\n", desc);
182 fprintf(outfile, " <category lang=\"ja_JP\">%s</category>\n", Category);
183 // fprintf(outfile, " <category lang=\"en\">%s</category>\n", ContentCatList[eitcur->content_type].english);
184 fprintf(outfile, " </programme>\n");
186 fprintf(outfile, "(%x:%x:%x)%s,%s,%s,%s,%s,%s\n",
187 eitcur->servid, eitcur->table_id, eitcur->event_id,
188 cstarttime, cendtime,
191 ContentCatList[eitcur->content_type].english);
194 fprintf(outfile, "(%x:%x)%04d/%02d/%02d,%02d:%02d:%02d,%02d:%02d:%02d,%s,%s,%s,%s\n",
195 eitcur->table_id, eitcur->event_id,
196 eitcur->yy, eitcur->mm, eitcur->dd,
197 eitcur->hh, eitcur->hm, eitcur->ss,
198 eitcur->ehh, eitcur->emm, eitcur->ess,
199 eitcur->title, eitcur->subtitle,
200 ContentCatList[eitcur->content_type].japanese,
201 ContentCatList[eitcur->content_type].english);
203 eitnext = eitcur->next ;
205 free(eitcur->subtitle);
212 void checkSta_BS(STATION **station,int *stalength){
217 STATION * statin= *station;
218 statmp=malloc(sizeof(STATION)*2);
219 for (int i=0;i<*stalength;i++){
221 for (int j=0;j<chlt;j++){
222 if (chl[j]==statin[i].svId || statin[i].svId >= 290){
227 statmp=realloc(statmp,(stal+1)*sizeof(STATION));
228 statmp[stal]=statin[i];
229 //memcpy(statmp[stal-1],station[i],sizeof(STATION));
230 chl[chlt]=statin[i].svId;
235 //*station=realloc(station,(stal+1)*sizeof(STATION));
236 //memcpy(*station,statmp,(stal+1)*sizeof(STATION));
239 //memcpy(statin,statmp,chlt*sizeof(STATION));
244 void checkSta(STATION **station,int *stalength){
249 STATION * statin= *station;
250 statmp=malloc(sizeof(STATION)*2);
251 for (int i=0;i<*stalength;i++){
253 for (int j=0;j<chlt;j++){
254 if (chl[j]==statin[i].svId){
259 statmp=realloc(statmp,(stal+1)*sizeof(STATION));
260 statmp[stal]=statin[i];
261 //memcpy(statmp[stal-1],station[i],sizeof(STATION));
262 chl[chlt]=statin[i].svId;
269 *stalength=stal;//¤³¤³¤¤¤é¤¬²ø¤·¤¤
270 //memcpy(statin,statmp,chlt*sizeof(STATION));
274 int main(int argc, char *argv[])
277 FILE *infile = stdin;
278 FILE *outfile = stdout;
279 int arg_maxcount = 1 ;
289 SVT_CONTROL *svtcur ;
290 SVT_CONTROL *svtsave ;
295 SECcache secs[SECCOUNT];
301 /* ¶½Ì£¤Î¤¢¤ëpid¤ò»ØÄê */
302 memset(secs, 0, sizeof(SECcache) * SECCOUNT);
311 if(strcmp(file, "-")) {
312 infile = fopen(file, "r");
315 if(strcmp(argv[3], "-")) {
316 outfile = fopen(argv[3], "w+");
320 fprintf(stdout, "Usage : %s /BS <tsFile> <outfile>\n", argv[0]);
321 fprintf(stdout, "Usage : %s <ontvcode> <tsFile> <outfile>\n", argv[0]);
322 fprintf(stdout, "ontvcode ¥Á¥ã¥ó¥Í¥ë¼±Ê̻ҡ£****.ontvjapan.com ¤Ê¤É\n");
323 fprintf(stdout, "/BS BS¥â¡¼¥É¡£°ì¤Ä¤ÎTS¤«¤éBSÁ´¶É¤Î¥Ç¡¼¥¿¤òÆɤ߹þ¤ß¤Þ¤¹¡£\n");
324 fprintf(stdout, "/CS CS¥â¡¼¥É¡£°ì¤Ä¤ÎTS¤«¤éÊ£¿ô¶É¤Î¥Ç¡¼¥¿¤òÆɤ߹þ¤ß¤Þ¤¹¡£\n");
328 if(strcmp(arg_onTV, "/BS") == 0){
329 STATION *sta=malloc(sizeof(STATION)*2);
331 svttop = calloc(1, sizeof(SVT_CONTROL));
333 GetSDT_chout(infile, svttop, secs, SECCOUNT,&sta, &sta_count,head);
334 checkSta_BS(&sta,&sta_count);
336 //printf("Station count: %d\n1st ontv=%s,name=%s\n",sta_count, sta[0].ontv, sta[0].name);
338 staCount = sta_count;// sizeof(pStas) / sizeof (STATION);
341 }else if(strcmp(arg_onTV, "/CS") == 0){
344 svttop = calloc(1, sizeof(SVT_CONTROL));
346 GetSDT_chout(infile, svttop, secs, SECCOUNT,&sta, &sta_count,head);
347 checkSta(&sta,&sta_count);
349 //printf("Station count: %d\n1st ontv=%s,name=%s\n",sta_count, sta[0].ontv, sta[0].name);
351 staCount = sta_count;
352 //staCount=sizeof(pStas) / sizeof (STATION);
355 }else if(strcmp(arg_onTV, "/TEST") == 0){
358 svttop = calloc(1, sizeof(SVT_CONTROL));
360 GetSDT_chout(infile, svttop, secs, SECCOUNT,&sta, &sta_count,head);
361 checkSta(&sta,&sta_count);
363 //printf("Station count: %d\n1st ontv=%s,name=%s\n",sta_count, sta[0].ontv, sta[0].name);
365 staCount = sta_count;// sizeof(pStas) / sizeof (STATION);
370 svttop = calloc(1, sizeof(SVT_CONTROL));
371 GetSDT(infile, svttop, secs, SECCOUNT);
372 svtcur = svttop->next ; //ÀèƬ
378 pStas = calloc(1, sizeof(STATION));
379 pStas->tsId = svtcur->transport_stream_id ;
380 pStas->onId = svtcur->original_network_id ;
381 pStas->svId = svtcur->event_id ;
382 pStas->ontv = arg_onTV ;
383 pStas->name = svtcur->servicename ;
388 svttop = calloc(1, sizeof(SVT_CONTROL));
389 //char *head=arg_onTV;
390 GetSDT_chout(infile, svttop, secs, SECCOUNT,&sta, &sta_count,arg_onTV);
391 checkSta(&sta,&sta_count);
393 //printf("Station count: %d\n1st ontv=%s,name=%s\n",sta_count, sta[0].ontv, sta[0].name);
395 staCount = sta_count;// sizeof(pStas) / sizeof (STATION);
399 if (outputhtml == 1){
400 fprintf(outfile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
401 fprintf(outfile, "<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n\n");
402 fprintf(outfile, "<tv generator-info-name=\"tsEPG2xml\" generator-info-url=\"http://localhost/\">\n");
404 cd = iconv_open("UTF-8", "EUC-JP");
405 for(lp = 0 ; lp < staCount ; lp++){
406 memset(ServiceName, '\0', sizeof(ServiceName));
407 ilen = strlen(pStas[lp].name);
408 olen = sizeof(ServiceName);
409 outptr = ServiceName ;
410 inptr = pStas[lp].name ;
411 iconv(cd, &inptr, &ilen, &outptr, &olen);
412 xmlspecialchars(ServiceName);
414 fprintf(outfile, " <channel id=\"%s\">\n", pStas[lp].ontv);
415 fprintf(outfile, " <display-name lang=\"ja_JP\">%s</display-name>\n", ServiceName);
416 fprintf(outfile, " </channel>\n");
418 for(lp = 0 ; lp < staCount ; lp++){
419 GetEIT(infile, outfile, &pStas[lp], secs, SECCOUNT);
421 fprintf(outfile, "</tv>\n");
432 svtcur = svttop ; //ÀèƬ
433 while(svtcur != NULL){
434 svtsave = svtcur->next ;