aboutsummaryrefslogtreecommitdiff
path: root/plugins/video_zencoder/video_zencoder.module
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/video_zencoder/video_zencoder.module')
-rw-r--r--plugins/video_zencoder/video_zencoder.module104
1 files changed, 104 insertions, 0 deletions
diff --git a/plugins/video_zencoder/video_zencoder.module b/plugins/video_zencoder/video_zencoder.module
new file mode 100644
index 0000000..042b2c3
--- /dev/null
+++ b/plugins/video_zencoder/video_zencoder.module
@@ -0,0 +1,104 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Provides wrapper functions for the s3 amazon webservices.
+ */
+
+/*
+ * Implementation of hook_perm().
+ */
+function video_zencoder_perm() {
+ return array('administer zencoder');
+}
+/*
+ * Implmentation of hook_help().
+ */
+function video_zencoder_help($path, $arg) {
+ switch($path) {
+ case 'admin/settings/video/amazon_s3':
+ $output = t('Use Amazon Simple Storage Service (Amazon S3) to store your video files. This free\'s up bandwidth from your site, providing a faster experience for your users. Simply enable this module and enter your authentication details and your done!');
+ return $output;
+ }
+}
+
+/*
+ * Implementation of hook_menu().
+ */
+function video_zencoder_menu() {
+ $items = array();
+ $items['admin/settings/video/zencoder'] = array(
+ 'title' => 'Zencoder',
+ 'description' => 'Configure your Zencoder API settings.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('video_zencoder_admin_settings'),
+ 'access arguments' => array('administer site configuration'),
+ 'file' => 'video_zencoder.admin.inc',
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 10,
+ );
+ return $items;
+}
+
+/*
+ * Implementation of hook_cron().
+ */
+function video_zencoder_cron() {
+ module_load_include('inc', 'video_zencoder', '/includes/zencoder');
+ $zc = new video_zencoder_api;
+// $s3->connect();
+// // Lets run our queue.
+ $zc->queue();
+}
+
+/**
+ * Implementation of hook_file_delete().
+ */
+function video_zencoder_file_delete($file) {
+ module_load_include('inc', 'video_zencoder', '/includes/zencoder');
+ $zc = new video_zencoder_api;
+ // Lets run delete.
+ $zc->delete($file->fid);
+}
+
+/*
+ * Implementation of hook_form_alter().
+ */
+function video_zencoder_form_alter(&$form, &$form_state, $form_id) {
+ if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
+ $form['buttons']['submit']['#submit'][] = 'video_zencoder_node_update_submit';
+ }
+}
+
+/*
+ * Submit hanlder to update our s3 table to include the node id.
+ */
+function video_zencoder_node_update_submit($form, &$form_state) {
+ //lets update our video rending table to include the node id created
+ if (isset($form_state['nid']) && isset($form_state['values']['video_id']) && is_array($form_state['values']['video_id'])) {
+ foreach($form_state['values']['video_id'] as $fid) {
+ //lets update our table to include the nid
+ db_query("UPDATE {video_zencoder} SET nid=%d WHERE fid=%d", $form_state['nid'], $fid);
+ }
+ }
+}
+
+/**
+ * Implementing hook_video_submit
+ * @param <type> $element
+ * @param <type> $form_state
+ */
+function video_zencoder_video_submit(&$element, &$form_state) {
+ $file = $element['#value'];
+ //we need to check if this fid has already been added to the database AND that there is in fact a fid
+ if (is_array($file) && isset($file['fid']) && !empty($file['fid'])) {
+ module_load_include('inc', 'video_zencoder', '/includes/zencoder');
+ $zc = new video_zencoder_api;
+ // Lets verify that we haven't added this video already. Multiple validation fails will cause this to be ran more than once
+ if(!$video = $zc->verify($file['fid'])) {
+ // Video has not been added to the queue yet so lets add it.
+ $zc->insert($file['fid'], $jobid);
+ drupal_set_message(t('Video submission queued for transfer to your Zencoder Transcoding server. Will be there shortly.'));
+ }
+ }
+} \ No newline at end of file