RTBFBridge.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class RTBFBridge extends BridgeAbstract {
  3. const NAME = 'RTBF Bridge';
  4. const URI = 'http://www.rtbf.be/auvio/';
  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(
  29. ',',
  30. $element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset')
  31. );
  32. $thumbnailUriLastSrc = end($thumbnailUriSrcSet);
  33. $thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0];
  34. $item['title'] = trim($element->find('h3', 0)->plaintext)
  35. . ' - '
  36. . trim($element->find('h4', 0)->plaintext);
  37. $item['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime'));
  38. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>';
  39. $this->items[] = $item;
  40. $count++;
  41. }
  42. }
  43. public function getURI(){
  44. if(!is_null($this->getInput('c'))) {
  45. return self::URI . 'emissions/detail?id=' . $this->getInput('c');
  46. }
  47. return parent::getURI() . 'emissions/';
  48. }
  49. public function getName(){
  50. if(!is_null($this->getInput('c'))) {
  51. return $this->getInput('c') .' - RTBF Bridge';
  52. }
  53. return parent::getName();
  54. }
  55. }