MixCloudBridge.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. class MixCloudBridge extends BridgeAbstract {
  3. const MAINTAINER = 'Alexis CHEMEL';
  4. const NAME = 'MixCloud';
  5. const URI = 'https://www.mixcloud.com';
  6. const CACHE_TIMEOUT = 3600; // 1h
  7. const DESCRIPTION = 'Returns latest musics on user stream';
  8. const PARAMETERS = array(array(
  9. 'u' => array(
  10. 'name' => 'username',
  11. 'required' => true,
  12. )
  13. ));
  14. public function getName(){
  15. if(!is_null($this->getInput('u'))) {
  16. return 'MixCloud - ' . $this->getInput('u');
  17. }
  18. return parent::getName();
  19. }
  20. public function collectData(){
  21. ini_set('user_agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0');
  22. $html = getSimpleHTMLDOM(self::URI . '/' . $this->getInput('u'))
  23. or returnServerError('Could not request MixCloud.');
  24. foreach($html->find('section.card') as $element) {
  25. $item = array();
  26. $item['uri'] = self::URI . $element->find('hgroup.card-title h1 a', 0)->getAttribute('href');
  27. $item['title'] = html_entity_decode(
  28. $element->find('hgroup.card-title h1 a span', 0)->getAttribute('title'),
  29. ENT_QUOTES
  30. );
  31. $image = $element->find('a.album-art img', 0);
  32. if($image) {
  33. $item['content'] = '<img src="' . $image->getAttribute('src') . '" />';
  34. }
  35. $item['author'] = trim($element->find('hgroup.card-title h2 a', 0)->innertext);
  36. $this->items[] = $item;
  37. }
  38. }
  39. }