19declare(strict_types=1);
27use _PHPStan_9815bbba4\Nette\Neon\Exception;
46 $this->repo =
$repo->mediaObject();
47 $this->image_converters =
new Images(
true);
67 $this->repo->addLocalDirectory($mob_id, $dir);
72 $this->repo->addFileFromLegacyUpload($mob_id, $tmp_name, $target_path);
80 $this->repo->addFileFromUpload($mob_id, $result,
$path);
85 $this->repo->addFileFromLocal($mob_id, $tmp_name,
$path);
92 $this->repo->removeLocation($mob_id,
$location);
107 $this->repo->addStream($mob_id,
$location, $stream);
112 $src = $this->repo->getLocalSrc(
120 }
catch (Exception
$e) {
128 return $this->repo->hasLocalFile($mob_id,
$location);
134 return $this->repo->getContainerResource($mob_id);
140 return $this->repo->getContainerResourceId($mob_id);
147 return $this->repo->getFilesOfPath($mob_id, $dir_path);
154 return $this->repo->getInfoOfEntry(
164 $this->repo->deliverEntry($mob_id,
$path);
174 string $target_location =
"mob_vpreview.png"
177 $is_image = is_int(strpos($format,
"image/"));
178 $is_video = in_array($format, [
"video/mp4",
"video/webm"]);
187 $tempStream = fopen(
'php://temp',
'w+');
188 stream_copy_to_stream($this->repo->getLocationStream($mob_id,
$location)->detach(), $tempStream);
190 $stream =
new Stream($tempStream);
192 $converter = $this->image_converters->resizeToFixedSize(
197 $this->output_options
198 ->withQuality($image_quality)
199 ->withFormat(ImageOutputOptions::FORMAT_PNG)
201 $this->repo->addStream(
204 $converter->getStream()
209 $zip_uri = $this->repo->getContainerPath($mob_id);
215 $png_res = fopen(
'php://memory',
'r+');
216 fwrite($png_res, $image_str);
218 $png_stream =
new Stream($png_res);
219 $this->repo->addStream(
231 string $target_location
235 $log->debug(
'Trying to fetch thumbnail from URL: {thumbnail_url}', [
236 'thumbnail_url' =>
$url,
238 $curl = new \ilCurlConnection(
$url);
240 $curl->setOpt(CURLOPT_RETURNTRANSFER,
true);
241 $curl->setOpt(CURLOPT_VERBOSE,
true);
242 $curl->setOpt(CURLOPT_FOLLOWLOCATION,
true);
243 $curl->setOpt(CURLOPT_TIMEOUT_MS, 5000);
244 $curl->setOpt(CURLOPT_TIMEOUT, 5);
245 $curl->setOpt(CURLOPT_FAILONERROR,
true);
246 $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
247 $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
249 $str = $curl->exec();
250 $info = $curl->getInfo();
252 $log->debug(
'cURL Info: {info}', [
253 'info' => print_r(
$info,
true)
256 $status =
$info[
'http_code'] ??
'';
257 if ((
int) $status === 200) {
258 $log->debug(
'Successfully fetched preview file from URL: Received {bytes} bytes', [
259 'bytes' => (
string) strlen($str),
262 $log->error(
'Could not fetch thumbnail from YouTube: {thumbnail_url}', [
263 'thumbnail_url' =>
$url,
267 $res = fopen(
'php://memory',
'r+');
271 $this->repo->addStream(
276 }
catch (\Exception
$e) {
277 $log->error(
'Could not fetch thumbnail from Url: {message}', [
278 'message' =>
$e->getMessage(),
280 $log->error(
$e->getTraceAsString());
284 public function getSrtFiles(
int $mob_id,
bool $vtt_only =
false): array
287 $valid_suffixes = $vtt_only
290 foreach ($this->getFilesOfPath($mob_id,
"/srt") as $i) {
291 $name = explode(
".", $i[
"basename"]);
292 if (in_array($name[1], $valid_suffixes) && substr($name[0], 0, 9) ==
"subtitle_") {
294 "file" => $i[
"basename"],
295 "full_path" => $i[
"path"],
296 "src" => $this->getLocalSrc($mob_id, $i[
"path"]),
297 "language" => substr($name[0], 9, 2)
306 $names = array_map(
static function (array $i) {
308 }, $this->getSrtFiles($mob_id));
310 foreach ($names as $name) {
311 if (str_ends_with($name,
".srt")) {
312 $vtt = str_replace(
".srt",
".vtt", $name);
313 if (!in_array($vtt, $names) && !in_array($vtt, $missing_vtt)) {
314 $missing_vtt[] = $vtt;
318 foreach ($missing_vtt as $vtt_name) {
319 $srt_name = str_replace(
".vtt",
".srt", $vtt_name);
320 $srt_content = stream_get_contents($this->repo->getLocationStream($mob_id,
"srt/" . $srt_name)->detach());
321 $vtt_content = $this->srtToVtt($srt_content);
322 $this->repo->addString($mob_id,
"/srt/" . $vtt_name, $vtt_content);
329 $srt_text = preg_replace(
'/^\xEF\xBB\xBF/',
'', $srt_text);
332 $srt_text = preg_replace(
'~\r\n?~',
"\n", $srt_text);
333 $blocks = preg_split(
"/\n{2,}/", trim($srt_text));
335 $vttLines = [
'WEBVTT',
''];
337 foreach ($blocks as $block) {
338 $lines = explode(
"\n", $block);
340 if (count($lines) < 2) {
345 if (preg_match(
'/^\s*\d+\s*$/u', $lines[0])) {
350 $lines[0] = preg_replace(
351 '/(\d{2}:\d{2}:\d{2}),(\d{3})/',
356 $vttLines = array_merge($vttLines, $lines, [
'']);
359 return implode(
"\n", $vttLines);
$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.