Subtitles interactive video: first commit

pull/10/head
xyulex 2015-12-14 11:18:03 +01:00
parent 2bc4dee85a
commit ec7081bd7f
1 changed files with 62 additions and 0 deletions

View File

@ -1866,6 +1866,68 @@ class H5PCore {
return $dependencies; return $dependencies;
} }
/**
* Process SRT to JSON files in order to Interactive Video load the subtitles
*
*/
public function processSRT($filename, $contentId) {
define('SRT_STATE_SUBNUMBER', 0);
define('SRT_STATE_TIME', 1);
define('SRT_STATE_TEXT', 2);
define('SRT_STATE_BLANK', 3);
$lines = file('../wp-content/uploads/h5p/content/'. $contentId .'/videos/'.$filename);
$subs = array();
$state = SRT_STATE_SUBNUMBER;
$subNum = 0;
$subText = '';
$subTime = '';
foreach($lines as $line) {
switch($state) {
case SRT_STATE_SUBNUMBER:
$subNum = trim($line);
$state = SRT_STATE_TIME;
break;
case SRT_STATE_TIME:
$subTime = trim($line);
$state = SRT_STATE_TEXT;
break;
case SRT_STATE_TEXT:
if (trim($line) == '') {
$sub = array();
$sub['number'] = $subNum;
list($sub['startTime'], $sub['stopTime']) = explode(' --> ', $subTime);
$sub['text'] = $subText;
$subText = '';
$state = SRT_STATE_SUBNUMBER;
$subs[] = $sub;
} else {
$subText .= utf8_encode($line);
}
break;
}
}
if ($subs) {
$filenameArray = explode(".", $filename);
$file = json_encode($subs);
$finalName = $filenameArray[0].'.json';
file_put_contents('../wp-content/uploads/h5p/content/'. $contentId .'/videos/'.$contentId.'_'.$finalName, $file);
return TRUE;
}
return FALSE;
}
/** /**
* Get all dependency assets of the given type * Get all dependency assets of the given type
* *