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';
|
2017-12-07 00:17:46 +03:00
|
|
|
const URI = 'https://www.mixcloud.com';
|
2022-04-03 10:51:41 +03:00
|
|
|
const API_URI = 'https://api.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,
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => 'DJJazzyJeff',
|
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 getName(){
|
2017-07-29 20:28:00 +03:00
|
|
|
if(!is_null($this->getInput('u'))) {
|
2017-02-15 00:20:55 +03:00
|
|
|
return 'MixCloud - ' . $this->getInput('u');
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2022-04-03 10:51:41 +03:00
|
|
|
private static function compareDate($stream1, $stream2) {
|
|
|
|
return (strtotime($stream1['timestamp']) < strtotime($stream2['timestamp']) ? 1 : -1);
|
|
|
|
}
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2022-04-03 10:51:41 +03:00
|
|
|
public function collectData(){
|
|
|
|
$user = urlencode($this->getInput('u'));
|
|
|
|
// Get Cloudcasts
|
|
|
|
$mixcloudUri = self::API_URI . $user . '/cloudcasts/';
|
|
|
|
$content = getContents($mixcloudUri);
|
|
|
|
$casts = json_decode($content)->data;
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2022-04-03 10:51:41 +03:00
|
|
|
// Get Listens
|
|
|
|
$mixcloudUri = self::API_URI . $user . '/listens/';
|
|
|
|
$content = getContents($mixcloudUri);
|
|
|
|
$listens = json_decode($content)->data;
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2022-04-03 10:51:41 +03:00
|
|
|
$streams = array_merge($casts, $listens);
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2022-04-03 10:51:41 +03:00
|
|
|
foreach($streams as $stream) {
|
|
|
|
$item = array();
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2022-04-03 10:51:41 +03:00
|
|
|
$item['uri'] = $stream->url;
|
|
|
|
$item['title'] = $stream->name;
|
|
|
|
$item['content'] = '<img src="' . $stream->pictures->thumbnail . '" />';
|
|
|
|
$item['author'] = $stream->user->name;
|
|
|
|
$item['timestamp'] = $stream->created_time;
|
2016-12-06 14:12:42 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2022-04-03 10:51:41 +03:00
|
|
|
|
|
|
|
// Sort items by date
|
|
|
|
usort($this->items, array('MixCloudBridge', 'compareDate'));
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
2016-12-06 14:12:42 +03:00
|
|
|
}
|