root/trunk/epgdumpr2/epgdump.c

リビジョン 144, 14.9 kB (コミッタ: sorshi, コミット時期: 11 年 前)

最新の110度CS放送状況に追従。

Line 
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <getopt.h>
6 #include <iconv.h>
7 #include <time.h>
8
9 #include "ts.h"
10 #include "sdt.h"
11 #include "eit.h"
12 #include "ts_ctl.h"
13
14 typedef         struct  _ContentTYPE{
15         char    *japanese ;
16         char    *english ;
17 }CONTENT_TYPE;
18
19 #define         CAT_COUNT               16
20 static  CONTENT_TYPE    ContentCatList[CAT_COUNT] = {
21         { "����若��糸���, "news" },
22         { "�鴻��若�", "sports" },
23         { "���", "information" },
24         { "�����, "drama" },
25         { "�恰ソ", "music" },
26         { "��������, "variety" },
27         { "���", "cinema" },
28         { "�≪��<��号�", "anime" },
29         { "����ャ��潟�����紙�蕕�, "documentary" },
30         { "羲��", "stage" },
31         { "莇e��糸���, "hobby" },
32         { "胼霛�, "etc" },                        //胼霛�   { "篋��", "etc" }, //篋��
33         { "篋��", "etc" }, //篋��
34         { "篋��", "etc" }, //篋��
35         { "���篁�, "etc" } //���篁�};
36 typedef struct _TAG_STATION
37 {
38         char    *name;
39         char    *ontv;
40         int             tsId;           // OriginalNetworkID
41         int             onId;           // TransportStreamID
42         int             svId;           // ServiceID
43 } STATION;
44
45 static STATION bsSta[] = {
46         { "NHK BS1", "3001.ontvjapan.com", 16625, 4, 101},
47         { "NHK BS2", "3002.ontvjapan.com", 16625, 4, 102},//綮�� 2011/3/31
48         { "NHK BS��������, "3003.ontvjapan.com", 16626, 4, 103},
49         { "BS�ャ���, "3004.ontvjapan.com", 16592, 4, 141},
50         { "BS���", "3005.ontvjapan.com", 16400, 4, 151},
51         { "BS-TBS", "3006.ontvjapan.com", 16401, 4, 161},
52         { "BS�吾����", "3007.ontvjapan.com", 16433, 4, 171},
53         { "BS���", "3008.ontvjapan.com", 16593, 4, 181},
54 //      { "WOWOW", "3009.ontvjapan.com", 16432, 4, 191},
55 //      { "WOWOW2", "3010.ontvjapan.com", 16432, 4, 192},
56 //      { "WOWOW3", "3011.ontvjapan.com", 16432, 4, 193},
57         { "WOWOW����ゃ�", "3009.ontvjapan.com", 16432, 4, 191},
58         { "WOWOW�����, "4192.epgdata.ontvjapan", 17488, 4, 192},
59         { "WOWOW�激���, "4193.epgdata.ontvjapan", 17489, 4, 193},
60 //      { "�鴻��若�����潟���, "3012.ontvjapan.com", 16529, 4, 200},
61         { "�鴻��若�����潟���", "3012.ontvjapan.com", 16529, 4, 200},
62         { "�鴻��若�����潟���", "4201.epgdata.ontvjapan", 17520, 4, 201},
63         { "�鴻��若�����潟���", "4202.epgdata.ontvjapan", 17520, 4, 202},
64         { "BS11", "3013.ontvjapan.com", 16528, 4, 211},
65         { "TwellV", "3014.ontvjapan.com", 16530, 4, 222},
66         { "�冗�紊у�1", "4231.epgdata.ontvjapan", 18098, 4, 231},
67         { "�冗�紊у�2", "4232.epgdata.ontvjapan", 18098, 4, 232},
68         { "�冗�紊у�3", "4233.epgdata.ontvjapan", 18098, 4, 233},
69         { "�違��若�����潟���, "4234.epgdata.ontvjapan", 18224, 4, 234},
70         { "BS�≪�������", "1047.ontvjapan.com", 18033, 4, 236},
71         { "FOX bs238", "4238.epgdata.ontvjapan", 18096, 4, 238},
72         { "BS�鴻����鐚�, "4241.epgdata.ontvjapan", 18097, 4, 241},
73         { "J SPORTS 1", "4242.epgdata.ontvjapan", 18225, 4, 242},
74         { "J SPORTS 2", "4243.epgdata.ontvjapan", 18226, 4, 243},
75         { "J SPORTS 3", "4244.epgdata.ontvjapan", 18257, 4, 244},
76         { "J SPORTS 4", "4245.epgdata.ontvjapan", 18258, 4, 245},
77         { "BS�c�����с�", "4251.epgdata.ontvjapan", 18288, 4, 251},
78         { "IMAGICA BS", "4252.epgdata.ontvjapan", 18256, 4, 252},
79         { "�ユ����絨������潟���, "4255.epgdata.ontvjapan", 18289, 4, 255},
80         { "����冴��若�����潟���, "1090.ontvjapan.com", 18034, 4, 256},
81         { "D-Life", "4258.epgdata.ontvjapan", 18290, 4, 258},
82         { "NHK膩�������吾��鰹��延根鐚�, "4291.epgdata.ontvjapan", 17168, 4, 291},
83         { "NHK����������с�鐚��篋��", "4292.epgdata.ontvjapan", 17168, 4, 292},
84         { "�ユ������, "4294.epgdata.ontvjapan", 17169, 4, 294},
85         { "��������, "4295.epgdata.ontvjapan", 17169, 4, 295},
86         { "TBS�����, "4296.epgdata.ontvjapan", 17169, 4, 296},
87         { "������篋�, "4297.epgdata.ontvjapan", 17169, 4, 297},
88         { "��������, "4298.epgdata.ontvjapan", 17168, 4, 298},
89         { "�冗�紊у������, "4531.epgdata.ontvjapan", 18098, 4, 531},
90         { "WNI", "4910.ontvjapan.com", 16626, 4, 910},
91 };
92
93 static int bsStaCount = sizeof(bsSta) / sizeof (STATION);
94
95
96
97 static STATION csSta[] = {
98 //ND2
99         { "鐚器滋鐚潟��c����鐚�, "3201.ontvjapan.com", 24608, 6, 296},//2012綛�����CS1/Ch.296�����     { "�������c����鐚�爾", "1092.ontvjapan.com", 24608, 6, 298},//2012綛�����CS1/Ch.298�����   { "�������若��帥�鐚�爾", "1067.ontvjapan.com", 24608, 6, 299},//2012綛�����CS1/Ch.299�����
100 //ND4
101         { "�鴻����鐚�����", "100ch.epgdata.ontvjapan", 28736, 7, 100},
102         { "����潟���汐鐚ワ治鐚�, "1008.ontvjapan.com", 28736, 7, 223},
103         { "�吟��激���, "1217.ontvjapan.com", 28736, 7, 227},//228��27
104         { "鐔��鐔��鐚<�������", "1040.ontvjapan.com", 28736, 7, 250},//2012綛���4��Ch.255���Ch.250�����     { "�������若��c����", "1050.ontvjapan.com", 28736, 7, 342},
105         { "�牙��糸�罍���c����", "363ch.epgdata.ontvjapan", 28736, 7, 363},
106                
107 //ND6
108         { "���������鐚o示", "294ch.epgdata.ontvjapan", 28768, 7, 294},
109         { "鐚�軸鐚吟�鐚�爾", "1019.ontvjapan.com", 28768, 7, 323},
110         { "罩��������", "329ch.epgdata.ontvjapan", 28768, 7, 329},
111         { "����鴻������, "1062.ontvjapan.com", 28768, 7, 340},
112         { "�≪������������, "1193.ontvjapan.com", 28768, 7, 341},
113         { "鐚o汐鐚��", "1069.ontvjapan.com", 28768, 7, 354},
114 //ND8
115         { "�激��������潟���, "1059.ontvjapan.com", 24704, 6, 55},
116         { "�掩�����潟���, "1010.ontvjapan.com", 24704, 6, 218},//2012/8/1���
117         { "茵�����", "1005.ontvjapan.com", 24704, 6, 219},//2012/8/1���
118         { "����若�����祉���, "1024.ontvjapan.com", 24704, 6, 326},//2012/8/1���
119         { "����冴��若��ャ���, "339ch.epgdata.ontvjapan", 24704, 6, 339},
120         { "�ャ���汐鐚ワ七鐚鰹�鐚�, "2002.ontvjapan.com", 24704, 6, 349},
121 //ND10
122         { "�鴻�����鰹�", "800ch.epgdata.ontvjapan", 24736, 6, 800},
123         { "�鴻�����鰹�", "801ch.epgdata.ontvjapan", 24736, 6, 801},
124         { "�鴻�����鰹�", "802ch.epgdata.ontvjapan", 24736, 6, 802},
125         { "�鴻�����鰹�", "805ch.epgdata.ontvjapan", 24736, 6, 805},
126 //ND12
127         { "鐚э次鐚�鴫鐚�, "1026.ontvjapan.com", 28864, 7, 254},
128         { "������鐚�示鐚�, "1022.ontvjapan.com", 28864, 7, 325},
129         { "����冴�����激���, "1045.ontvjapan.com", 28864, 7, 330},//HD��2012/07/26�泣����330��Щ��/ND14
130 //ND14
131         { "��撮������鐔�示鐚�, "1133.ontvjapan.com", 28896, 7, 292},
132         { "�������弱��器示鐚�, "1015.ontvjapan.com", 28896, 7, 293},
133         { "�鴻����鐚�����鐚�爾", "1006.ontvjapan.com", 28896, 7, 310},
134 //ND16
135         { "鐚鰹自鐚鴻�鐚鰹軸鐚¥磁鐚�, "1207.ontvjapan.com", 28928, 7, 290},
136         { "����潟����羃�, "305ch.epgdata.ontvjapan", 28928, 7, 305},
137         { "鐚¥叱鐚�, "1014.ontvjapan.com", 28928, 7, 311},
138         { "鐚¥軸��叱", "1201.ontvjapan.com", 28928, 7, 333},
139         { "����с�����c����", "1204.ontvjapan.com", 28928, 7, 343},
140         { "鐚�滋鐚c��若���, "1070.ontvjapan.com", 28928, 7, 353},
141 //ND18
142         { "����������刻示鐚�, "1007.ontvjapan.com", 28960, 7, 240},
143         { "�眼�������鐚�爾", "1027.ontvjapan.com", 28960, 7, 262},
144         { "絅恰�鐔��鐚���鐚��", "1074.ontvjapan.com", 28960, 7, 314},
145 //ND20
146         { "��������鹿鐚�璽", "1073.ontvjapan.com", 28992, 7, 307},//��������39��   { "��������軸鐚件鹿", "1072.ontvjapan.com", 28992, 7, 308},//��������21��   { "��������汐鐚ワ叱鐚�, "309ch.epgdata.ontvjapan", 28992, 6, 309},//306��09����c����紊��
147 //ND22
148         { "鐚縁雫鐚�, "1120.ontvjapan.com", 29024, 7, 161},
149         { "鐚器滋鐚潟��c����鐚�, "297ch.epgdata.ontvjapan", 29024, 7, 297},
150         { "鐚�鹿鐚�, "1016.ontvjapan.com", 29024, 7, 312},
151         { "�鴻��若��激����鐚器雫", "1018.ontvjapan.com", 29024, 7, 322},
152         { "�������若�", "1046.ontvjapan.com", 29024, 7, 331},
153         { "鐚器滋鐚潟��ャ��鴻��若�", "1076.ontvjapan.com", 29024, 7, 351},
154 //ND24
155         { "鐚�鹿鐚吾��若���, "229ch.epgdata.ontvjapan", 29056, 7, 229},
156         { "�ャ���磁鐚��鐚�爾", "1068.ontvjapan.com", 29056, 7, 257},//HD��   { "�ャ�������", "300ch.epgdata.ontvjapan", 29056, 7, 300},
157         { "�鴻��激������, "321ch.epgdata.ontvjapan", 29056, 7, 321},
158         { "����c����", "1052.ontvjapan.com", 29056, 7, 362},
159 };
160
161 static int csStaCount = sizeof(csSta) / sizeof (STATION);
162 SVT_CONTROL     *svttop = NULL;
163 #define         SECCOUNT        4
164 char    title[1024];
165 char    subtitle[1024];
166 char    Category[1024];
167 char    ServiceName[1024];
168
169 /* prototype */
170 extern int strrep(char *buf, char *mae, char *ato);
171
172 void    xmlspecialchars(char *str)
173 {
174         strrep(str, "&", "&amp;");
175         strrep(str, "'", "&apos;");
176         strrep(str, "\"", "&quot;");
177         strrep(str, "<", "&lt;");
178         strrep(str, ">", "&gt;");
179 }
180
181
182
183 void    GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, int count)
184 {
185         SECcache  *bsecs;
186
187         while((bsecs = readTS(infile, secs, count)) != NULL) {
188                 /* SDT */
189                 if((bsecs->pid & 0xFF) == 0x11) {
190                         dumpSDT(bsecs->buf, svttop);
191                 }
192         }
193 }
194 void    GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int count)
195 {
196         SECcache  *bsecs;
197         EIT_CONTROL     *eitcur ;
198         EIT_CONTROL     *eitnext ;
199         EIT_CONTROL     *eittop = NULL;
200         time_t  l_time ;
201         time_t  end_time ;
202         struct  tm      tl ;
203         struct  tm      *endtl ;
204         char    cendtime[32];
205         char    cstarttime[32];
206
207         eittop = calloc(1, sizeof(EIT_CONTROL));
208         eitcur = eittop ;
209         fseek(infile, 0, SEEK_SET);
210         while((bsecs = readTS(infile, secs, SECCOUNT)) != NULL) {
211                 /* EIT */
212                 if((bsecs->pid & 0xFF) == 0x12) {
213                         dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
214                 }else if((bsecs->pid & 0xFF) == 0x26) {
215                         dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
216                 }else if((bsecs->pid & 0xFF) == 0x27) {
217                         dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
218                 }
219         }
220         eitcur = eittop ;
221         while(eitcur != NULL){
222                 if(!eitcur->servid){
223                         eitcur = eitcur->next ;
224                         continue ;
225                 }
226                 if(eitcur->content_type > CAT_COUNT){
227                         eitcur->content_type = CAT_COUNT -1 ;
228                 }
229                 memset(title, '\0', sizeof(title));
230                 strcpy(title, eitcur->title);
231                 xmlspecialchars(title);
232
233                 memset(subtitle, '\0', sizeof(subtitle));
234                 strcpy(subtitle, eitcur->subtitle);
235                 xmlspecialchars(subtitle);
236
237                 memset(Category, '\0', sizeof(Category));
238                 strcpy(Category, ContentCatList[eitcur->content_type].japanese);
239                 xmlspecialchars(Category);
240
241                 tl.tm_sec = eitcur->ss ;
242                 tl.tm_min = eitcur->hm ;
243                 tl.tm_hour = eitcur->hh ;
244                 tl.tm_mday = eitcur->dd ;
245                 tl.tm_mon = (eitcur->mm - 1);
246                 tl.tm_year = (eitcur->yy - 1900);
247                 tl.tm_wday = 0;
248                 tl.tm_isdst = 0;
249                 tl.tm_yday = 0;
250                 l_time = mktime(&tl);
251                 if((eitcur->ehh == 0) && (eitcur->emm == 0) && (eitcur->ess == 0)){
252                         (void)time(&l_time);
253                         end_time = l_time + (60 * 5);           // 鐚��緇��荐��
254                 endtl = localtime(&end_time);
255                 }else{
256                         end_time = l_time + eitcur->ehh * 3600 + eitcur->emm * 60 + eitcur->ess;
257                         endtl = localtime(&end_time);
258                 }
259                 memset(cendtime, '\0', sizeof(cendtime));
260                 memset(cstarttime, '\0', sizeof(cstarttime));
261                 strftime(cendtime, (sizeof(cendtime) - 1), "%Y%m%d%H%M%S", endtl);
262                 strftime(cstarttime, (sizeof(cstarttime) - 1), "%Y%m%d%H%M%S", &tl);
263 #if 1
264                 fprintf(outfile, "  <programme start=\"%s +0900\" stop=\"%s +0900\" channel=\"%s\">\n",
265                                 cstarttime, cendtime, psta->ontv);
266                 fprintf(outfile, "    <title lang=\"ja_JP\">%s</title>\n", title);
267                 fprintf(outfile, "    <desc lang=\"ja_JP\">%s</desc>\n", subtitle);
268                 fprintf(outfile, "    <category lang=\"ja_JP\">%s</category>\n", Category);
269                 fprintf(outfile, "    <category lang=\"en\">%s</category>\n", ContentCatList[eitcur->content_type].english);
270                 fprintf(outfile, "  </programme>\n");
271 #else
272                 fprintf(outfile, "(%x:%x:%x)%s,%s,%s,%s,%s,%s\n",
273                                         eitcur->servid, eitcur->table_id, eitcur->event_id,
274                                         cstarttime, cendtime,
275                                         title, subtitle,
276                                         Category,
277                                         ContentCatList[eitcur->content_type].english);
278 #endif
279 #if 0
280                 fprintf(outfile, "(%x:%x)%04d/%02d/%02d,%02d:%02d:%02d,%02d:%02d:%02d,%s,%s,%s,%s\n",
281                                         eitcur->table_id, eitcur->event_id,
282                                         eitcur->yy, eitcur->mm, eitcur->dd,
283                                         eitcur->hh, eitcur->hm, eitcur->ss,
284                                         eitcur->ehh, eitcur->emm, eitcur->ess,
285                                         eitcur->title, eitcur->subtitle,
286                                         ContentCatList[eitcur->content_type].japanese,
287                                         ContentCatList[eitcur->content_type].english);
288 #endif
289                 eitnext = eitcur->next ;
290                 free(eitcur->title);
291                 free(eitcur->subtitle);
292                 free(eitcur);
293                 eitcur = eitnext ;
294         }
295         free(eittop);
296         eittop = NULL;
297 }
298 int main(int argc, char *argv[])
299 {
300
301         FILE *infile = stdin;
302         FILE *outfile = stdout;
303         char    *arg_onTV ;
304         int             staCount ;
305         char *file;
306         int   inclose = 0;
307         int   outclose = 0;
308         SVT_CONTROL     *svtcur ;
309         SVT_CONTROL     *svtsave ;
310         SECcache   secs[SECCOUNT];
311         int             lp ;
312         STATION *pStas ;
313         int             act ;
314
315         /* ��������id���絎�*/
316         memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
317         secs[0].pid = 0x11;
318         secs[1].pid = 0x12;
319         secs[2].pid = 0x26;
320         secs[3].pid = 0x27;
321
322         if(argc == 4){
323                 arg_onTV = argv[1];
324                 file = argv[2];
325                 if(strcmp(file, "-")) {
326                         infile = fopen(file, "r");
327                         inclose = 1;
328                 }
329                 if(strcmp(argv[3], "-")) {
330                         outfile = fopen(argv[3], "w+");
331                         outclose = 1;
332                 }
333         }else{
334                 fprintf(stdout, "Usage : %s {/BS|/CS} <tsFile> <outfile>\n", argv[0]);
335                 fprintf(stdout, "Usage : %s <ontvcode> <tsFile> <outfile>\n", argv[0]);
336                 fprintf(stdout, "\n");
337                 fprintf(stdout, "  ontvcode   Channel identifier (ex. ****.ontvjapan.com)\n");
338                 fprintf(stdout, "  /BS        BS mode\n");
339                 fprintf(stdout, "               This mode reads the data of all BS TV stations\n");
340                 fprintf(stdout, "               from one TS data.\n");
341                 fprintf(stdout, "  /CS        CS mode\n");
342                 fprintf(stdout, "               This mode reads the data of two or more CS TV stations\n");
343                 fprintf(stdout, "               from one TS data.\n");
344                 return 0;
345         }
346
347         if(strcmp(arg_onTV, "/BS") == 0){
348                 pStas = bsSta;
349                 staCount = bsStaCount;
350                 act = 0 ;
351         }else if(strcmp(arg_onTV, "/CS") == 0){
352                 pStas = csSta;
353                 staCount = csStaCount;
354                 act = 0 ;
355         }else{
356                 act = 1 ;
357                 svttop = calloc(1, sizeof(SVT_CONTROL));
358                 GetSDT(infile, svttop, secs, SECCOUNT);
359                 svtcur = svttop->next ; //���
360                 if(svtcur == NULL){
361                         free(svttop);
362                         return 1;
363                 }
364
365                 pStas = calloc(1, sizeof(STATION));
366                 pStas->tsId = svtcur->transport_stream_id ;
367                 pStas->onId = svtcur->original_network_id ;
368                 pStas->svId = svtcur->event_id ;
369                 pStas->ontv = arg_onTV ;
370                 pStas->name = svtcur->servicename ;
371                 staCount = 1;
372         }
373
374         fprintf(outfile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
375         fprintf(outfile, "<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n\n");
376         fprintf(outfile, "<tv generator-info-name=\"tsEPG2xml\" generator-info-url=\"http://localhost/\">\n");
377
378         for(lp = 0 ; lp < staCount ; lp++){
379                 memset(ServiceName, '\0', sizeof(ServiceName));
380                 strcpy(ServiceName, pStas[lp].name);
381                 xmlspecialchars(ServiceName);
382
383                 fprintf(outfile, "  <channel id=\"%s\">\n", pStas[lp].ontv);
384                 fprintf(outfile, "    <display-name lang=\"ja_JP\">%s</display-name>\n", ServiceName);
385                 fprintf(outfile, "  </channel>\n");
386         }
387         for(lp = 0 ; lp < staCount ; lp++){
388                 GetEIT(infile, outfile, &pStas[lp], secs, SECCOUNT);
389         }
390         fprintf(outfile, "</tv>\n");
391         if(inclose) {
392                 fclose(infile);
393         }
394
395         if(outclose) {
396                 fclose(outfile);
397         }
398         if(act){
399                 free(pStas);
400                 svtcur = svttop ;       //���
401                 while(svtcur != NULL){
402                         svtsave = svtcur->next ;
403                         free(svtcur);
404                         svtcur = svtsave ;
405                 }
406         }
407
408         return 0;
409 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed