173 lines
4.3 KiB
PHP
173 lines
4.3 KiB
PHP
<?php
|
|
namespace Uiharu\Lookup;
|
|
|
|
use Uiharu\AudioTags;
|
|
use Uiharu\Url;
|
|
use Index\MediaType;
|
|
|
|
final class EEPROMLookupResult implements \Uiharu\ILookupResult, \Uiharu\IHasMediaInfo {
|
|
private Url $url;
|
|
private MediaType $type;
|
|
private object $fileInfo;
|
|
private ?object $mediaInfo;
|
|
private ?AudioTags $audioTags;
|
|
|
|
public function __construct(
|
|
Url $url,
|
|
MediaType $type,
|
|
object $fileInfo,
|
|
?object $mediaInfo
|
|
) {
|
|
$this->url = $url;
|
|
$this->type = $type;
|
|
$this->fileInfo = $fileInfo;
|
|
$this->mediaInfo = $mediaInfo;
|
|
|
|
if($this->isAudio() && $mediaInfo !== null)
|
|
$this->audioTags = AudioTags::fromMediaInfo($mediaInfo);
|
|
else
|
|
$this->audioTags = null;
|
|
}
|
|
|
|
public function getUrl(): Url {
|
|
return $this->url;
|
|
}
|
|
public function getObjectType(): string {
|
|
return 'eeprom:file';
|
|
}
|
|
|
|
public function hasMediaType(): bool {
|
|
return true;
|
|
}
|
|
public function getMediaType(): MediaType {
|
|
return $this->type;
|
|
}
|
|
|
|
public function getEEPROMId(): string {
|
|
return $this->fileInfo->id;
|
|
}
|
|
public function getEEPROMInfo(): object {
|
|
return $this->fileInfo;
|
|
}
|
|
|
|
public function hasColour(): bool {
|
|
return true;
|
|
}
|
|
public function getColour(): int {
|
|
return 0x8559A5;
|
|
}
|
|
|
|
public function hasTitle(): bool {
|
|
return true;
|
|
}
|
|
public function getTitle(): string {
|
|
if($this->audioTags !== null) {
|
|
$title = '';
|
|
|
|
if($this->audioTags->hasArtist())
|
|
$title .= $this->audioTags->getArtist() . ' - ';
|
|
|
|
if($this->audioTags->hasTitle())
|
|
$title .= $this->audioTags->getTitle();
|
|
|
|
if($this->audioTags->hasDate())
|
|
$title .= ' (' . $this->audioTags->getDate() . ')';
|
|
|
|
if(!empty($title))
|
|
return $title;
|
|
}
|
|
|
|
return $this->fileInfo->name;
|
|
}
|
|
|
|
public function hasSiteName(): bool {
|
|
return true;
|
|
}
|
|
public function getSiteName(): string {
|
|
return 'EEPROM';
|
|
}
|
|
|
|
public function hasDescription(): bool {
|
|
return $this->audioTags !== null && $this->audioTags->hasComment();
|
|
}
|
|
public function getDescription(): string {
|
|
return $this->audioTags->getComment();
|
|
}
|
|
|
|
public function hasPreviewImage(): bool {
|
|
return true;
|
|
}
|
|
public function getPreviewImage(): string {
|
|
return $this->fileInfo->thumb;
|
|
}
|
|
|
|
public function getConfidence(): float {
|
|
return $this->mediaInfo->confidence ?? 0;
|
|
}
|
|
|
|
public function isMedia(): bool {
|
|
return $this->mediaInfo !== null;
|
|
}
|
|
public function isImage(): bool {
|
|
return $this->type->matchCategory('image');
|
|
}
|
|
public function isVideo(): bool {
|
|
return $this->type->matchCategory('video');
|
|
}
|
|
public function isAudio(): bool {
|
|
return $this->type->matchCategory('audio');
|
|
}
|
|
|
|
public function hasDimensions(): bool {
|
|
return $this->isImage() || $this->isVideo();
|
|
}
|
|
public function getWidth(): int {
|
|
return $this->mediaInfo->width ?? 0;
|
|
}
|
|
public function getHeight(): int {
|
|
return $this->mediaInfo->height ?? 0;
|
|
}
|
|
|
|
public function hasAspectRatio(): bool {
|
|
return isset($this->mediaInfo->aspectRatio);
|
|
}
|
|
public function getAspectRatio(): string {
|
|
return $this->mediaInfo->aspectRatio;
|
|
}
|
|
|
|
public function hasDuration(): bool {
|
|
return isset($this->mediaInfo->duration);
|
|
}
|
|
public function getDuration(): float {
|
|
return $this->mediaInfo->duration;
|
|
}
|
|
|
|
public function hasSize(): bool {
|
|
return isset($this->mediaInfo->size);
|
|
}
|
|
public function getSize(): int {
|
|
return $this->mediaInfo->size;
|
|
}
|
|
|
|
public function hasBitRate(): bool {
|
|
return isset($this->mediaInfo->bitRate);
|
|
}
|
|
public function getBitRate(): int {
|
|
return $this->mediaInfo->bitRate;
|
|
}
|
|
|
|
public function hasAudioTags(): bool {
|
|
return $this->audioTags !== null;
|
|
}
|
|
public function getAudioTags(): AudioTags {
|
|
return $this->audioTags;
|
|
}
|
|
|
|
public function hasMediaInfo(): bool {
|
|
return $this->mediaInfo !== null;
|
|
}
|
|
public function getMediaInfo(): object {
|
|
return $this->mediaInfo;
|
|
}
|
|
}
|