Zmiana sposobu pobierania programu telewizyjnego w związku ze zmianami na stronie wp.pl oraz poprawa linku do kanału RSS Dziennika Internautów.
2 files modified
1 files added
| | |
| | | http://wiadomosci.wp.pl/ver,rss,rss.xml wp w,wirtualna polska,wp.pl WP.pl |
| | | http://kanaly.rss.interia.pl/fakty.xml interia i,interia.pl Interia.pl |
| | | http://rss.gazeta.pl/pub/rss/wiadomosci.xml gazeta g,gazeta.pl Gazeta.pl |
| | | http://rss.di.com.pl/di.rss di dziennik internautow Dziennik Internautów |
| | | http://feeds.feedburner.com/glowny-di di dziennik internautow Dziennik Internautów |
| | | http://hacking.pl/rss.xml hacking h,hacking.pl Hacking.pl |
| | | http://linuxnews.pl/feed/ linuxnews l,linux,ln,linux news,linuxnews.pl Linux News |
| | | http://rss.bankier.pl/wiadomosci/wiadomosci.xml bankier bankier.pl Bankier.pl |
| | |
| | | <?php |
| | | require_once('wp_parse.php'); |
| | | |
| | | echo STAR.'Pobieranie programu TV...'; |
| | | $stations = array( |
| | | 1 => 'TVP 1', |
| | |
| | | fwrite($out, '<?xml version="1.0" encoding="UTF-8" ?> |
| | | <tv date="'.date('YmdHis O').'" generator-info-name="BotGG" generator-info-url="http://jacekk.info/botgg"> |
| | | '); |
| | | $address = 'http://tv.wp.pl/program.html?stid=$STATION&date=$DATE&time='; |
| | | $address = 'http://tv.wp.pl/program.html?stid=$STATION'; |
| | | $date = date('Y-m-d'); |
| | | |
| | | $counter = 0; |
| | | foreach($stations as $num => $station) { |
| | | fwrite($out, ' <channel id="'.$station.'"> |
| | | <display-name>'.$station.'</display-name> |
| | | </channel> |
| | | '); |
| | | for($i=0; $i<7; $i++) { |
| | | echo "\r".STAR.'Pobieranie programu TV: '.floor(($counter*7 + $i)/$NUMOF*100).'%'; |
| | | echo "\r".STAR.'Pobieranie programu TV: '.floor($counter/$NUMOF*100).'%'; |
| | | |
| | | $timestamp = strtotime('+'.$i.' days'); |
| | | $date = date('Y-m-d', $timestamp); |
| | | if(!file_exists('./cache/'.$num.'_'.$date) || filesize('./cache/'.$num.'_'.$date)==0) { |
| | | curl_setopt($c, CURLOPT_URL, str_replace(array('$DATE', '$STATION'), array($date, $num), $address)); |
| | | curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30); |
| | |
| | | return; |
| | | } |
| | | |
| | | $data = str_replace(array('id="C_TSR-franc"', 'id="C_TSR-2-franc"', 'id="stationId"', 'id="searchForm"', '&'), array('', '', '', '', '&'), $data); |
| | | |
| | | file_put_contents('./cache/'.$num.'_'.$date, $data); |
| | | unset($data); |
| | | } |
| | | |
| | | $doc = new DOMDocument; |
| | | $doc->loadHTMLFile('./cache/'.$num.'_'.$date); |
| | | $doc = $doc->getElementById('bxNazwaBoksu')->childNodes; |
| | | @$doc->loadHTMLFile('./cache/'.$num.'_'.$date); |
| | | |
| | | foreach($doc as $el) { |
| | | if($el instanceof DOMElement) { |
| | | $doc = $el->childNodes; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | $last_time = 0; |
| | | $last_timestamp = 0; |
| | | foreach($doc as $el) { |
| | | if(!$el instanceof DOMElement || substr($el->getAttribute('class'), 0, 7)!='program') continue; |
| | | |
| | | $time = $el->getElementsByTagName('strong')->item(0)->childNodes->item(0)->nodeValue; |
| | | $time = trim($time); |
| | | if($last_time>(int)$time) { |
| | | $timestamp = strtotime('+1 day', $timestamp); |
| | | } |
| | | $last_time = (int)$time; |
| | | $timestamp = strtotime($time, $timestamp); |
| | | |
| | | if($last_timestamp) { |
| | | fwrite($out, ' <programme channel="'.$station.'" start="'.date('YmdHis O', $last_timestamp).'" stop="'.date('YmdHis O', $timestamp).'"> |
| | | <title>'.$name.'</title> |
| | | <desc/> |
| | | </programme> |
| | | '); |
| | | } |
| | | |
| | | $name = $el->getElementsByTagName('h4')->item(0)->childNodes->item(0)->childNodes->item(0)->nodeValue; |
| | | $name = htmlspecialchars(trim($name), ENT_COMPAT, 'UTF-8'); |
| | | $last_timestamp = $timestamp; |
| | | } |
| | | |
| | | fwrite($out, ' <programme channel="'.$station.'" start="'.date('YmdHis O', $timestamp).'" stop="'.date('YmdHis O', $timestamp+3600).'"> |
| | | <title>'.$name.'</title> |
| | | <desc/> |
| | | </programme> |
| | | '); |
| | | |
| | | unset($doc); |
| | | } |
| | | $wp = new wp_parse($doc); |
| | | $wp->xmltv($station, $out); |
| | | |
| | | $counter++; |
| | | } |
New file |
| | |
| | | <?php |
| | | class wp_parse { |
| | | var $document, $xpath, $context; |
| | | var $name = ''; |
| | | var $program = array(); |
| | | var $months = array( |
| | | 'stycznia' => 1, |
| | | 'lutego' => 2, |
| | | 'marca' => 3, |
| | | 'kwietnia' => 4, |
| | | 'maja' => 5, |
| | | 'czerwca' => 6, |
| | | 'lipca' => 7, |
| | | 'sierpnia' => 8, |
| | | 'września' => 9, |
| | | 'października' => 10, |
| | | 'listopada' => 11, |
| | | 'grudnia' => 12, |
| | | ); |
| | | var $weekdays = array( |
| | | 'poniedziałek' => 'next Monday', |
| | | 'wtorek' => 'next Tuesday', |
| | | 'środa' => 'next Wednesday', |
| | | 'czwartek' => 'next Thursday', |
| | | 'piątek' => 'next Friday', |
| | | 'sobota' => 'next Saturday', |
| | | 'niedziela' => 'next Sunday', |
| | | ); |
| | | |
| | | function __construct(DOMDocument $document) { |
| | | $this->document = $document; |
| | | $this->xpath = new DOMXPath($this->document); |
| | | |
| | | $context = $this->xpath->query('//div[@class="ramowka"]'); |
| | | if($context->length != 1) { |
| | | throw new Exception('Nie znaleziono ramówki!'); |
| | | } |
| | | $this->context = $context->item(0); |
| | | |
| | | $name = $this->xpath->query('.//h2[@class="sh2"]//span//text()', $this->context); |
| | | if($name->length != 1) { |
| | | throw new Exception('Nie znaleziono nazwy stacji, błędny HTML.'); |
| | | } |
| | | $this->name = $name->item(0)->nodeValue; |
| | | } |
| | | |
| | | function parse_date($date) { |
| | | if($date == 'dzisiaj') { |
| | | // 'dzisiaj' |
| | | return mktime(0, 0, 0); |
| | | } |
| | | elseif(isset($this->weekdays[$date])) { |
| | | // data przyszła: 'poniedziałek' |
| | | return strtotime($this->weekdays[$date]); |
| | | } |
| | | else |
| | | { |
| | | // data przeszła: 'pon. 18 czerwca' |
| | | $date = explode(' ', $date); |
| | | if(!isset($this->months[$date[2]])) { |
| | | throw new Exception('Nie udało się przetworzyć daty ('.$date[2].')'); |
| | | } |
| | | $timestamp = mktime(0, 0, 0, $this->months[$date[2]], $date[1]); |
| | | |
| | | // Należy przesunąć się o rok |
| | | if($timestamp > time()) { |
| | | $timestamp = strtotime('-1 year', $timestamp); |
| | | } |
| | | |
| | | return $timestamp; |
| | | } |
| | | } |
| | | |
| | | function xmltv($id, $fp) { |
| | | $program = array(); |
| | | |
| | | $days_dom = $this->xpath->query('.//ul[@class="lsDay"]//li', $this->context); |
| | | $days = array(); |
| | | foreach($days_dom as $day) { |
| | | $days[] = $this->parse_date($day->nodeValue); |
| | | $program[] = array(); |
| | | } |
| | | unset($days_dom, $day); |
| | | |
| | | $hours_dom = $this->xpath->query('.//div[@class="hrsOut"]//div[@class="hour"]', $this->context); |
| | | // Kolejne wiersze (pełne godziny) |
| | | foreach($hours_dom as $in => $hour) { |
| | | $days_dom = $this->xpath->query('.//div[@class="col"]', $hour); |
| | | // Zbiory programów w tych godzinach dla kolejnych dni |
| | | foreach($days_dom as $num => $day) { |
| | | $programs_dom = $this->xpath->query('.//div[@class="prog"]', $day); |
| | | // Kolejne programy w danej godzinie i dniu |
| | | foreach($programs_dom as $n => $programs) { |
| | | $godzina = $this->xpath->query('.//div[@class="tm"]', $programs)->item(0)->textContent; |
| | | $nazwa = $this->xpath->query('.//h3', $programs)->item(0)->textContent; |
| | | $opis = $this->xpath->query('.//p', $programs)->item(0)->textContent; |
| | | |
| | | $program[$num][] = array($godzina, $nazwa, $opis); |
| | | } |
| | | unset($programs_dom, $programs); |
| | | } |
| | | unset($days_dom, $day); |
| | | } |
| | | unset($hours_dom, $hour, $godzina, $nazwa, $opis); |
| | | |
| | | fwrite($fp, "\t".'<channel id="'.$id.'">'."\n" |
| | | ."\t\t".'<display-name>'.htmlspecialchars($this->name).'</display-name>'."\n" |
| | | ."\t".'</channel>'."\n"); |
| | | |
| | | $last_timestamp = $timestamp = $days[0]; |
| | | $last_prog = NULL; |
| | | foreach($program as $day => $dayprog) { |
| | | foreach($dayprog as $prog) { |
| | | $timestamp = strtotime($prog[0], $last_timestamp); |
| | | if($timestamp < $last_timestamp) { |
| | | $timestamp = strtotime('+1 day', $timestamp); |
| | | } |
| | | while($timestamp < $days[$day]) { |
| | | $timestamp = strtotime('+1 day', $timestamp); |
| | | } |
| | | |
| | | if($program !== NULL) |
| | | fwrite($fp, "\t".'<programme channel="'.$id.'" start="'.date('YmdHis O', $last_timestamp).'"' |
| | | .' stop="'.date('YmdHis O', $timestamp).'">'."\n" |
| | | ."\t\t".'<title>'.htmlspecialchars($last_prog[1]).'</title>'."\n" |
| | | ."\t\t".'<desc>'.htmlspecialchars($last_prog[2]).'</desc>'."\n" |
| | | ."\t".'</programme>'."\n"); |
| | | |
| | | $last_prog = $prog; |
| | | $last_timestamp = $timestamp; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ?> |