2014-07-24 13:51:42 +02:00
|
|
|
<?php
|
2017-02-11 16:16:56 +01:00
|
|
|
class SoundCloudBridge extends BridgeAbstract {
|
2015-09-09 00:13:56 +02:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
const MAINTAINER = 'kranack';
|
|
|
|
const NAME = 'Soundcloud Bridge';
|
|
|
|
const URI = 'https://soundcloud.com/';
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 600; // 10min
|
2017-02-11 16:16:56 +01:00
|
|
|
const DESCRIPTION = 'Returns 10 newest music from user profile';
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
const PARAMETERS = array( array(
|
|
|
|
'u' => array(
|
|
|
|
'name' => 'username',
|
|
|
|
'required' => true
|
|
|
|
)
|
|
|
|
));
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2019-03-12 13:29:11 +01:00
|
|
|
const CLIENT_ID = 'W0KEWWILAjDiRH89X0jpwzuq6rbSK08R';
|
2015-09-09 00:13:56 +02:00
|
|
|
|
2019-06-01 15:04:43 +02:00
|
|
|
private $feedIcon = null;
|
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2015-09-09 00:13:56 +02:00
|
|
|
|
2017-02-11 16:16:56 +01: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');
|
|
|
|
|
2019-06-01 15:04:43 +02:00
|
|
|
$this->feedIcon = $res->avatar_url;
|
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
$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');
|
|
|
|
|
2018-12-26 20:35:05 +01:00
|
|
|
$numTracks = min(count($tracks), 10);
|
|
|
|
for($i = 0; $i < $numTracks; $i++) {
|
2017-02-11 16:16:56 +01:00
|
|
|
$item = array();
|
2018-12-10 21:35:18 +01:00
|
|
|
$item['author'] = $tracks[$i]->user->username;
|
2017-02-11 16:16:56 +01:00
|
|
|
$item['title'] = $tracks[$i]->user->username . ' - ' . $tracks[$i]->title;
|
2018-12-10 21:35:18 +01:00
|
|
|
$item['timestamp'] = strtotime($tracks[$i]->created_at);
|
|
|
|
$item['content'] = $tracks[$i]->description;
|
2018-12-04 16:16:19 +01:00
|
|
|
$item['enclosures'] = array($tracks[$i]->uri
|
|
|
|
. '/stream?client_id='
|
|
|
|
. self::CLIENT_ID);
|
2017-02-11 16:16:56 +01:00
|
|
|
|
|
|
|
$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 13:51:42 +02:00
|
|
|
}
|
2015-09-09 00:13:56 +02:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
}
|
2018-12-26 21:58:07 +01:00
|
|
|
|
2019-06-01 15:04:43 +02:00
|
|
|
public function getIcon(){
|
|
|
|
if ($this->feedIcon) {
|
|
|
|
return $this->feedIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getIcon();
|
|
|
|
}
|
|
|
|
|
2014-07-24 13:51:42 +02:00
|
|
|
public function getName(){
|
2017-07-29 19:28:00 +02:00
|
|
|
if(!is_null($this->getInput('u'))) {
|
2017-02-14 22:20:55 +01:00
|
|
|
return self::NAME . ' - ' . $this->getInput('u');
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
2014-07-24 13:51:42 +02:00
|
|
|
}
|
|
|
|
}
|