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);
106 $this->repo->addStream($mob_id,
$location, $stream);
111 $src = $this->repo->getLocalSrc(
119 }
catch (\Exception
$e) {
127 return $this->repo->hasLocalFile($mob_id,
$location);
133 return $this->repo->getContainerResource($mob_id);
139 return $this->repo->getContainerResourceId($mob_id);
146 return $this->repo->getFilesOfPath($mob_id, $dir_path);
153 return $this->repo->getInfoOfEntry(
163 $this->repo->deliverEntry($mob_id,
$path);
173 string $target_location =
"mob_vpreview.png"
176 $is_image = is_int(strpos($format,
"image/"));
177 $is_video = in_array($format, [
"video/mp4",
"video/webm"]);
186 $tempStream = fopen(
'php://temp',
'w+');
187 stream_copy_to_stream($this->repo->getLocationStream($mob_id,
$location)->detach(), $tempStream);
189 $stream =
new Stream($tempStream);
191 $converter = $this->image_converters->resizeToFixedSize(
196 $this->output_options
197 ->withQuality($image_quality)
198 ->withFormat(ImageOutputOptions::FORMAT_PNG)
200 $this->repo->addStream(
203 $converter->getStream()
208 $zip_uri = $this->repo->getContainerPath($mob_id);
214 $png_res = fopen(
'php://memory',
'r+');
215 fwrite($png_res, $image_str);
217 $png_stream =
new Stream($png_res);
218 $this->repo->addStream(
230 string $target_location
234 $log->debug(
'Trying to fetch thumbnail from URL: {thumbnail_url}', [
235 'thumbnail_url' =>
$url,
237 $curl = new \ilCurlConnection(
$url);
239 $curl->setOpt(CURLOPT_RETURNTRANSFER,
true);
240 $curl->setOpt(CURLOPT_VERBOSE,
true);
241 $curl->setOpt(CURLOPT_FOLLOWLOCATION,
true);
242 $curl->setOpt(CURLOPT_TIMEOUT_MS, 5000);
243 $curl->setOpt(CURLOPT_TIMEOUT, 5);
244 $curl->setOpt(CURLOPT_FAILONERROR,
true);
245 $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
246 $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
248 $str = $curl->exec();
249 $info = $curl->getInfo();
251 $log->debug(
'cURL Info: {info}', [
252 'info' => print_r(
$info,
true)
255 $status =
$info[
'http_code'] ??
'';
256 if ((
int) $status === 200) {
257 $log->debug(
'Successfully fetched preview file from URL: Received {bytes} bytes', [
258 'bytes' => (
string) strlen($str),
261 $log->error(
'Could not fetch thumbnail from YouTube: {thumbnail_url}', [
262 'thumbnail_url' =>
$url,
266 $res = fopen(
'php://memory',
'r+');
270 $this->repo->addStream(
275 }
catch (\Exception
$e) {
276 $log->error(
'Could not fetch thumbnail from Url: {message}', [
277 'message' =>
$e->getMessage(),
279 $log->error(
$e->getTraceAsString());
283 public function getSrtFiles(
int $mob_id,
bool $vtt_only =
false): array
286 $valid_suffixes = $vtt_only
289 foreach ($this->getFilesOfPath($mob_id,
"/srt") as $i) {
290 $name = explode(
".", $i[
"basename"]);
291 if (in_array($name[1], $valid_suffixes) && substr($name[0], 0, 9) ==
"subtitle_") {
293 "file" => $i[
"basename"],
294 "full_path" => $i[
"path"],
295 "src" => $this->getLocalSrc($mob_id, $i[
"path"]),
296 "language" => substr($name[0], 9, 2)
305 $names = array_map(
static function (array $i) {
307 }, $this->getSrtFiles($mob_id));
309 foreach ($names as $name) {
310 if (str_ends_with($name,
".srt")) {
311 $vtt = str_replace(
".srt",
".vtt", $name);
312 if (!in_array($vtt, $names) && !in_array($vtt, $missing_vtt)) {
313 $missing_vtt[] = $vtt;
317 foreach ($missing_vtt as $vtt_name) {
318 $srt_name = str_replace(
".vtt",
".srt", $vtt_name);
319 $srt_content = stream_get_contents($this->repo->getLocationStream($mob_id,
"srt/" . $srt_name)->detach());
320 $vtt_content = $this->srtToVtt($srt_content);
321 $this->repo->addString($mob_id,
"/srt/" . $vtt_name, $vtt_content);
328 $srt_text = preg_replace(
'/^\xEF\xBB\xBF/',
'', $srt_text);
331 $srt_text = preg_replace(
'~\r\n?~',
"\n", $srt_text);
332 $blocks = preg_split(
"/\n{2,}/", trim($srt_text));
334 $vttLines = [
'WEBVTT',
''];
336 foreach ($blocks as $block) {
337 $lines = explode(
"\n", $block);
339 if (count($lines) < 2) {
344 if (preg_match(
'/^\s*\d+\s*$/u', $lines[0])) {
349 $lines[0] = preg_replace(
350 '/(\d{2}:\d{2}:\d{2}),(\d{3})/',
355 $vttLines = array_merge($vttLines, $lines, [
'']);
358 return implode(
"\n", $vttLines);
363 return $this->repo->getLastChangeTimestamp($mob_id);
368 $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.