1
0

RTBFBridge.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class RTBFBridge extends BridgeAbstract {
  3. public function loadMetadatas() {
  4. $this->name = "RTBF Bridge";
  5. $this->uri = "http://www.rtbf.be/auvio/emissions";
  6. $this->description = "Returns the newest RTBF videos by series ID";
  7. $this->maintainer = "Frenzie";
  8. $this->update = "2016-08-09";
  9. $this->parameters[] =
  10. '[
  11. {
  12. "type" : "text",
  13. "identifier" : "c",
  14. "name" : "series id",
  15. "exampleValue" : "9500",
  16. "required" : "required"
  17. }
  18. ]';
  19. }
  20. public function collectData(array $param) {
  21. $html = '';
  22. $limit = 10;
  23. $count = 0;
  24. if (isset($param['c'])) {
  25. $html = $this->file_get_html('http://www.rtbf.be/auvio/emissions/detail?id='.$param['c']) or $this->returnError('Could not request RTBF.', 404);
  26. foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) {
  27. if($count < $limit) {
  28. $item = new \Item();
  29. $item->id = $element->getAttribute('data-id');
  30. $item->uri = 'http://www.rtbf.be/auvio/detail?id='.$item->id;
  31. $thumbnailUriSrcSet = explode(',', $element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset'));
  32. $thumbnailUriLastSrc = end($thumbnailUriSrcSet);
  33. $thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0];
  34. $item->title = trim($element->find('h3',0)->plaintext) . ' - ' . trim($element->find('h4',0)->plaintext);
  35. $item->timestamp = strtotime($element->find('time', 0)->getAttribute('datetime'));
  36. $item->content = '<a href="' . $item->uri . '"><img src="' . $thumbnailUri . '" /></a>';
  37. $this->items[] = $item;
  38. $count++;
  39. }
  40. }
  41. }
  42. else {
  43. $this->returnError('You must specify a series id.', 400);
  44. }
  45. }
  46. public function getName(){
  47. return (!empty($this->request) ? $this->request .' - ' : '') .'RTBF Bridge';
  48. }
  49. public function getURI(){
  50. return 'http://www.rtbf.be/auvio/emissions';
  51. }
  52. public function getCacheDuration(){
  53. return 21600; // 6 hours
  54. }
  55. }