<?php

/**
 * @file
 * Provides a stream wrapper and formatters appropriate for accessing and
 * displaying YouTube videos.
 */

// Load all YouTube file formatters.
require_once dirname(__FILE__) . '/includes/media_youtube.formatters.inc';

/**
 * Implements hook_media_internet_providers().
 */
function media_youtube_media_internet_providers() {
  return array(
    'MediaInternetYouTubeHandler' => array(
      'title' => t('YouTube'),
    ),
  );
}

/**
 * Implements hook_stream_wrappers().
 */
function media_youtube_stream_wrappers() {
  return array(
    'youtube' => array(
      'name' => t('YouTube videos'),
      'class' => 'MediaYouTubeStreamWrapper',
      'description' => t('Remote videos hosted on the YouTube video-sharing website.'),
      'type' => STREAM_WRAPPERS_READ_VISIBLE,
    ),
  );
}

/**
 * Implements hook_theme().
 */
function media_youtube_theme($existing, $type, $theme, $path) {
  return array(
    'media_youtube_video' => array(
      'variables' => array('uri' => NULL, 'options' => array()),
      'file' => 'media_youtube.theme.inc',
      'path' => $path . '/themes',
      'template' => 'media-youtube-video',
    ),
  );
}

/**
 * Implements hook_media_parse().
 *
 * @todo This hook should be deprecated. Refactor Media module to not call it
 * any more, since media_internet should be able to automatically route to the
 * appropriate handler.
 */
function media_youtube_media_parse($embed_code) {
  $handler = new MediaInternetYouTubeHandler($embed_code);
  return $handler->parse($embed_code);
}

/**
 * Implements hook_file_mimetype_mapping_alter().
 */
function media_youtube_file_mimetype_mapping_alter(&$mapping) {
  $mapping['mimetypes'][] = 'video/youtube';
}

/**
 * Implements hook_ctools_plugin_api().
 */
function media_youtube_ctools_plugin_api($module, $api) {
  if ($module == 'file_entity' && $api == 'file_default_displays') {
    return array('version' => 1);
  }
}
