2014-07-24 13:51:42 +02:00
|
|
|
<?php
|
|
|
|
class SoundCloudBridge extends BridgeAbstract{
|
2015-09-09 00:13:56 +02:00
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
public $maintainer = "kranack";
|
|
|
|
public $name = "Soundcloud Bridge";
|
|
|
|
public $uri = "http://www.soundcloud.com/";
|
|
|
|
public $description = "Returns 10 newest music from user profile";
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
public $parameters = array( array(
|
|
|
|
'u'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'username',
|
|
|
|
'required'=>true
|
2016-08-27 21:03:26 +02:00
|
|
|
)
|
|
|
|
));
|
2015-11-05 16:50:18 +01:00
|
|
|
|
|
|
|
const CLIENT_ID = '0aca19eae3843844e4053c6d8fdb7875';
|
2015-09-09 00:13:56 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2015-09-09 00:13:56 +02:00
|
|
|
|
2016-08-27 16:02:12 +02:00
|
|
|
$res = json_decode($this->getContents(
|
|
|
|
'https://api.soundcloud.com/resolve?url=http://www.soundcloud.com/'
|
2016-08-28 01:25:33 +02:00
|
|
|
. urlencode($this->getInput('u'))
|
2016-08-27 16:02:12 +02:00
|
|
|
.'&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 13:51:42 +02:00
|
|
|
|
|
|
|
for ($i=0; $i < 10; $i++) {
|
2016-08-22 18:55:59 +02: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 16:02:12 +02:00
|
|
|
$item['id'] = 'https://soundcloud.com/'
|
2016-08-28 01:25:33 +02:00
|
|
|
. urlencode($this->getInput('u')) .'/'
|
2016-08-27 16:02:12 +02:00
|
|
|
. urlencode($tracks[$i]->permalink);
|
|
|
|
$item['uri'] = 'https://soundcloud.com/'
|
2016-08-28 01:25:33 +02:00
|
|
|
. urlencode($this->getInput('u')) .'/'
|
2016-08-27 16:02:12 +02:00
|
|
|
. urlencode($tracks[$i]->permalink);
|
2014-07-24 13:51:42 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2015-09-09 00:13:56 +02:00
|
|
|
|
2014-07-24 13:51:42 +02:00
|
|
|
}
|
|
|
|
public function getName(){
|
2016-08-28 01:25:33 +02:00
|
|
|
return $this->name .' - '. $this->getInput('u');
|
2014-07-24 13:51:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
2015-09-10 00:00:29 +02:00
|
|
|
return 600; // 10 minutes
|
2014-07-24 13:51:42 +02:00
|
|
|
}
|
|
|
|
}
|