2016-12-06 14:12:42 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class MixCloudBridge extends BridgeAbstract {
|
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'Alexis CHEMEL';
|
|
|
|
const NAME = 'MixCloud';
|
|
|
|
const URI = 'https://mixcloud.com/';
|
2016-12-06 14:12:42 +03:00
|
|
|
const CACHE_TIMEOUT = 3600; // 1h
|
2017-02-11 18:16:56 +03:00
|
|
|
const DESCRIPTION = 'Returns latest musics on user stream';
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const PARAMETERS = array(array(
|
|
|
|
'u' => array(
|
|
|
|
'name' => 'username',
|
|
|
|
'required' => true,
|
|
|
|
)
|
|
|
|
));
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
public function getName(){
|
2017-02-15 00:20:55 +03:00
|
|
|
if(!is_null($this->getInput('u'))){
|
|
|
|
return 'MixCloud - ' . $this->getInput('u');
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
public function collectData(){
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-03-19 14:04:59 +03:00
|
|
|
$html = getSimpleHTMLDOM(self::URI . $this->getInput('u'))
|
2017-02-11 18:16:56 +03:00
|
|
|
or returnServerError('Could not request MixCloud.');
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-03-19 14:04:59 +03:00
|
|
|
foreach($html->find('section.card') as $element){
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$item = array();
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-03-19 14:04:59 +03:00
|
|
|
$item['uri'] = self::URI . $element->find('hgroup.card-title h1 a', 0)->getAttribute('href');
|
2017-02-11 18:16:56 +03:00
|
|
|
$item['title'] = html_entity_decode(
|
2017-03-19 14:04:59 +03:00
|
|
|
$element->find('hgroup.card-title h1 a span', 0)->getAttribute('title'),
|
2017-02-11 18:16:56 +03:00
|
|
|
ENT_QUOTES
|
|
|
|
);
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-03-19 14:04:59 +03:00
|
|
|
$image = $element->find('a.album-art img', 0);
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
if($image){
|
|
|
|
$item['content'] = '<img src="' . $image->getAttribute('src') . '" />';
|
|
|
|
}
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-03-19 14:04:59 +03:00
|
|
|
$item['author'] = trim($element->find('hgroup.card-title h2 a', 0)->innertext);
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-12-06 14:12:42 +03:00
|
|
|
}
|