RTBFBridge.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. class RTBFBridge extends BridgeAbstract {
  3. const NAME = "RTBF Bridge";
  4. const URI = "http://www.rtbf.be/auvio/emissions/";
  5. const CACHE_TIMEOUT = 21600; //6h
  6. const DESCRIPTION = "Returns the newest RTBF videos by series ID";
  7. const MAINTAINER = "Frenzie";
  8. const PARAMETERS = array( array(
  9. 'c'=>array(
  10. 'name'=>'series id',
  11. 'exampleValue'=>9500,
  12. 'required'=>true
  13. )
  14. ));
  15. public function collectData(){
  16. $html = '';
  17. $limit = 10;
  18. $count = 0;
  19. $html = getSimpleHTMLDOM($this->getURI())
  20. or returnServerError('Could not request RTBF.');
  21. foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) {
  22. if($count >= $limit) {
  23. break;
  24. }
  25. $item = array();
  26. $item['id'] = $element->getAttribute('data-id');
  27. $item['uri'] = self::URI.'detail?id='.$item['id'];
  28. $thumbnailUriSrcSet = explode(',', $element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset'));
  29. $thumbnailUriLastSrc = end($thumbnailUriSrcSet);
  30. $thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0];
  31. $item['title'] = trim($element->find('h3',0)->plaintext) . ' - ' . trim($element->find('h4',0)->plaintext);
  32. $item['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime'));
  33. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>';
  34. $this->items[] = $item;
  35. $count++;
  36. }
  37. }
  38. public function getURI(){
  39. return self::URI.'detail?id='.$this->getInput('c');
  40. }
  41. public function getName(){
  42. return $this->getInput('c') .' - RTBF Bridge';
  43. }
  44. }