You are here

public static function MediaInternetSoundCloudHandler::validId in Media: SoundCloud 7.2

Check if a SoundCloud audio ID is valid.

Return value

boolean TRUE if the audio ID is valid, or throws a MediaInternetValidationException otherwise.

1 call to MediaInternetSoundCloudHandler::validId()
MediaInternetSoundCloudHandler::parse in includes/MediaInternetSoundCloudHandler.inc

File

includes/MediaInternetSoundCloudHandler.inc, line 103
Extends the MediaInternetBaseHandler class to handle SoundCloud audio.

Class

MediaInternetSoundCloudHandler
Implementation of MediaInternetBaseHandler.

Code

public static function validId($uri) {
  $uri = file_stream_wrapper_uri_normalize($uri);
  $external_url = file_create_url($uri);
  $oembed_url = url('http://soundcloud.com/oembed', array(
    'query' => array(
      'url' => $external_url,
      'format' => 'json',
    ),
  ));
  $response = drupal_http_request($oembed_url, array(
    'method' => 'HEAD',
  ));
  if ($response->code == 401) {
    throw new MediaInternetValidationException('Embedding has been disabled for this SoundCloud audio.');
  }
  elseif ($response->code != 200) {
    throw new MediaInternetValidationException('The SoundCloud audio ID is invalid or the audio is either private or has been deleted.');
  }
  return TRUE;
}