19 declare(strict_types=1);
40 protected InternalDataService
$data,
41 InternalRepoService $repo,
45 $this->repo = $repo->mediaObject();
46 $this->image_converters =
new Images(
true);
65 $this->repo->addLocalDirectory($mob_id, $dir);
70 $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);
98 return $this->repo->getLocationStream($mob_id, $location);
106 $this->repo->addStream($mob_id, $location, $stream);
111 $src = $this->repo->getLocalSrc(
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);
154 return $this->repo->getInfoOfEntry(
165 $this->repo->deliverEntry($mob_id, $path);
175 string $target_location =
"mob_vpreview.png" 178 $is_image = is_int(strpos($format,
"image/"));
179 $is_video = in_array($format, [
"video/mp4",
"video/webm"]);
188 $tempStream = fopen(
'php://temp',
'w+');
189 stream_copy_to_stream($this->repo->getLocationStream($mob_id, $location)->detach(), $tempStream);
191 $stream =
new Stream($tempStream);
193 $converter = $this->image_converters->resizeToFixedSize(
198 $this->output_options
199 ->withQuality($image_quality)
202 $this->repo->addStream(
205 $converter->getStream()
210 $zip_uri = $this->repo->getContainerPath($mob_id);
216 $png_res = fopen(
'php://memory',
'r+');
217 fwrite($png_res, $image_str);
219 $png_stream =
new Stream($png_res);
220 $this->repo->addStream(
232 string $target_location
235 $str = file_get_contents($url);
236 $res = fopen(
'php://memory',
'r+');
240 $this->repo->addStream(
247 public function getSrtFiles(
int $mob_id,
bool $vtt_only =
false): array
250 $valid_suffixes = $vtt_only
254 $name = explode(
".", $i[
"basename"]);
255 if (in_array($name[1], $valid_suffixes) && substr($name[0], 0, 9) ==
"subtitle_") {
257 "file" => $i[
"basename"],
258 "full_path" => $i[
"path"],
260 "language" => substr($name[0], 9, 2)
269 $names =
array_map(
static function(array $i) {
273 foreach ($names as $name) {
274 if (str_ends_with($name,
".srt")) {
275 $vtt = str_replace (
".srt",
".vtt", $name);
276 if (!in_array($vtt, $names) && !in_array($vtt, $missing_vtt)) {
277 $missing_vtt[] = $vtt;
281 foreach($missing_vtt as $vtt_name) {
282 $srt_name = str_replace (
".vtt",
".srt", $vtt_name);
283 $srt_content = stream_get_contents($this->repo->getLocationStream($mob_id,
"srt/" . $srt_name)->detach());
284 $vtt_content = $this->
srtToVtt($srt_content);
285 $this->repo->addString($mob_id,
"/srt/" . $vtt_name, $vtt_content);
292 $srt_text = preg_replace(
'/^\xEF\xBB\xBF/',
'', $srt_text);
295 $srt_text = preg_replace(
'~\r\n?~',
"\n", $srt_text);
296 $blocks = preg_split(
"/\n{2,}/", trim($srt_text));
298 $vttLines = [
'WEBVTT',
''];
300 foreach ($blocks as $block) {
301 $lines = explode(
"\n", $block);
303 if (count($lines) < 2) {
308 if (preg_match(
'/^\s*\d+\s*$/u', $lines[0])) {
313 $lines[0] = preg_replace(
314 '/(\d{2}:\d{2}:\d{2}),(\d{3})/',
319 $vttLines = array_merge($vttLines, $lines, [
'']);
322 return implode(
"\n", $vttLines);
Interface StorageResource.
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static extractPNGFromVideoInZip(string $zip, string $path, int $sec=1)
Class ResourceIdentification.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static signFile(string $path_to_file)
The base interface for all filesystem streams.