commit | author | age
|
8bd4d9
|
1 |
<?php |
8091b1
|
2 |
require_once('wp_parse.php'); |
JK |
3 |
|
8bd4d9
|
4 |
echo STAR.'Pobieranie programu TV...'; |
JK |
5 |
$stations = array( |
|
6 |
1 => 'TVP 1', |
|
7 |
2 => 'TVP 2', |
|
8 |
233 => 'TVP3 Regionalna', |
|
9 |
3 => 'TV Polonia', |
|
10 |
368 => 'TVP Kultura', |
|
11 |
5 => 'Polsat', |
|
12 |
6 => 'Polsat 2', |
|
13 |
435 => 'Polsat Cafe', |
|
14 |
224 => 'Polsat Sport', |
|
15 |
17 => 'TVN', |
|
16 |
238 => 'TVN 7', |
|
17 |
151 => 'TVN 24', |
|
18 |
375 => 'TVN Style', |
|
19 |
265 => 'TVN Turbo', |
|
20 |
18 => 'TV 4', |
|
21 |
235 => 'TV Puls', |
|
22 |
16 => 'Tele 5', |
|
23 |
355 => 'Animal Planet', |
|
24 |
15 => 'Planete', |
|
25 |
360 => 'National Geographic', |
|
26 |
67 => 'Discovery', |
|
27 |
356 => 'Discovery Science', |
|
28 |
186 => 'Discovery World', |
|
29 |
14 => 'HBO', |
|
30 |
201 => 'HBO 2', |
|
31 |
421 => 'HBO Comedy', |
|
32 |
13 => 'CANAL+', |
|
33 |
179 => 'CANAL+ Film', |
|
34 |
183 => 'CANAL+ Sport', |
|
35 |
437 => 'Cinemax', |
|
36 |
442 => 'Cinemax 2', |
|
37 |
436 => 'FilmBox', |
|
38 |
433 => 'FilmBox Extra', |
|
39 |
174 => 'AXN', |
587c93
|
40 |
538 => 'AXN Black', |
JK |
41 |
539 => 'AXN White', |
8bd4d9
|
42 |
85 => 'Ale Kino!', |
JK |
43 |
205 => 'Kino Polska', |
|
44 |
403 => 'TCM', |
|
45 |
400 => 'Comedy Central', |
|
46 |
42 => 'Eurosport', |
|
47 |
364 => 'Eurosport 2', |
|
48 |
420 => 'BBC Entertainment', |
|
49 |
448 => 'BBC Knowledge', |
|
50 |
415 => 'BBC Lifestyle', |
|
51 |
71 => 'Zone Club', |
|
52 |
78 => 'Zone Romantica', |
|
53 |
267 => 'Zone Europa', |
|
54 |
84 => 'Zone Reality', |
|
55 |
434 => 'Religia TV', |
|
56 |
449 => 'BBC CBeebies', |
|
57 |
74 => 'Jetix', |
|
58 |
217 => 'ZigZap', |
|
59 |
361 => 'Cartoon Network', |
|
60 |
); |
3f9e0f
|
61 |
$NUMOF = count($stations); |
8bd4d9
|
62 |
|
4e13c0
|
63 |
ini_set('mbstring.substitute_character', 'none'); |
JK |
64 |
|
8bd4d9
|
65 |
$c = curl_init(); |
JK |
66 |
$out = fopen('./xmltv-pre.xml', 'w'); |
|
67 |
fwrite($out, '<?xml version="1.0" encoding="UTF-8" ?> |
|
68 |
<tv date="'.date('YmdHis O').'" generator-info-name="BotGG" generator-info-url="http://jacekk.info/botgg"> |
|
69 |
'); |
8091b1
|
70 |
$address = 'http://tv.wp.pl/program.html?stid=$STATION'; |
JK |
71 |
$date = date('Y-m-d'); |
8bd4d9
|
72 |
|
JK |
73 |
$counter = 0; |
|
74 |
foreach($stations as $num => $station) { |
8091b1
|
75 |
echo "\r".STAR.'Pobieranie programu TV: '.floor($counter/$NUMOF*100).'%'; |
JK |
76 |
|
|
77 |
if(!file_exists('./cache/'.$num.'_'.$date) || filesize('./cache/'.$num.'_'.$date)==0) { |
|
78 |
curl_setopt($c, CURLOPT_URL, str_replace(array('$DATE', '$STATION'), array($date, $num), $address)); |
|
79 |
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30); |
|
80 |
curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); |
|
81 |
curl_setopt($c, CURLOPT_MAXREDIRS, 5); |
|
82 |
curl_setopt($c, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; pl-PL; rv:1.9.2) Gecko/20100101 Firefox/3.6')); |
|
83 |
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE); |
|
84 |
$data = curl_exec($c); |
|
85 |
if(!$data) { |
|
86 |
echo FAIL; |
|
87 |
return; |
8bd4d9
|
88 |
} |
JK |
89 |
|
4e13c0
|
90 |
$data = mb_convert_encoding($data, 'UTF-8', 'UTF-8'); |
8091b1
|
91 |
file_put_contents('./cache/'.$num.'_'.$date, $data); |
JK |
92 |
unset($data); |
8bd4d9
|
93 |
} |
JK |
94 |
|
4e13c0
|
95 |
$doc = new DOMDocument('1.0', 'utf-8'); |
8091b1
|
96 |
@$doc->loadHTMLFile('./cache/'.$num.'_'.$date); |
JK |
97 |
|
|
98 |
$wp = new wp_parse($doc); |
|
99 |
$wp->xmltv($station, $out); |
|
100 |
|
8bd4d9
|
101 |
$counter++; |
JK |
102 |
} |
|
103 |
|
|
104 |
fwrite($out, '</tv>'); |
|
105 |
fclose($out); |
|
106 |
|
|
107 |
rename('./xmltv-pre.xml', './xmltv-utf.xml'); |
|
108 |
|
|
109 |
echo "\r".STAR.'Pobieranie programu TV: 100%'.OK; |
|
110 |
|
|
111 |
echo STAR.'Czyszczenie cache...'; |
|
112 |
$today = strtotime('today'); |
|
113 |
foreach(glob('./cache/*') as $garbage) { |
|
114 |
$date = substr($garbage, -10); |
|
115 |
if(strtotime($date) < $today) { |
|
116 |
unlink($garbage); |
|
117 |
} |
|
118 |
} |
|
119 |
echo OK; |
c786da
|
120 |
?> |