rss-bridge/bridges/RTBFBridge.php
Pierre Mazière f1fb95b257 [core] extract BridgeAbstract methods to make them functions
- returnError, returnServerError, returnClientError ,debugMessage are
  moved to lib/error.php

- getContents, getSimpleHTMLDOM, getSimpleHTMLDOMCached are moved to
  lib/contents.php

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
2016-09-25 23:22:33 +02:00

53 lignes
1,6 Kio
PHP

<?php
class RTBFBridge extends BridgeAbstract {
const NAME = "RTBF Bridge";
const URI = "http://www.rtbf.be/auvio/emissions/";
const DESCRIPTION = "Returns the newest RTBF videos by series ID";
const MAINTAINER = "Frenzie";
const PARAMETERS = array( array(
'c'=>array(
'name'=>'series id',
'exampleValue'=>9500,
'required'=>true
)
));
public function collectData(){
$html = '';
$limit = 10;
$count = 0;
$html = getSimpleHTMLDOM($this->getURI())
or returnServerError('Could not request RTBF.');
foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) {
if($count >= $limit) {
break;
}
$item = array();
$item['id'] = $element->getAttribute('data-id');
$item['uri'] = self::URI.'detail?id='.$item['id'];
$thumbnailUriSrcSet = explode(',', $element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset'));
$thumbnailUriLastSrc = end($thumbnailUriSrcSet);
$thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0];
$item['title'] = trim($element->find('h3',0)->plaintext) . ' - ' . trim($element->find('h4',0)->plaintext);
$item['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime'));
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>';
$this->items[] = $item;
$count++;
}
}
public function getURI(){
return self::URI.'detail?id='.$this->getInput('c');
}
public function getName(){
return $this->getInput('c') .' - RTBF Bridge';
}
public function getCacheDuration(){
return 21600; // 6 hours
}
}