RTBFBridge.php 1.9 KB

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