root/trunk/epgdumpr2/epgdump.c

リビジョン 136, 13.5 kB (コミッタ: sorshi, コミット時期: 13 年 前)

foltiaで利用しているepgdumpを追加

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         { "�鴻��若�����潟���, "3012.ontvjapan.com", 16529, 4, 200},
58         { "BS11", "3013.ontvjapan.com", 16528, 4, 211},
59         { "TwellV", "3014.ontvjapan.com", 16530, 4, 222},
60 };
61
62 static int bsStaCount = sizeof(bsSta) / sizeof (STATION);
63
64
65
66 static STATION csSta[] = {
67         { "�鴻��種�鐔�����", "1002.ontvjapan.com", 24608, 6, 237},
68         { "�ユ����絨��鐔��鐚�爾", "1086.ontvjapan.com", 24608, 6, 239},//��������SHD ��      { "��������汐鐚ワ叱鐚�, "306ch.epgdata.ontvjapan", 24608, 6, 306},
69         { "�激��������潟���, "1059.ontvjapan.com", 24704, 6, 55},
70         { "�吟��激���, "1217.ontvjapan.com", 24736, 6, 228},
71         { "�鴻�����鰹示鐚わ�鐚��", "800ch.epgdata.ontvjapan", 24736, 6, 800},
72         { "�鴻�����鰹�鐚��", "801ch.epgdata.ontvjapan", 24736, 6, 801},
73         { "�鴻�����鰹�鐚��", "802ch.epgdata.ontvjapan", 24736, 6, 802},
74         { "鐔�������, "100ch.epgdata.ontvjapan", 28736, 7, 100},
75         { "�ゃ��帥�������鐚器雫", "194ch.epgdata.ontvjapan", 28736, 7, 194},
76         { "鐚��������鐚ワ竺鐚逸汐", "1025.ontvjapan.com", 28736, 7, 256},
77         { "鐚�鹿鐚�, "1016.ontvjapan.com", 28736, 7, 312},
78         { "�鴻��若��激����鐚器雫", "1018.ontvjapan.com", 28736, 7, 322},
79         { "�������若�������", "1046.ontvjapan.com", 28736, 7, 331},
80         { "����若��祉��c����", "1213.ontvjapan.com", 28736, 7, 334},
81         { "�掩�����潟���, "1010.ontvjapan.com", 28768, 7, 221},
82         { "茵�����", "1005.ontvjapan.com", 28768, 7, 222},
83         { "����潟���汐鐚ワ治鐚�, "1008.ontvjapan.com", 28768, 7, 223},
84         { "羇���������c�", "1009.ontvjapan.com", 28768, 7, 224},
85         { "�鴻��若�����激���, "1003.ontvjapan.com", 28768, 7, 238},
86         { "��撮�������c����", "1133.ontvjapan.com", 28768, 7, 292},
87         { "�鴻���������, "1006.ontvjapan.com", 28768, 7, 310},
88         { "鐚¥叱鐚�, "1014.ontvjapan.com", 28768, 7, 311},
89         { "����с�����c����", "1204.ontvjapan.com", 28768, 7, 343},
90         { "����������帥�", "110ch.epgdata.ontvjapan", 28864, 7, 110},
91         { "�眼�����c����", "1028.ontvjapan.com", 28864, 7, 260},
92         { "�������c����", "1092.ontvjapan.com", 28864, 7, 303},
93         { "鐚�軸鐚�, "1019.ontvjapan.com", 28864, 7, 323},
94         { "����若�����祉���, "1024.ontvjapan.com", 28864, 7, 324},
95         { "�������若��帥�", "1067.ontvjapan.com", 28864, 7, 352},
96         { "鐚�滋鐚c��若���, "1070.ontvjapan.com", 28864, 7, 353},
97         { "鐚o汐鐚��", "1069.ontvjapan.com", 28864, 7, 354},
98         { "�吾��鴻��祉���, "361ch.epgdata.ontvjapan", 28864, 7, 361},
99         { "鐚��������鐚�, "1041.ontvjapan.com", 28896, 7, 251},
100         { "鐚��������鐚�, "1042.ontvjapan.com", 28896, 7, 252},
101         { "鐚�������式鐔��鐔�示", "1043.ontvjapan.com", 28896, 7, 253},
102         { "鐚э次鐚�鴫鐚�, "1026.ontvjapan.com", 28896, 7, 254},
103         { "鐔��鐔��鐚<�������", "1040.ontvjapan.com", 28896, 7, 255},
104         { "絎������≪��c����", "101ch.epgdata.ontvjapan", 28928, 7, 101},
105         { "鐚鰹自鐚鴻�鐚鰹軸鐚¥磁鐚�, "1207.ontvjapan.com", 28928, 7, 290},
106         { "����潟����羃�, "305ch.epgdata.ontvjapan", 28928, 7, 305},
107         { "鐚¥軸-鐚�, "1201.ontvjapan.com", 28928, 7, 333},
108         { "�������若��c����", "1050.ontvjapan.com", 28928, 7, 342},
109         { "�鴻�����鰹�鐚��", "803ch.epgdata.ontvjapan", 28928, 7, 803},
110         { "�鴻�����鰹�鐚��", "804ch.epgdata.ontvjapan", 28928, 7, 804},
111         { "����������刻示鐚�, "1007.ontvjapan.com", 28960, 7, 240},
112         { "�眼������������, "1027.ontvjapan.com", 28960, 7, 262},
113         { "鐚��鐚����示鐚�, "1074.ontvjapan.com", 28960, 7, 314},
114         { "��������鹿鐚�璽", "1073.ontvjapan.com", 28992, 7, 307},//��������39��   { "��������軸鐚件鹿", "1072.ontvjapan.com", 28992, 7, 308},//��������21��   { "�≪�������", "1047.ontvjapan.com", 28992, 7, 332},
115         { "����鴻������, "1062.ontvjapan.com", 28992, 7, 340},
116         { "�≪������������, "1193.ontvjapan.com", 28992, 7, 341},
117         { "鐚�鐚器滋鐚潟�������", "160ch.epgdata.ontvjapan", 29024, 7, 160},
118         { "鐚縁雫鐚�, "1120.ontvjapan.com", 29024, 7, 161},
119         { "����ゃ�鐚��鐚��鐚器雫", "185ch.epgdata.ontvjapan", 29024, 7, 185},
120         { "�������弱���, "1015.ontvjapan.com", 29024, 7, 293},
121         { "鐚器滋鐚潟��c����", "3201.ontvjapan.com", 29024, 7, 301},
122         { "����冴��若��c����", "1090.ontvjapan.com", 29024, 7, 304},
123         { "MUSIC ON! TV", "1022.ontvjapan.com", 29024, 7, 325},
124         { "����冴�����激���D", "1045.ontvjapan.com", 29024, 7, 335},//HD��        { "鐚器滋鐚潟��ャ��鴻��若�", "1076.ontvjapan.com", 29024, 7, 351},
125         { "鐚o竺�ユ���������, "147ch.epgdata.ontvjapan", 29056, 7, 147},
126         { "�ャ���磁鐚�, "1068.ontvjapan.com", 29056, 7, 257},
127         { "fashion TV", "5004.ontvjapan.com", 29056, 7, 291},
128         { "�ャ�������", "300ch.epgdata.ontvjapan", 29056, 7, 300},
129         { "�������若����鐚器雫", "1023.ontvjapan.com", 29056, 7, 320},
130         { "Music Japan TV", "1208.ontvjapan.com", 29056, 7, 321},
131         { "�ャ���汐鐚ワ七鐚鰹�鐚�, "2002.ontvjapan.com", 29056, 7, 350},
132 };
133
134 static int csStaCount = sizeof(csSta) / sizeof (STATION);
135 SVT_CONTROL     *svttop = NULL;
136 #define         SECCOUNT        4
137 char    title[1024];
138 char    subtitle[1024];
139 char    Category[1024];
140 char    ServiceName[1024];
141
142 /* prototype */
143 extern int strrep(char *buf, char *mae, char *ato);
144
145 void    xmlspecialchars(char *str)
146 {
147         strrep(str, "&", "&amp;");
148         strrep(str, "'", "&apos;");
149         strrep(str, "\"", "&quot;");
150         strrep(str, "<", "&lt;");
151         strrep(str, ">", "&gt;");
152 }
153
154
155
156 void    GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, int count)
157 {
158         SECcache  *bsecs;
159
160         while((bsecs = readTS(infile, secs, count)) != NULL) {
161                 /* SDT */
162                 if((bsecs->pid & 0xFF) == 0x11) {
163                         dumpSDT(bsecs->buf, svttop);
164                 }
165         }
166 }
167 void    GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int count)
168 {
169         SECcache  *bsecs;
170         EIT_CONTROL     *eitcur ;
171         EIT_CONTROL     *eitnext ;
172         EIT_CONTROL     *eittop = NULL;
173         time_t  l_time ;
174         time_t  end_time ;
175         struct  tm      tl ;
176         struct  tm      *endtl ;
177         char    cendtime[32];
178         char    cstarttime[32];
179
180         eittop = calloc(1, sizeof(EIT_CONTROL));
181         eitcur = eittop ;
182         fseek(infile, 0, SEEK_SET);
183         while((bsecs = readTS(infile, secs, SECCOUNT)) != NULL) {
184                 /* EIT */
185                 if((bsecs->pid & 0xFF) == 0x12) {
186                         dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
187                 }else if((bsecs->pid & 0xFF) == 0x26) {
188                         dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
189                 }else if((bsecs->pid & 0xFF) == 0x27) {
190                         dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
191                 }
192         }
193         eitcur = eittop ;
194         while(eitcur != NULL){
195                 if(!eitcur->servid){
196                         eitcur = eitcur->next ;
197                         continue ;
198                 }
199                 if(eitcur->content_type > CAT_COUNT){
200                         eitcur->content_type = CAT_COUNT -1 ;
201                 }
202                 memset(title, '\0', sizeof(title));
203                 strcpy(title, eitcur->title);
204                 xmlspecialchars(title);
205
206                 memset(subtitle, '\0', sizeof(subtitle));
207                 strcpy(subtitle, eitcur->subtitle);
208                 xmlspecialchars(subtitle);
209
210                 memset(Category, '\0', sizeof(Category));
211                 strcpy(Category, ContentCatList[eitcur->content_type].japanese);
212                 xmlspecialchars(Category);
213
214                 tl.tm_sec = eitcur->ss ;
215                 tl.tm_min = eitcur->hm ;
216                 tl.tm_hour = eitcur->hh ;
217                 tl.tm_mday = eitcur->dd ;
218                 tl.tm_mon = (eitcur->mm - 1);
219                 tl.tm_year = (eitcur->yy - 1900);
220                 tl.tm_wday = 0;
221                 tl.tm_isdst = 0;
222                 tl.tm_yday = 0;
223                 l_time = mktime(&tl);
224                 if((eitcur->ehh == 0) && (eitcur->emm == 0) && (eitcur->ess == 0)){
225                         (void)time(&l_time);
226                         end_time = l_time + (60 * 5);           // 鐚��緇��荐��
227                 endtl = localtime(&end_time);
228                 }else{
229                         end_time = l_time + eitcur->ehh * 3600 + eitcur->emm * 60 + eitcur->ess;
230                         endtl = localtime(&end_time);
231                 }
232                 memset(cendtime, '\0', sizeof(cendtime));
233                 memset(cstarttime, '\0', sizeof(cstarttime));
234                 strftime(cendtime, (sizeof(cendtime) - 1), "%Y%m%d%H%M%S", endtl);
235                 strftime(cstarttime, (sizeof(cstarttime) - 1), "%Y%m%d%H%M%S", &tl);
236 #if 1
237                 fprintf(outfile, "  <programme start=\"%s +0900\" stop=\"%s +0900\" channel=\"%s\">\n",
238                                 cstarttime, cendtime, psta->ontv);
239                 fprintf(outfile, "    <title lang=\"ja_JP\">%s</title>\n", title);
240                 fprintf(outfile, "    <desc lang=\"ja_JP\">%s</desc>\n", subtitle);
241                 fprintf(outfile, "    <category lang=\"ja_JP\">%s</category>\n", Category);
242                 fprintf(outfile, "    <category lang=\"en\">%s</category>\n", ContentCatList[eitcur->content_type].english);
243                 fprintf(outfile, "  </programme>\n");
244 #else
245                 fprintf(outfile, "(%x:%x:%x)%s,%s,%s,%s,%s,%s\n",
246                                         eitcur->servid, eitcur->table_id, eitcur->event_id,
247                                         cstarttime, cendtime,
248                                         title, subtitle,
249                                         Category,
250                                         ContentCatList[eitcur->content_type].english);
251 #endif
252 #if 0
253                 fprintf(outfile, "(%x:%x)%04d/%02d/%02d,%02d:%02d:%02d,%02d:%02d:%02d,%s,%s,%s,%s\n",
254                                         eitcur->table_id, eitcur->event_id,
255                                         eitcur->yy, eitcur->mm, eitcur->dd,
256                                         eitcur->hh, eitcur->hm, eitcur->ss,
257                                         eitcur->ehh, eitcur->emm, eitcur->ess,
258                                         eitcur->title, eitcur->subtitle,
259                                         ContentCatList[eitcur->content_type].japanese,
260                                         ContentCatList[eitcur->content_type].english);
261 #endif
262                 eitnext = eitcur->next ;
263                 free(eitcur->title);
264                 free(eitcur->subtitle);
265                 free(eitcur);
266                 eitcur = eitnext ;
267         }
268         free(eittop);
269         eittop = NULL;
270 }
271 int main(int argc, char *argv[])
272 {
273
274         FILE *infile = stdin;
275         FILE *outfile = stdout;
276         char    *arg_onTV ;
277         int             staCount ;
278         char *file;
279         int   inclose = 0;
280         int   outclose = 0;
281         SVT_CONTROL     *svtcur ;
282         SVT_CONTROL     *svtsave ;
283         SECcache   secs[SECCOUNT];
284         int             lp ;
285         STATION *pStas ;
286         int             act ;
287
288         /* ��������id���絎�*/
289         memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
290         secs[0].pid = 0x11;
291         secs[1].pid = 0x12;
292         secs[2].pid = 0x26;
293         secs[3].pid = 0x27;
294
295         if(argc == 4){
296                 arg_onTV = argv[1];
297                 file = argv[2];
298                 if(strcmp(file, "-")) {
299                         infile = fopen(file, "r");
300                         inclose = 1;
301                 }
302                 if(strcmp(argv[3], "-")) {
303                         outfile = fopen(argv[3], "w+");
304                         outclose = 1;
305                 }
306         }else{
307                 fprintf(stdout, "Usage : %s {/BS|/CS} <tsFile> <outfile>\n", argv[0]);
308                 fprintf(stdout, "Usage : %s <ontvcode> <tsFile> <outfile>\n", argv[0]);
309                 fprintf(stdout, "\n");
310                 fprintf(stdout, "  ontvcode   Channel identifier (ex. ****.ontvjapan.com)\n");
311                 fprintf(stdout, "  /BS        BS mode\n");
312                 fprintf(stdout, "               This mode reads the data of all BS TV stations\n");
313                 fprintf(stdout, "               from one TS data.\n");
314                 fprintf(stdout, "  /CS        CS mode\n");
315                 fprintf(stdout, "               This mode reads the data of two or more CS TV stations\n");
316                 fprintf(stdout, "               from one TS data.\n");
317                 return 0;
318         }
319
320         if(strcmp(arg_onTV, "/BS") == 0){
321                 pStas = bsSta;
322                 staCount = bsStaCount;
323                 act = 0 ;
324         }else if(strcmp(arg_onTV, "/CS") == 0){
325                 pStas = csSta;
326                 staCount = csStaCount;
327                 act = 0 ;
328         }else{
329                 act = 1 ;
330                 svttop = calloc(1, sizeof(SVT_CONTROL));
331                 GetSDT(infile, svttop, secs, SECCOUNT);
332                 svtcur = svttop->next ; //���
333                 if(svtcur == NULL){
334                         free(svttop);
335                         return 1;
336                 }
337
338                 pStas = calloc(1, sizeof(STATION));
339                 pStas->tsId = svtcur->transport_stream_id ;
340                 pStas->onId = svtcur->original_network_id ;
341                 pStas->svId = svtcur->event_id ;
342                 pStas->ontv = arg_onTV ;
343                 pStas->name = svtcur->servicename ;
344                 staCount = 1;
345         }
346
347         fprintf(outfile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
348         fprintf(outfile, "<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n\n");
349         fprintf(outfile, "<tv generator-info-name=\"tsEPG2xml\" generator-info-url=\"http://localhost/\">\n");
350
351         for(lp = 0 ; lp < staCount ; lp++){
352                 memset(ServiceName, '\0', sizeof(ServiceName));
353                 strcpy(ServiceName, pStas[lp].name);
354                 xmlspecialchars(ServiceName);
355
356                 fprintf(outfile, "  <channel id=\"%s\">\n", pStas[lp].ontv);
357                 fprintf(outfile, "    <display-name lang=\"ja_JP\">%s</display-name>\n", ServiceName);
358                 fprintf(outfile, "  </channel>\n");
359         }
360         for(lp = 0 ; lp < staCount ; lp++){
361                 GetEIT(infile, outfile, &pStas[lp], secs, SECCOUNT);
362         }
363         fprintf(outfile, "</tv>\n");
364         if(inclose) {
365                 fclose(infile);
366         }
367
368         if(outclose) {
369                 fclose(outfile);
370         }
371         if(act){
372                 free(pStas);
373                 svtcur = svttop ;       //���
374                 while(svtcur != NULL){
375                         svtsave = svtcur->next ;
376                         free(svtcur);
377                         svtcur = svtsave ;
378                 }
379         }
380
381         return 0;
382 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed