146 lines
3.8 KiB
PHP
146 lines
3.8 KiB
PHP
<?php
|
|
namespace Uiharu\Lookup;
|
|
|
|
use Uiharu\AudioTags;
|
|
use Uiharu\Url;
|
|
use Index\MediaType;
|
|
|
|
class WebLookupMediaResult extends WebLookupResult implements \Uiharu\IHasMediaInfo {
|
|
private object $mediaInfo;
|
|
private ?AudioTags $audioTags;
|
|
|
|
public function __construct(Url $url, MediaType $mediaType, object $mediaInfo) {
|
|
parent::__construct($url, $mediaType);
|
|
$this->mediaInfo = $mediaInfo;
|
|
|
|
if($this->isAudio() && $mediaInfo !== null)
|
|
$this->audioTags = AudioTags::fromMediaInfo($mediaInfo);
|
|
else
|
|
$this->audioTags = null;
|
|
}
|
|
|
|
public function getObjectType(): string {
|
|
return 'media';
|
|
}
|
|
|
|
public function hasColour(): bool {
|
|
return false;
|
|
}
|
|
public function getColour(): int {
|
|
throw new RuntimeException('Unsupported');
|
|
}
|
|
|
|
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 basename($this->url->getPath());
|
|
}
|
|
|
|
public function hasSiteName(): bool {
|
|
return true;
|
|
}
|
|
public function getSiteName(): string {
|
|
return $this->url->getHost();
|
|
}
|
|
|
|
public function hasDescription(): bool {
|
|
return $this->audioTags !== null && $this->audioTags->hasComment();
|
|
}
|
|
public function getDescription(): string {
|
|
return $this->audioTags->getComment();
|
|
}
|
|
|
|
public function hasPreviewImage(): bool {
|
|
return $this->isImage();
|
|
}
|
|
public function getPreviewImage(): string {
|
|
return (string)$this->url;
|
|
}
|
|
|
|
public function getConfidence(): float {
|
|
return $this->mediaInfo->confidence;
|
|
}
|
|
|
|
public function isMedia(): bool {
|
|
return true;
|
|
}
|
|
public function isImage(): bool {
|
|
return $this->mediaType->matchCategory('image');
|
|
}
|
|
public function isVideo(): bool {
|
|
return $this->mediaType->matchCategory('video');
|
|
}
|
|
public function isAudio(): bool {
|
|
return $this->mediaType->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 true;
|
|
}
|
|
public function getMediaInfo(): object {
|
|
return $this->mediaInfo;
|
|
}
|
|
}
|