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 |
449 => 'BBC CBeebies', |
|
56 |
74 => 'Jetix', |
|
57 |
217 => 'ZigZap', |
|
58 |
361 => 'Cartoon Network', |
|
59 |
); |
3f9e0f
|
60 |
$NUMOF = count($stations); |
8bd4d9
|
61 |
|
4e13c0
|
62 |
ini_set('mbstring.substitute_character', 'none'); |
JK |
63 |
|
8bd4d9
|
64 |
$c = curl_init(); |
JK |
65 |
$out = fopen('./xmltv-pre.xml', 'w'); |
|
66 |
fwrite($out, '<?xml version="1.0" encoding="UTF-8" ?> |
|
67 |
<tv date="'.date('YmdHis O').'" generator-info-name="BotGG" generator-info-url="http://jacekk.info/botgg"> |
|
68 |
'); |
8091b1
|
69 |
$address = 'http://tv.wp.pl/program.html?stid=$STATION'; |
JK |
70 |
$date = date('Y-m-d'); |
8bd4d9
|
71 |
|
JK |
72 |
$counter = 0; |
|
73 |
foreach($stations as $num => $station) { |
8091b1
|
74 |
echo "\r".STAR.'Pobieranie programu TV: '.floor($counter/$NUMOF*100).'%'; |
JK |
75 |
|
|
76 |
if(!file_exists('./cache/'.$num.'_'.$date) || filesize('./cache/'.$num.'_'.$date)==0) { |
|
77 |
curl_setopt($c, CURLOPT_URL, str_replace(array('$DATE', '$STATION'), array($date, $num), $address)); |
|
78 |
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30); |
|
79 |
curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); |
|
80 |
curl_setopt($c, CURLOPT_MAXREDIRS, 5); |
|
81 |
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')); |
|
82 |
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE); |
|
83 |
$data = curl_exec($c); |
|
84 |
if(!$data) { |
|
85 |
echo FAIL; |
|
86 |
return; |
8bd4d9
|
87 |
} |
JK |
88 |
|
4e13c0
|
89 |
$data = mb_convert_encoding($data, 'UTF-8', 'UTF-8'); |
8091b1
|
90 |
file_put_contents('./cache/'.$num.'_'.$date, $data); |
JK |
91 |
unset($data); |
8bd4d9
|
92 |
} |
JK |
93 |
|
4e13c0
|
94 |
$doc = new DOMDocument('1.0', 'utf-8'); |
8091b1
|
95 |
@$doc->loadHTMLFile('./cache/'.$num.'_'.$date); |
JK |
96 |
|
4aa627
|
97 |
try { |
JK |
98 |
$wp = new wp_parse($doc); |
|
99 |
$wp->xmltv($station, $out); |
|
100 |
} catch(Exception $e) { |
|
101 |
echo "\n"; |
|
102 |
echo STAR.'Błąd przy pobieraniu danych dla kanału '.$station.FAIL."\n"; |
|
103 |
continue; |
|
104 |
} |
8091b1
|
105 |
|
8bd4d9
|
106 |
$counter++; |
JK |
107 |
} |
|
108 |
|
|
109 |
fwrite($out, '</tv>'); |
|
110 |
fclose($out); |
|
111 |
|
|
112 |
rename('./xmltv-pre.xml', './xmltv-utf.xml'); |
|
113 |
|
|
114 |
echo "\r".STAR.'Pobieranie programu TV: 100%'.OK; |
|
115 |
|
|
116 |
echo STAR.'Czyszczenie cache...'; |
|
117 |
$today = strtotime('today'); |
|
118 |
foreach(glob('./cache/*') as $garbage) { |
|
119 |
$date = substr($garbage, -10); |
|
120 |
if(strtotime($date) < $today) { |
|
121 |
unlink($garbage); |
|
122 |
} |
|
123 |
} |
|
124 |
echo OK; |
c786da
|
125 |
?> |