root/trunk/epgdumpr2/epgdump.c

リビジョン 139, 16.0 kB (コミッタ: sorshi, コミット時期: 12 年 前)

スペースシャワーTVプラス、追加

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