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