[RTBFBridge] add getURI() + code simplification

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-29 22:04:26 +02:00
parent 08158825d9
commit 9f82adc87b

View file

@ -1,7 +1,7 @@
<?php
class RTBFBridge extends BridgeAbstract {
public $name = "RTBF Bridge";
public $uri = "http://www.rtbf.be/auvio/emissions";
public $uri = "http://www.rtbf.be/auvio/emissions/";
public $description = "Returns the newest RTBF videos by series ID";
public $maintainer = "Frenzie";
@ -18,32 +18,33 @@ class RTBFBridge extends BridgeAbstract {
$limit = 10;
$count = 0;
if ($this->getInput('c')) {
$html = $this->getSimpleHTMLDOM('http://www.rtbf.be/auvio/emissions/detail?id='.$this->getInput('c')) or $this->returnServerError('Could not request RTBF.');
$html = $this->getSimpleHTMLDOM($this->getURI())
or $this->returnServerError('Could not request RTBF.');
foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) {
if($count < $limit) {
$item = array();
$item['id'] = $element->getAttribute('data-id');
$item['uri'] = 'http://www.rtbf.be/auvio/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++;
}
}
}
else {
$this->returnClientError('You must specify a series id.');
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'] = $this->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 $this->uri.'detail?id='.$this->getInput('c');
}
public function getName(){
return (!empty($this->request) ? $this->request .' - ' : '') .'RTBF Bridge';
return $this->getInput('c') .' - RTBF Bridge';
}
public function getCacheDuration(){