-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideo.install
317 lines (305 loc) · 9.4 KB
/
video.install
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
use Drupal\video\Transcoder;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* @file
* Provides installation schema for video.module
* @author Heshan Wanigasooriya <[email protected]>
*/
/**
* Implements hook_schema().
*/
function video_schema() {
// video queue
$schema['video_queue'] = array(
'description' => 'Store video transcoding queue.',
'fields' => array(
'vid' => array(
'description' => t('Video id, the primary identifier'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'fid' => array(
'description' => 'The {file_managed}.fid being referenced in this field.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'entity_type' => array(
'description' => 'The entity_type of the video.',
'type' => 'varchar',
'length' => 128,
'default' => 'node',
),
'entity_id' => array(
'description' => 'The entity_id being referenced in this field.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'status' => array(
'description' => 'Status of the transcoding, possible values are 1, 5, 10, 20',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'dimensions' => array(
'description' => 'The dimensions of the output video.',
'type' => 'varchar',
'length' => 255,
'default' => '',
),
'duration' => array(
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
'description' => 'Stores the video duration in Sec.',
),
'started' => array(
'description' => t('Start timestamp of transcodings'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'completed' => array(
'description' => 'Transcoding completed timestamp',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'statusupdated' => array(
'description' => 'Timestamp of last status update, used to track stuck videos',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
),
'data' => array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of converted files.',
),
),
'indexes' => array(
'status' => array('status'),
'file' => array('fid'),
),
'primary key' => array('vid'),
);
// video preset
$schema['video_preset'] = array(
'description' => 'The preset table.',
'fields' => array(
'pid' => array(
'description' => 'The primary identifier for a video preset.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'description' => 'The name of this preset.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'A brief description of this preset.',
'type' => 'text',
'size' => 'medium',
'translatable' => TRUE,
),
'settings' => array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'Serialized preset settings.',
),
),
'unique keys' => array(
'name' => array('name'),
),
'primary key' => array('pid'),
);
// video thumbnails
$schema['video_thumbnails'] = array(
'description' => 'Table to store thumbnails associated with each video.',
'fields' => array(
'videofid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'fid of original video.',
),
'thumbnailfid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'fid of thumbnail.',
),
),
'unique keys' => array(
'thumbnail' => array('thumbnailfid'),
),
'primary key' => array('videofid', 'thumbnailfid'),
'foreign keys' => array(
'videofid' => array(
'table' => 'file_managed',
'columns' => array('videofid' => 'fid'),
),
'thumbnailfid' => array(
'table' => 'file_managed',
'columns' => array('thumbnailfid' => 'fid'),
),
),
);
// video converted file reference
$schema['video_output'] = array(
'description' => 'Track file id for converted files.',
'fields' => array(
'vid' => array(
'description' => 'Video identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'original_fid' => array(
'description' => 'Original file identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'output_fid' => array(
'description' => 'Converted file fid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'job_id' => array(
'description' => 'Referenced job id if any.',
'type' => 'int',
'not null' => FALSE,
'default' => NULL,
),
),
'indexes' => array(
'original_fid' => array('original_fid'),
),
'primary key' => array('vid', 'original_fid', 'output_fid')
);
return $schema;
}
/**
* {@inheritdoc}
*/
function schema(FieldStorageDefinitionInterface $field) {
return array(
'columns' => array(
'fid' => array(
'description' => 'The {file_managed}.fid being referenced in this field.',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
),
'thumbnail' => array(
'description' => 'The {file_managed}.fid being referenced for video thumbnail.',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
),
),
'indexes' => array(
'fid' => array('fid'),
),
'foreign keys' => array(
'fid' => array(
'table' => 'file_managed',
'columns' => array('fid' => 'fid'),
),
),
);
}
/**
* Implements hook_install().
*/
function video_install() {
// Create the videos directory and ensure it's writable.
$directory = file_default_scheme() . '://videos';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
/**
* Implements hook_uninstall().
*/
function video_uninstall() {
drupal_uninstall_schema('video');
// remove variables
// db_query("DELETE FROM {variable} WHERE name LIKE 'video_%'");
// Remove the video directory and generated images.
file_unmanaged_delete_recursive(file_default_scheme() . '://videos');
}
/**
* Implements hook_requirements().
*/
function video_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
// $includes\transcoder = new Transcoder();
$errormsg = '';
if (!Transcoder::hasTranscoder()) {
$name = t('None');
$version = t('None');
$available = TRUE;
}
else {
$name = Transcoder::getTranscoder()->getName();
$version = Transcoder::getTranscoder()->getVersion();
$available = Transcoder::getTranscoder()->isAvailable($errormsg);
}
$requirements['video'] = array(
'title' => t('Video transcoder: @transcoder', array('@transcoder' => $name)),
'value' => NULL,
);
if (!$version) {
$requirements['video']['description'] = t('Missing the transcoder library. Please <a href="@url">install FFmpeg</a> in to your server if you intend to transcode or to auto create thumbnails.', array('@url' => url('http://video.heidisoft.com/documentation/ffmpeg-installtion-scripts')));
$requirements['video']['severity'] = REQUIREMENT_ERROR;
}
elseif (!$available) {
$requirements['video']['description'] = t('The selected transcoder can\'t be used: !reason. Select <a href="@transcoder-url">another transcoder</a> or resolve the problem.', array('!reason' => rtrim($errormsg, '.'), '@transcoder-url' => url('admin/config/media/video/transcoders')));
$requirements['video']['severity'] = REQUIREMENT_ERROR;
}
else {
$requirements['video']['value'] = $version;
$requirements['video']['severity'] = REQUIREMENT_OK;
}
// Check if URL wrappers are present when allow_url_fopen is off
// Also see http://drupal.org/node/1521224
if (!ini_get('allow_url_fopen')) {
$wrappers = \Drupal::moduleHandler()->invokeAll('stream_wrappers');
$remotes = array();
foreach ($wrappers as $wrapper) {
if (empty($wrapper['type']) || ($wrapper['type'] & STREAM_WRAPPERS_LOCAL) == 0) {
$remotes[] = $wrapper['name'];
}
}
// $remotes contains all remote stream wrappers
if (!empty($remotes)) {
$requirements['php_allow_url_fopen'] = array(
'title' => t('PHP remote stream wrappers'),
'value' => t('Not supported'),
'severity' => REQUIREMENT_WARNING,
'description' => t('Your PHP configuration disallows remote stream wrappers. Change the php.ini setting <em>allow_url_fopen</em> to <em>On</em> to use the following locations for storing files:') .
theme('item_list', array('items' => $remotes)),
);
}
}
}
return $requirements;
}