Source of file SoundcloudApi.php
Size: 1,651 Bytes - Last Modified: 2021-12-23T10:07:40+00:00
/var/www/docs.ssmods.com/process/src/code/providers/SoundcloudApi.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | <?php /** * Implementation for the SoundCloud api. Read more of the api on * http://developers.soundcloud.com/docs/api * @author Christian Blank <c.blank@notthatbad.net> */ class SoundCloudApi implements IApiProvider { /** * The public api key. * @var string */ private $key = null; /** * The base path for the api. * @var string */ private static $api_base = 'http://api.soundcloud.com/'; /** * The path for the request. * @var string */ private static $api_path = 'resolve.json'; /** * The domain to check against the requested url. * @var string */ private static $domain = 'soundcloud.com'; public function __construct() { $this->key = Config::inst()->get('SoundCloudApi', 'Key'); } public function search($url) { $requestUrl = self::$api_base . self::$api_path . "?url=$url&client_id=" . $this->key; $jsonData = Injector::inst()->get('Fetcher')->fetch($requestUrl); $data = json_decode($jsonData, true); if ($data['kind'] == 'track') { $result = [ 'Type' => 'soundcloud', 'Video' => $data['id'], 'Image' => $data['artwork_url'], 'Title' => $data['title'], 'Description' => $data['description'] ]; return ParseResult::create($result); } return ParseResult::create(['Error' => "'$requestUrl' can't be found on soundclound.com"]); } public function isProvided($url) { return strpos(parse_url($url, PHP_URL_HOST), self::$domain) !== false; } } |