';
foreach ($ChaptersData as $index => $item) {
$time = secondsToTime($item["timeInSeconds"], '%02d');
$html .= '
'
. $time . ' '
. $item["name"] . '
';
}
$html .= '
';
return $html;
}
static function generateChaptersJSONLD($videos_id)
{
$ChaptersData = BookmarkTable::getAllFromVideo($videos_id);
$Chapters = [];
if (!empty($ChaptersData)) {
$video = new VIdeo('', '', $videos_id);
$durationInSeconds = $video->getDuration_in_seconds();
foreach ($ChaptersData as $index => $item) {
$startTime = secondsToTime($item["timeInSeconds"], '%02d');
// Calculate end time based on the next chapter's start time
$endTimeInSeconds = ($index < count($ChaptersData) - 1)
? $ChaptersData[$index + 1]["timeInSeconds"]
: $durationInSeconds;
$endTime = secondsToTime($endTimeInSeconds, '%02d');
$Chapter = [
"@type" => "VideoGameClip",
"name" => $item["name"],
"startTime" => "PT" . $startTime . "S",
"endTime" => "PT" . $endTime . "S"
];
$Chapters[] = $Chapter;
}
}
return $Chapters;
}
static function videoToVtt($videos_id)
{
$data = BookmarkTable::getAllFromVideo($videos_id);
$output = "WEBVTT\n\n";
foreach ($data as $index => $item) {
$start_time = $item["timeInSeconds"];
// Assume each Chapter is 5 seconds long if it's the last one,
// or calculate the time until the next Chapter starts
$end_time = ($index == count($data) - 1) ? $start_time + 5 : $data[$index + 1]["timeInSeconds"] - 1;
$output .= secondsToTime($start_time) . " --> " . secondsToTime($end_time) . "\n";
$output .= $item["name"] . "\n\n";
}
// Save to a WebVTT file
$bytes = file_put_contents(self::getChaptersFilename($videos_id), $output);
return $bytes;
//var_dump($bytes, self::getChaptersFilename($videos_id), $output);exit;
}
static function getChaptersFilenameFromFilename($fileName, $lang = 'en')
{
$video = Video::getVideoFromFileNameLight($fileName);
//var_dump($video);
return self::getChaptersFilename($video['id'], $lang);
}
static function getChaptersFilename($videos_id, $lang = 'en')
{
$video = new Video("", "", $videos_id);
$filename = $video->getFilename();
$path = Video::getPathToFile($filename);
if (empty($lang) || strtoupper($lang) == 'CC') {
$vttFilename = "{$path}.Chapters.vtt";
} else {
$vttFilename = "{$path}.Chapters.{$lang}.vtt";
}
return $vttFilename;
}
}
function getVTTChapterTracks($fileName, $returnArray = false)
{
global $global;
$cache = getVTTChapterCache($fileName);
if (!empty($cache)) {
$objCache = _json_decode($cache);
} else {
$sourcesArray = array();
$tracks = "";
if (!empty($fileName)) {
$defaultFile = Bookmark::getChaptersFilenameFromFilename($fileName);
//var_dump( $defaultFile, Video::getCleanFilenameFromFile($defaultFile));exit;
if (file_exists($defaultFile)) {
$path_parts = pathinfo($defaultFile);
$src = Video::getURLToFile($path_parts['basename']);
//var_dump($src, $path_parts['basename'], $defaultFile);exit;
$obj = new stdClass();
$obj->srclang = 'en';
$obj->src = $src;
$obj->filename = $defaultFile;
$obj->label = 'Chapters';
$obj->desc = 'Chapters';
$tracks .= "