You are here

function pmpapi_pull_get_enclosure_url in Public Media Platform API Integration 7

Determines the URL of a given PMP enclosure object.

This functions solely exists to deal with the way APM points to audio files in the PMP.

Parameters

object $enclosure: A PMP enclosure object

Return value

string The URI of the enclosure file

2 calls to pmpapi_pull_get_enclosure_url()
PMPAPIDrupalPull::createEnclosureFile in pmpapi_pull/classes/PMPAPIDrupalPull.php
Creates a file object from a PMP object.
pmpapi_pull_preview in pmpapi_pull/pmpapi_pull.pages.inc
Page callback: Previews a pulled doc without creating a node.

File

pmpapi_pull/pmpapi_pull.module, line 363
Allows admins to pull content from the PMP API, and turn PMP docs into (locally-stored, independent) drupal entities.

Code

function pmpapi_pull_get_enclosure_url($enclosure) {
  if (pmpapi_url_is_m3u($enclosure->href)) {

    // NPR enclosures are M3Us; we need to crack that file and extract the MP3
    $uri = pmpapi_get_mp3_from_m3u($enclosure->href);
  }
  elseif (stripos($enclosure->href, 'apm-audio:') !== 0) {
    $uri = $enclosure->href;
  }
  else {
    $file = $enclosure->meta->api->href;
    $call = drupal_http_request($file, array(
      'timeout' => 3,
    ));
    if ($call->code == '200') {
      $json = json_decode($call->data);
      if (!empty($json->{$enclosure->href}->podcast->http_file_path)) {
        $uri = $json->{$enclosure->href}->podcast->http_file_path;
      }
      else {
        drupal_set_message(t('Unable to extract an http_file_path for the file:') . ' ' . check_url($enclosure->href), 'warning');
      }
    }
    else {
      drupal_set_message(t('Unable to extract a URL for the file:') . ' ' . check_url($enclosure->href), 'warning');
    }
  }
  return $uri;
}