RadioRaiBridge.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class RadioRaiBridge extends BridgeAbstract {
  3. const MAINTAINER = 'boyska';
  4. const NAME = 'Radio Rai';
  5. const URI = 'https://www.raiplayradio.it';
  6. const CACHE_TIMEOUT = 900; // 15min
  7. const DESCRIPTION = 'Segui le trasmissioni radio rai con feed/podcast valido';
  8. const PARAMETERS = array( array(
  9. 'txname' => array(
  10. 'name' => 'txname',
  11. 'required' => true
  12. )
  13. ));
  14. private function getFinalURL($url) {
  15. $ch = curl_init($url);
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. curl_setopt($ch, CURLOPT_NOBODY, true);
  18. curl_setopt($ch, CURLOPT_HEADER, true);
  19. $ret = curl_exec($ch);
  20. if($ret === FALSE) {
  21. return null;
  22. }
  23. $redirect = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
  24. if($redirect === false) return $url;
  25. return $redirect;
  26. }
  27. public function collectData(){
  28. $html = getSimpleHTMLDOM($this->getURI())
  29. or returnServerError('No results for this query.');
  30. foreach($html->find('[data-mediapolis]') as $episode) {
  31. // var_dump($episode);
  32. $title = $episode->getAttribute('data-title');
  33. if($title === FALSE) { continue; }
  34. $audiourl = $episode->getAttribute('data-mediapolis');
  35. $item = array();
  36. $item['author'] = $this->getInput('txname');
  37. $item['title'] = $title;
  38. $item['content'] = $episode->plaintext;
  39. $item['enclosures'] = [ $this::getFinalURL($audiourl) ];
  40. $item['uri'] = $this::URI . $episode->getAttribute('data-href');
  41. $this->items[] = $item;
  42. }
  43. }
  44. public function getURI(){
  45. return 'https://www.raiplayradio.it/programmi/' . $this->getInput('txname') . '/archivio/puntate/';
  46. }
  47. public function getName(){
  48. if($this->getInput('txname')) {
  49. return 'Radio Rai - ' . $this->getInput('txname');
  50. }
  51. return parent::getName();
  52. }
  53. }