2014-07-24 15:51:42 +04:00
|
|
|
<?php
|
|
|
|
class SoundCloudBridge extends BridgeAbstract{
|
2015-09-09 01:13:56 +03:00
|
|
|
|
2015-11-05 18:50:18 +03:00
|
|
|
public function loadMetadatas() {
|
|
|
|
|
|
|
|
$this->maintainer = "kranack";
|
|
|
|
$this->name = "Soundcloud Bridge";
|
|
|
|
$this->uri = "http://www.soundcloud.com/";
|
|
|
|
$this->description = "Returns 10 newest music from user profile";
|
|
|
|
|
2016-08-22 02:25:56 +03:00
|
|
|
$this->parameters[] = array(
|
|
|
|
'u'=>array(
|
|
|
|
'name'=>'username',
|
|
|
|
'required'=>true
|
|
|
|
)
|
|
|
|
);
|
2015-11-05 18:50:18 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const CLIENT_ID = '0aca19eae3843844e4053c6d8fdb7875';
|
2015-09-09 01:13:56 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
|
|
|
$param=$this->parameters[$this->queriedContext];
|
2015-09-09 01:13:56 +03:00
|
|
|
|
2016-08-27 17:02:12 +03:00
|
|
|
$res = json_decode($this->getContents(
|
|
|
|
'https://api.soundcloud.com/resolve?url=http://www.soundcloud.com/'
|
|
|
|
. urlencode($param['u']['value'])
|
|
|
|
.'&client_id=' . self::CLIENT_ID
|
|
|
|
)) or $this->returnServerError('No results for this query');
|
|
|
|
$tracks = json_decode($this->getContents(
|
|
|
|
'https://api.soundcloud.com/users/'
|
|
|
|
. urlencode($res->id)
|
|
|
|
.'/tracks?client_id=' . self::CLIENT_ID
|
|
|
|
)) or $this->returnServerError('No results for this user');
|
2014-07-24 15:51:42 +04:00
|
|
|
|
|
|
|
for ($i=0; $i < 10; $i++) {
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['author'] = $tracks[$i]->user->username .' - '. $tracks[$i]->title;
|
|
|
|
$item['title'] = $tracks[$i]->user->username .' - '. $tracks[$i]->title;
|
|
|
|
$item['content'] = '<audio src="'. $tracks[$i]->uri .'/stream?client_id='. self::CLIENT_ID .'">';
|
2016-08-27 17:02:12 +03:00
|
|
|
$item['id'] = 'https://soundcloud.com/'
|
|
|
|
. urlencode($param['u']['value']) .'/'
|
|
|
|
. urlencode($tracks[$i]->permalink);
|
|
|
|
$item['uri'] = 'https://soundcloud.com/'
|
|
|
|
. urlencode($param['u']['value']) .'/'
|
|
|
|
. urlencode($tracks[$i]->permalink);
|
2014-07-24 15:51:42 +04:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2015-09-09 01:13:56 +03:00
|
|
|
|
2014-07-24 15:51:42 +04:00
|
|
|
}
|
|
|
|
public function getName(){
|
2016-08-27 17:02:12 +03:00
|
|
|
$param=$this->parameters[$this->queriedContext];
|
|
|
|
return $this->name .' - '. $param['u']['value'];
|
2014-07-24 15:51:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
2015-09-10 01:00:29 +03:00
|
|
|
return 600; // 10 minutes
|
2014-07-24 15:51:42 +04:00
|
|
|
}
|
|
|
|
}
|