19declare(strict_types=1);
45 $this->repo =
$repo->mediaObject();
46 $this->image_converters =
new Images(
true);
66 $this->repo->addLocalDirectory($mob_id, $dir);
71 $this->repo->addFileFromLegacyUpload($mob_id, $tmp_name, $target_path);
79 $this->repo->addFileFromUpload($mob_id, $result,
$path);
84 $this->repo->addFileFromLocal($mob_id, $tmp_name,
$path);
91 $this->repo->removeLocation($mob_id,
$location);
113 $this->repo->addStream($mob_id,
$location, $stream);
118 $src = $this->repo->getLocalSrc(
126 }
catch (\Exception
$e) {
134 return $this->repo->hasLocalFile($mob_id,
$location);
140 return $this->repo->getContainerResource($mob_id);
146 return $this->repo->getContainerResourceId($mob_id);
153 return $this->repo->getFilesOfPath($mob_id, $dir_path);
160 return $this->repo->getInfoOfEntry(
170 $this->repo->deliverEntry($mob_id,
$path);
180 string $target_location =
"mob_vpreview.png"
183 $is_image = is_int(strpos($format,
"image/"));
184 $is_video = in_array($format, [
"video/mp4",
"video/webm"]);
193 $tempStream = fopen(
'php://temp',
'w+');
194 stream_copy_to_stream($this->repo->getLocationStream($mob_id,
$location)->detach(), $tempStream);
196 $stream =
new Stream($tempStream);
198 $converter = $this->image_converters->resizeToFixedSize(
203 $this->output_options
204 ->withQuality($image_quality)
205 ->withFormat(ImageOutputOptions::FORMAT_PNG)
207 $this->repo->addStream(
210 $converter->getStream()
215 $zip_uri = $this->repo->getContainerPath($mob_id);
221 $png_res = fopen(
'php://memory',
'r+');
222 fwrite($png_res, $image_str);
224 $png_stream =
new Stream($png_res);
225 $this->repo->addStream(
240 bool $a_constrain_prop =
false
243 if (!is_int(strpos($format,
"image/"))) {
248 $new_location = substr($file_path[
"basename"], 0, strlen($file_path[
"basename"]) -
249 strlen($file_path[
"extension"]) - 1) .
"_" .
251 $height .
"." . $file_path[
"extension"];
258 $tempStream = fopen(
'php://temp',
'w+');
259 stream_copy_to_stream($this->repo->getLocationStream($mob_id,
$location)->detach(), $tempStream);
261 $stream =
new Stream($tempStream);
263 $converter = $this->image_converters->resizeToFixedSize(
268 $this->output_options
272 $this->repo->addStream(
275 $converter->getStream()
278 return $new_location;
284 string $target_location
288 $log->debug(
'Trying to fetch thumbnail from URL: {thumbnail_url}', [
289 'thumbnail_url' =>
$url,
291 $curl = new \ilCurlConnection(
$url);
293 $curl->setOpt(CURLOPT_RETURNTRANSFER,
true);
294 $curl->setOpt(CURLOPT_VERBOSE,
true);
295 $curl->setOpt(CURLOPT_FOLLOWLOCATION,
true);
296 $curl->setOpt(CURLOPT_TIMEOUT_MS, 5000);
297 $curl->setOpt(CURLOPT_TIMEOUT, 5);
298 $curl->setOpt(CURLOPT_FAILONERROR,
true);
299 $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
300 $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
302 $str = $curl->exec();
303 $info = $curl->getInfo();
305 $log->debug(
'cURL Info: {info}', [
306 'info' => print_r(
$info,
true)
309 $status =
$info[
'http_code'] ??
'';
310 if ((
int) $status === 200) {
311 $log->debug(
'Successfully fetched preview file from URL: Received {bytes} bytes', [
312 'bytes' => (
string) strlen($str),
315 $log->error(
'Could not fetch thumbnail from YouTube: {thumbnail_url}', [
316 'thumbnail_url' =>
$url,
320 $res = fopen(
'php://memory',
'r+');
324 $this->repo->addStream(
329 }
catch (\Exception
$e) {
330 $log->error(
'Could not fetch thumbnail from Url: {message}', [
331 'message' =>
$e->getMessage(),
333 $log->error(
$e->getTraceAsString());
337 public function getSrtFiles(
int $mob_id,
bool $vtt_only =
false): array
340 $valid_suffixes = $vtt_only
343 foreach ($this->getFilesOfPath($mob_id,
"/srt") as $i) {
344 $name = explode(
".", $i[
"basename"]);
345 if (in_array($name[1], $valid_suffixes) && substr($name[0], 0, 9) ==
"subtitle_") {
347 "file" => $i[
"basename"],
348 "full_path" => $i[
"path"],
349 "src" => $this->getLocalSrc($mob_id, $i[
"path"]),
350 "language" => substr($name[0], 9, 2)
359 $names = array_map(
static function (array $i) {
361 }, $this->getSrtFiles($mob_id));
363 foreach ($names as $name) {
364 if (str_ends_with($name,
".srt")) {
365 $vtt = str_replace(
".srt",
".vtt", $name);
366 if (!in_array($vtt, $names) && !in_array($vtt, $missing_vtt)) {
367 $missing_vtt[] = $vtt;
371 foreach ($missing_vtt as $vtt_name) {
372 $srt_name = str_replace(
".vtt",
".srt", $vtt_name);
373 $srt_content = stream_get_contents($this->repo->getLocationStream($mob_id,
"srt/" . $srt_name)->detach());
374 $vtt_content = $this->srtToVtt($srt_content);
375 $this->repo->addString($mob_id,
"/srt/" . $vtt_name, $vtt_content);
382 $srt_text = preg_replace(
'/^\xEF\xBB\xBF/',
'', $srt_text);
385 $srt_text = preg_replace(
'~\r\n?~',
"\n", $srt_text);
386 $blocks = preg_split(
"/\n{2,}/", trim($srt_text));
388 $vttLines = [
'WEBVTT',
''];
390 foreach ($blocks as $block) {
391 $lines = explode(
"\n", $block);
393 if (count($lines) < 2) {
398 if (preg_match(
'/^\s*\d+\s*$/u', $lines[0])) {
403 $lines[0] = preg_replace(
404 '/(\d{2}:\d{2}:\d{2}),(\d{3})/',
409 $vttLines = array_merge($vttLines, $lines, [
'']);
412 return implode(
"\n", $vttLines);
417 return $this->repo->getLastChangeTimestamp($mob_id);
422 $this->repo->updateLastChangeTimestamp($mob_id, time());
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Class ResourceIdentification.
static extractPNGFromVideoInZip(string $zip, string $path, int $sec=1)
static getLogger(string $a_component_id)
Get component logger.
static signFile(string $path_to_file)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The base interface for all filesystem streams.
Interface StorageResource.
if(!file_exists('../ilias.ini.php'))