1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-11 03:48:17 +01:00
MadelineProto/src/EventHandler/Media.php

87 lines
2.3 KiB
PHP
Raw Normal View History

2023-07-04 18:19:06 +02:00
<?php declare(strict_types=1);
namespace danog\MadelineProto\EventHandler;
use danog\MadelineProto\Ipc\IpcCapable;
use danog\MadelineProto\MTProto;
2023-07-10 10:12:46 +02:00
use JsonSerializable;
2023-07-04 18:19:06 +02:00
/**
* Represents a generic media.
*/
2023-07-10 10:12:46 +02:00
abstract class Media extends IpcCapable implements JsonSerializable
2023-07-04 18:19:06 +02:00
{
/** Media filesize */
public readonly int $size;
/** Media file name */
public readonly string $fileName;
/** Media file extension */
public readonly string $fileExt;
2023-07-04 18:19:06 +02:00
/** Media creation date */
2023-07-10 10:12:46 +02:00
public readonly int $creationDate;
2023-07-04 18:19:06 +02:00
/** Media MIME type */
public readonly string $mimeType;
/** Time-to-live of media */
public readonly ?int $ttl;
/** @var list<array> Thumbnails */
2023-07-04 18:19:06 +02:00
public readonly array $thumbs;
/** @var list<array> Video thumbnails */
2023-07-04 18:19:06 +02:00
public readonly array $videoThumbs;
/** Whether the media should be hidden behind a spoiler */
public readonly bool $spoiler;
2023-07-11 19:43:31 +02:00
/** File ID in bot API format (always present even for users) */
public readonly string $botApiFileId;
/** Unique file ID in bot API format (always present even for users) */
public readonly string $botApiFileUniqueId;
/** @internal Media location */
public readonly array $location;
/** @internal */
public function __construct(
MTProto $API,
array $rawMedia,
2023-07-11 19:43:31 +02:00
/** Whether this media is protected */
public readonly bool $protected
) {
parent::__construct($API);
[
'name' => $name,
'ext' => $this->fileExt,
'mime' => $this->mimeType,
'size' => $this->size,
'InputFileLocation' => $this->location
] = $API->getDownloadInfo($rawMedia);
$this->fileName = "$name.".$this->fileExt;
2023-07-11 19:43:31 +02:00
[
'file_id' => $this->botApiFileId,
'file_unique_id' => $this->botApiFileUniqueId
] = $API->extractBotAPIFile($API->MTProtoToBotAPI($rawMedia));
2023-07-10 10:12:46 +02:00
$this->creationDate = ($rawMedia['document'] ?? $rawMedia['photo'])['date'];
$this->ttl = $rawMedia['ttl_seconds'] ?? null;
$this->spoiler = $rawMedia['spoiler'] ?? false;
}
2023-07-10 10:12:46 +02:00
2023-07-14 20:15:04 +02:00
/** @internal */
2023-07-10 10:12:46 +02:00
public function jsonSerialize(): mixed
{
$v = \get_object_vars($this);
2023-07-13 17:05:44 +02:00
unset($v['API'], $v['session'], $v['location']);
2023-07-10 10:12:46 +02:00
$v['_'] = static::class;
return $v;
}
2023-07-04 18:19:06 +02:00
}