commit | author | age
|
8bd4d9
|
1 |
<?php |
JK |
2 |
echo STAR.'Pobieranie programu TV...'; |
|
3 |
$stations = array( |
|
4 |
1 => 'TVP 1', |
|
5 |
2 => 'TVP 2', |
|
6 |
233 => 'TVP3 Regionalna', |
|
7 |
3 => 'TV Polonia', |
|
8 |
368 => 'TVP Kultura', |
|
9 |
5 => 'Polsat', |
|
10 |
6 => 'Polsat 2', |
|
11 |
435 => 'Polsat Cafe', |
|
12 |
224 => 'Polsat Sport', |
|
13 |
17 => 'TVN', |
|
14 |
238 => 'TVN 7', |
|
15 |
151 => 'TVN 24', |
|
16 |
375 => 'TVN Style', |
|
17 |
265 => 'TVN Turbo', |
|
18 |
18 => 'TV 4', |
|
19 |
235 => 'TV Puls', |
|
20 |
16 => 'Tele 5', |
|
21 |
355 => 'Animal Planet', |
|
22 |
15 => 'Planete', |
|
23 |
360 => 'National Geographic', |
|
24 |
67 => 'Discovery', |
|
25 |
356 => 'Discovery Science', |
|
26 |
186 => 'Discovery World', |
|
27 |
14 => 'HBO', |
|
28 |
201 => 'HBO 2', |
|
29 |
421 => 'HBO Comedy', |
|
30 |
13 => 'CANAL+', |
|
31 |
179 => 'CANAL+ Film', |
|
32 |
183 => 'CANAL+ Sport', |
|
33 |
437 => 'Cinemax', |
|
34 |
442 => 'Cinemax 2', |
|
35 |
436 => 'FilmBox', |
|
36 |
433 => 'FilmBox Extra', |
|
37 |
174 => 'AXN', |
|
38 |
418 => 'AXN Crime', |
|
39 |
416 => 'AXN Sci-fi', |
|
40 |
85 => 'Ale Kino!', |
|
41 |
205 => 'Kino Polska', |
|
42 |
403 => 'TCM', |
|
43 |
400 => 'Comedy Central', |
|
44 |
42 => 'Eurosport', |
|
45 |
364 => 'Eurosport 2', |
|
46 |
420 => 'BBC Entertainment', |
|
47 |
448 => 'BBC Knowledge', |
|
48 |
415 => 'BBC Lifestyle', |
|
49 |
71 => 'Zone Club', |
|
50 |
78 => 'Zone Romantica', |
|
51 |
267 => 'Zone Europa', |
|
52 |
84 => 'Zone Reality', |
|
53 |
434 => 'Religia TV', |
|
54 |
449 => 'BBC CBeebies', |
|
55 |
74 => 'Jetix', |
|
56 |
217 => 'ZigZap', |
|
57 |
361 => 'Cartoon Network', |
|
58 |
); |
|
59 |
$NUMOF = count($stations)*7; |
|
60 |
|
|
61 |
$c = curl_init(); |
|
62 |
$out = fopen('./xmltv-pre.xml', 'w'); |
|
63 |
fwrite($out, '<?xml version="1.0" encoding="UTF-8" ?> |
|
64 |
<tv date="'.date('YmdHis O').'" generator-info-name="BotGG" generator-info-url="http://jacekk.info/botgg"> |
|
65 |
'); |
|
66 |
$address = 'http://tv.wp.pl/program.html?stid=$STATION&date=$DATE&time='; |
|
67 |
|
|
68 |
$counter = 0; |
|
69 |
foreach($stations as $num => $station) { |
|
70 |
fwrite($out, ' <channel id="'.$station.'"> |
|
71 |
<display-name>'.$station.'</display-name> |
|
72 |
</channel> |
|
73 |
'); |
|
74 |
for($i=0; $i<7; $i++) { |
|
75 |
echo "\r".STAR.'Pobieranie programu TV: '.floor(($counter*7 + $i)/$NUMOF*100).'%'; |
|
76 |
|
|
77 |
$timestamp = strtotime('+'.$i.' days'); |
|
78 |
$date = date('Y-m-d', $timestamp); |
|
79 |
if(!file_exists('./cache/'.$num.'_'.$date) || filesize('./cache/'.$num.'_'.$date)==0) { |
|
80 |
curl_setopt($c, CURLOPT_URL, str_replace(array('$DATE', '$STATION'), array($date, $num), $address)); |
|
81 |
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30); |
|
82 |
curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); |
|
83 |
curl_setopt($c, CURLOPT_MAXREDIRS, 5); |
|
84 |
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')); |
|
85 |
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE); |
|
86 |
$data = curl_exec($c); |
|
87 |
if(!$data) { |
|
88 |
echo FAIL; |
|
89 |
return; |
|
90 |
} |
|
91 |
|
|
92 |
$data = str_replace(array('id="C_TSR-franc"', 'id="C_TSR-2-franc"', 'id="stationId"', 'id="searchForm"', '&'), array('', '', '', '', '&'), $data); |
|
93 |
|
|
94 |
file_put_contents('./cache/'.$num.'_'.$date, $data); |
|
95 |
unset($data); |
|
96 |
} |
|
97 |
|
|
98 |
$doc = new DOMDocument; |
|
99 |
$doc->loadHTMLFile('./cache/'.$num.'_'.$date); |
|
100 |
$doc = $doc->getElementById('bxNazwaBoksu')->childNodes; |
|
101 |
|
|
102 |
foreach($doc as $el) { |
|
103 |
if($el instanceof DOMElement) { |
|
104 |
$doc = $el->childNodes; |
|
105 |
break; |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
$last_time = 0; |
|
110 |
$last_timestamp = 0; |
|
111 |
foreach($doc as $el) { |
|
112 |
if(!$el instanceof DOMElement || substr($el->getAttribute('class'), 0, 7)!='program') continue; |
|
113 |
|
|
114 |
$time = $el->getElementsByTagName('strong')->item(0)->childNodes->item(0)->nodeValue; |
|
115 |
$time = trim($time); |
|
116 |
if($last_time>(int)$time) { |
|
117 |
$timestamp = strtotime('+1 day', $timestamp); |
|
118 |
} |
|
119 |
$last_time = (int)$time; |
|
120 |
$timestamp = strtotime($time, $timestamp); |
|
121 |
|
|
122 |
if($last_timestamp) { |
|
123 |
fwrite($out, ' <programme channel="'.$station.'" start="'.date('YmdHis O', $last_timestamp).'" stop="'.date('YmdHis O', $timestamp).'"> |
|
124 |
<title>'.$name.'</title> |
|
125 |
<desc/> |
|
126 |
</programme> |
|
127 |
'); |
|
128 |
} |
|
129 |
|
|
130 |
$name = $el->getElementsByTagName('h4')->item(0)->childNodes->item(0)->childNodes->item(0)->nodeValue; |
|
131 |
$name = htmlspecialchars(trim($name), ENT_COMPAT, 'UTF-8'); |
|
132 |
$last_timestamp = $timestamp; |
|
133 |
} |
|
134 |
|
|
135 |
fwrite($out, ' <programme channel="'.$station.'" start="'.date('YmdHis O', $timestamp).'" stop="'.date('YmdHis O', $timestamp+3600).'"> |
|
136 |
<title>'.$name.'</title> |
|
137 |
<desc/> |
|
138 |
</programme> |
|
139 |
'); |
|
140 |
|
|
141 |
unset($doc); |
|
142 |
} |
|
143 |
|
|
144 |
$counter++; |
|
145 |
} |
|
146 |
|
|
147 |
fwrite($out, '</tv>'); |
|
148 |
fclose($out); |
|
149 |
|
|
150 |
rename('./xmltv-pre.xml', './xmltv-utf.xml'); |
|
151 |
|
|
152 |
echo "\r".STAR.'Pobieranie programu TV: 100%'.OK; |
|
153 |
|
|
154 |
echo STAR.'Czyszczenie cache...'; |
|
155 |
$today = strtotime('today'); |
|
156 |
foreach(glob('./cache/*') as $garbage) { |
|
157 |
$date = substr($garbage, -10); |
|
158 |
if(strtotime($date) < $today) { |
|
159 |
unlink($garbage); |
|
160 |
} |
|
161 |
} |
|
162 |
echo OK; |
|
163 |
?> |