aboutsummaryrefslogtreecommitdiff
path: root/plugins/video_optmetadata/video_optmetadata.module
blob: 1ab62652a88db96633754a347235b12a7bf90171 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
//$Id$
/**
 * @file
 * Enable addition of optional metadata on video nodes created by video module.
 *
 * @author Fabio Varesano <fvaresano at yahoo dot it>
 * porting to Drupal 6
 * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw@gmail.com>
 * @todo
 */


/**
 * Implementation of hook_help().
 */
function video_optmetadata_help($path, $arg) {
  switch ($path) {
    case 'admin/modules#description':
      return t('Enable addition of optional metadata on video nodes created by video module. Optional metadata are Video Bitrate, Audio Bitrate, Audio Sampling Rate and Audio Channels.');
  }
}


/**
 * Implementation of hook_perm().
 */
function video_optmetadata_perm() {
  return array('insert optional metadata');
}



/**
 * Implementation of hook_form_alter()
 * We use this to add some fields to the video creation form.
 * In those fields users will be able to insert some video metadatas.
 */
function video_optmetadata_form_alter(&$form, &$form_state, $form_id) {

  if($form_id == 'video_node_form' && isset($form['video']) && user_access('insert optional metadata')) {

    // get node object
    $node = $form['#node'];
    // Optional Video Metadata. We display this group expanded only if displaying of optional metadata is enabled.
    $form['metadata'] = array(
      '#type' => 'fieldset',
      '#title' => t('Optional Metadata'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => -16,
      '#description' => t('Insert here the metadata informations.')
    );
    $form['metadata']['video_bitrate'] = array(
      '#type' => 'textfield',
      '#title' => t('Video Bitrate'),
      '#length' => 11,
      '#maxlength' => 11,
      '#default_value' => $node->video_bitrate,
      '#description' => t('Video bitrate in kbits/sec.')
    );
    $form['metadata']['audio_bitrate'] = array(
      '#type' => 'textfield',
      '#title' => t('Audio Bitrate'),
      '#length' => 11,
      '#maxlength' => 11,
      '#default_value' => $node->audio_bitrate,
      '#description' => t('Audio bitrate in kbits/sec.')
    );
    $form['metadata']['audio_sampling_rate'] = array(
      '#type' => 'select',
      '#title' => t('Audio Sampling Rate'),
      '#options' => array(0 => 'none', 8000 => '8 kHz', 11025 => '11 kHz', 16000 => '16 kHz', 22050 => '22 kHz', 32000 => '32 kHz', 44100 => '44.1 kHz', 48000 => '48 kHz', 96000 => '96 kHz', 192400 => '192 kHz'),
      '#default_value' => $node->audio_sampling_rate,
      '#description' => t('Integer value of audio sampling rate in Hz.')
    );
    $form['metadata']['audio_channels'] = array(
      '#type' => 'select',
      '#title' => t('Audio Channels'),
      '#options' => array('' => 'none', '5.1' => t('5.1'), 'stereo' => t('Stereo'), 'mono' => t('Mono')),
      '#default_value' => $node->audio_channels
    );
    // Ends Video Optional Metadata
  }
}


/**
 * Implementation of hook_nodeapi()
 */
function video_optmetadata_nodeapi(&$node, $op, $teaser) {
  if($node->type == 'video') {
    switch ($op) {
      case 'view':
        //Add the HTML formatted output of the optional video metadata to the bottom.
        $node->body .= theme('video_metadata', $node);
      break;
    }
  }
}

/**
 * Display optional metadata (Video and Audio bitrate,..) on the view page.
 *
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 $node->video_bitrate, $node->audio_bitrate, $node->audio_sampling_rate, $node->audio_channels,
 */
function theme_video_metadata($node) {
  //Make sure atleast one fields had data.
  if ($node->video_bitrate != 0 or $node->audio_bitrate != 0 or $node->audio_sampling_rate != 0 or $node->audio_channels != 0) {
    $output = "\n\n<div class=\"video_metadata\">\n";
    $output .= '  <div class="title"><h2>'.t('Video Metadata')."</h2></div>\n";
    if($node->video_bitrate != 0) {
      $fields[] = array('title' => t('Video Bitrate') . ':', 'body' => $node->video_bitrate . ' ' . t('kbits/sec'));
    }
    if($node->audio_bitrate != 0) {
      $fields[] = array('title' => t('Audio Bitrate') . ':', 'body' => $node->audio_bitrate . ' ' . t('kbits/sec'));
    }
    if($node->audio_sampling_rate != 0) {
      $fields[] = array('title' => t('Audio Sampling Rate') . ':', 'body' => $node->audio_sampling_rate . ' ' . t('Hz'));
    }
    if($node->audio_channels != '') {
      $fields[] = array('title' => t('Audio Channels') . ':', 'body' => $node->audio_channels);
    }
    $output .= theme('video_fields', $fields); //Generate the fields HTML.
    $output .= '</div>'; //Closing div video_metadata
  }
  else { //If all the fields are blank then display nothing.
    $output = '';
  }
  return $output;
}

/**
 * Implementation of hook_theme().
 */
function video_optmetadata_theme() {
  return array(
    'video_metadata' => array(
      'arguments' => array('node' => NULL),
    ),
  );
}