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);
78 $this->repo->addFileFromUpload($mob_id, $result,
$path);
83 $this->repo->addFileFromLocal($mob_id, $tmp_name, $path);
90 $this->repo->removeLocation($mob_id, $location);
97 return $this->repo->getLocationStream($mob_id, $location);
105 $this->repo->addStream($mob_id, $location, $stream);
110 $src = $this->repo->getLocalSrc(
126 return $this->repo->hasLocalFile($mob_id, $location);
132 return $this->repo->getContainerResource($mob_id);
138 return $this->repo->getContainerResourceId($mob_id);
145 return $this->repo->getFilesOfPath($mob_id, $dir_path);
152 return $this->repo->getInfoOfEntry(
162 $this->repo->deliverEntry($mob_id, $path);
172 string $target_location =
"mob_vpreview.png" 175 $is_image = is_int(strpos($format,
"image/"));
176 $is_video = in_array($format, [
"video/mp4",
"video/webm"]);
185 $tempStream = fopen(
'php://temp',
'w+');
186 stream_copy_to_stream($this->repo->getLocationStream($mob_id, $location)->detach(), $tempStream);
188 $stream =
new Stream($tempStream);
190 $converter = $this->image_converters->resizeToFixedSize(
195 $this->output_options
196 ->withQuality($image_quality)
199 $this->repo->addStream(
202 $converter->getStream()
207 $zip_uri = $this->repo->getContainerPath($mob_id);
213 $png_res = fopen(
'php://memory',
'r+');
214 fwrite($png_res, $image_str);
216 $png_stream =
new Stream($png_res);
217 $this->repo->addStream(
229 string $target_location
231 $str = file_get_contents($url);
232 $res = fopen(
'php://memory',
'r+');
236 $this->repo->addStream(
243 public function getSrtFiles(
int $mob_id,
bool $vtt_only =
false): array
246 $valid_suffixes = $vtt_only
250 $name = explode(
".", $i[
"basename"]);
251 if (in_array($name[1], $valid_suffixes) && substr($name[0], 0, 9) ==
"subtitle_") {
253 "file" => $i[
"basename"],
254 "full_path" => $i[
"path"],
256 "language" => substr($name[0], 9, 2)
265 $names =
array_map(
static function (array $i) {
269 foreach ($names as $name) {
270 if (str_ends_with($name,
".srt")) {
271 $vtt = str_replace(
".srt",
".vtt", $name);
272 if (!in_array($vtt, $names) && !in_array($vtt, $missing_vtt)) {
273 $missing_vtt[] = $vtt;
277 foreach ($missing_vtt as $vtt_name) {
278 $srt_name = str_replace(
".vtt",
".srt", $vtt_name);
279 $srt_content = stream_get_contents($this->repo->getLocationStream($mob_id,
"srt/" . $srt_name)->detach());
280 $vtt_content = $this->
srtToVtt($srt_content);
281 $this->repo->addString($mob_id,
"/srt/" . $vtt_name, $vtt_content);
288 $srt_text = preg_replace(
'/^\xEF\xBB\xBF/',
'', $srt_text);
291 $srt_text = preg_replace(
'~\r\n?~',
"\n", $srt_text);
292 $blocks = preg_split(
"/\n{2,}/", trim($srt_text));
294 $vttLines = [
'WEBVTT',
''];
296 foreach ($blocks as $block) {
297 $lines = explode(
"\n", $block);
299 if (count($lines) < 2) {
304 if (preg_match(
'/^\s*\d+\s*$/u', $lines[0])) {
309 $lines[0] = preg_replace(
310 '/(\d{2}:\d{2}:\d{2}),(\d{3})/',
315 $vttLines = array_merge($vttLines, $lines, [
'']);
318 return implode(
"\n", $vttLines);
Interface StorageResource.
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.