Improve Soundcloud bridge (#1500)

* [SoundcloudBridge] Add playlist support, migrate to `api-v2`
This commit is contained in:
somini 2020-07-05 18:49:46 +01:00 committed by GitHub
parent 3ad126cdf2
commit 976445b490
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,15 @@ class SoundCloudBridge extends BridgeAbstract {
'u' => array(
'name' => 'username',
'required' => true
),
't' => array(
'name' => 'type',
'type' => 'list',
'defaultValue' => 'tracks',
'values' => array(
'Tracks' => 'tracks',
'Playlists' => 'playlists'
)
)
));
@ -19,13 +28,13 @@ class SoundCloudBridge extends BridgeAbstract {
public function collectData(){
$res = $this->apiGet('resolve', array(
'url' => 'http://www.soundcloud.com/' . $this->getInput('u')
'url' => 'https://soundcloud.com/' . $this->getInput('u')
)) or returnServerError('No results for this query');
$this->feedIcon = $res->avatar_url;
$tracks = $this->apiGet('users/' . urlencode($res->id) . '/tracks')
or returnServerError('No results for this user');
$tracks = $this->apiGet('users/' . urlencode($res->id) . '/' . $this->getInput('t'))->collection
or returnServerError('No results for this user/playlist');
$numTracks = min(count($tracks), 10);
for($i = 0; $i < $numTracks; $i++) {
@ -33,7 +42,7 @@ class SoundCloudBridge extends BridgeAbstract {
$item['author'] = $tracks[$i]->user->username;
$item['title'] = $tracks[$i]->user->username . ' - ' . $tracks[$i]->title;
$item['timestamp'] = strtotime($tracks[$i]->created_at);
$item['content'] = $tracks[$i]->description;
$item['content'] = nl2br($tracks[$i]->description);
$item['enclosures'] = array($tracks[$i]->uri
. '/stream?client_id='
. $this->getClientID());
@ -117,7 +126,7 @@ class SoundCloudBridge extends BridgeAbstract {
}
private function buildAPIURL($endpoint, $parameters){
return 'https://api.soundcloud.com/'
return 'https://api-v2.soundcloud.com/'
. $endpoint
. '?'
. http_build_query($parameters);