2014-07-24 15:51:42 +04:00
|
|
|
<?php
|
2017-02-11 18:16:56 +03:00
|
|
|
class SoundCloudBridge extends BridgeAbstract {
|
2015-09-09 01:13:56 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'kranack';
|
|
|
|
const NAME = 'Soundcloud Bridge';
|
|
|
|
const URI = 'https://soundcloud.com/';
|
2016-09-25 18:04:28 +03:00
|
|
|
const CACHE_TIMEOUT = 600; // 10min
|
2017-02-11 18:16:56 +03:00
|
|
|
const DESCRIPTION = 'Returns 10 newest music from user profile';
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const PARAMETERS = array( array(
|
|
|
|
'u' => array(
|
|
|
|
'name' => 'username',
|
|
|
|
'required' => true
|
|
|
|
)
|
|
|
|
));
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2017-02-11 18:16:56 +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(){
|
2015-09-09 01:13:56 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$res = json_decode(getContents(
|
|
|
|
'https://api.soundcloud.com/resolve?url=http://www.soundcloud.com/'
|
|
|
|
. urlencode($this->getInput('u'))
|
|
|
|
. '&client_id='
|
|
|
|
. self::CLIENT_ID
|
|
|
|
)) or returnServerError('No results for this query');
|
|
|
|
|
|
|
|
$tracks = json_decode(getContents(
|
|
|
|
'https://api.soundcloud.com/users/'
|
|
|
|
. urlencode($res->id)
|
|
|
|
. '/tracks?client_id='
|
|
|
|
. self::CLIENT_ID
|
|
|
|
)) or returnServerError('No results for this user');
|
|
|
|
|
|
|
|
for($i = 0; $i < 10; $i++){
|
|
|
|
$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
|
|
|
|
. '">';
|
|
|
|
|
|
|
|
$item['id'] = self::URI
|
|
|
|
. urlencode($this->getInput('u'))
|
|
|
|
. '/'
|
|
|
|
. urlencode($tracks[$i]->permalink);
|
|
|
|
$item['uri'] = self::URI
|
|
|
|
. urlencode($this->getInput('u'))
|
|
|
|
. '/'
|
|
|
|
. urlencode($tracks[$i]->permalink);
|
|
|
|
$this->items[] = $item;
|
2014-07-24 15:51:42 +04:00
|
|
|
}
|
2015-09-09 01:13:56 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
2014-07-24 15:51:42 +04:00
|
|
|
public function getName(){
|
2017-02-15 00:20:55 +03:00
|
|
|
if(!is_null($this->getInput('u'))){
|
|
|
|
return self::NAME . ' - ' . $this->getInput('u');
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
2014-07-24 15:51:42 +04:00
|
|
|
}
|
|
|
|
}
|