Skip to content

Commit ba9c4ec

Browse files
committed
Improvements for soundcloud #9
1 parent 0c7d2b1 commit ba9c4ec

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

Embed/Adapters/Adapter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ abstract class Adapter {
1616
'minImageHeight' => 0,
1717
'getBiggerImage' => false,
1818
'getBiggerIcon' => false,
19-
'facebookAccessToken' => null
19+
'facebookAccessToken' => null,
20+
'soundcloudClientId' => null
2021
);
2122

2223
abstract protected function initProviders (Url $Url);

Embed/Adapters/Soundcloud.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Adapter to provide information from soundcloud.com api
4+
*/
5+
namespace Embed\Adapters;
6+
7+
use Embed\Url;
8+
use Embed\Providers\Provider;
9+
10+
class Soundcloud extends Webpage implements AdapterInterface {
11+
public $Api;
12+
13+
static public function check (Url $Url) {
14+
return $Url->match(array(
15+
'https?://soundcloud.com/*'
16+
));
17+
}
18+
19+
protected function initProviders (Url $Url) {
20+
parent::initProviders($Url);
21+
22+
$this->Api = new Provider();
23+
24+
$UrlApi = new Url('http://api.soundcloud.com/resolve.json');
25+
$UrlApi->setParameter('client_id', isset($this->options['soundcloudClientId']) ? $this->options['soundcloudClientId'] : 'YOUR_CLIENT_ID');
26+
$UrlApi->setParameter('url', $Url->getUrl());
27+
28+
if ($json = $UrlApi->getJsonContent()) {
29+
$this->Api->set($json);
30+
}
31+
}
32+
33+
public function getTitle () {
34+
return $this->Api->get('title') ?: parent::getTitle();
35+
}
36+
37+
public function getDescription () {
38+
return $this->Api->get('description') ?: parent::getDescription();
39+
}
40+
41+
public function getUrl () {
42+
return $this->Api->get('permalink_url') ?: parent::getUrl();
43+
}
44+
45+
public function getImages () {
46+
$images = parent::getImages();
47+
48+
if (!$this->Api->get('artwork_url') && ($img = $this->Api->get('user', 'avatar_url'))) {
49+
array_unshift($images, str_replace('-large.jpg', '-t500x500.jpg', $img));
50+
}
51+
52+
return array_unique($images);
53+
}
54+
55+
public function getAuthorName () {
56+
return $this->Api->get('user', 'username') ?: parent::getAuthorName();
57+
}
58+
59+
public function getAuthorUrl () {
60+
return $this->Api->get('user', 'permalink_url') ?: parent::getAuthorUrl();
61+
}
62+
}

0 commit comments

Comments
 (0)