2015-01-02 08:16:54 +00:00
|
|
|
<?php
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Entity;
|
2015-01-02 08:16:54 +00:00
|
|
|
|
2018-10-01 20:34:12 +00:00
|
|
|
use App\Radio\Backend\Liquidsoap;
|
2017-01-24 00:35:16 +00:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2017-08-17 18:28:48 +00:00
|
|
|
use Doctrine\Common\Collections\Collection;
|
2018-10-04 23:12:12 +00:00
|
|
|
use Psr\Http\Message\UriInterface;
|
2015-01-02 08:16:54 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Table(name="station_media", indexes={
|
2016-09-23 00:49:59 +00:00
|
|
|
* @index(name="search_idx", columns={"title", "artist", "album"})
|
|
|
|
* }, uniqueConstraints={
|
2016-11-22 05:09:18 +00:00
|
|
|
* @UniqueConstraint(name="path_unique_idx", columns={"path", "station_id"})
|
2015-01-02 08:16:54 +00:00
|
|
|
* })
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Entity(repositoryClass="App\Entity\Repository\StationMediaRepository")
|
2015-01-02 08:16:54 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
class StationMedia
|
2015-01-02 08:16:54 +00:00
|
|
|
{
|
2018-04-06 21:29:27 +00:00
|
|
|
use Traits\UniqueId, Traits\TruncateStrings;
|
2017-11-04 02:13:41 +00:00
|
|
|
|
2015-01-02 08:16:54 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="id", type="integer")
|
|
|
|
* @ORM\Id
|
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY")
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int
|
2015-01-02 08:16:54 +00:00
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="station_id", type="integer")
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
2015-01-02 08:16:54 +00:00
|
|
|
protected $station_id;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\ManyToOne(targetEntity="Station", inversedBy="media")
|
2017-08-17 18:28:48 +00:00
|
|
|
* @JoinColumns({
|
|
|
|
* @JoinColumn(name="station_id", referencedColumnName="id", onDelete="CASCADE")
|
|
|
|
* })
|
|
|
|
* @var Station
|
|
|
|
*/
|
|
|
|
protected $station;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="song_id", type="string", length=50, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int|null
|
|
|
|
*/
|
2015-01-02 08:16:54 +00:00
|
|
|
protected $song_id;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\ManyToOne(targetEntity="Song")
|
2017-08-17 18:28:48 +00:00
|
|
|
* @JoinColumns({
|
|
|
|
* @JoinColumn(name="song_id", referencedColumnName="id", onDelete="SET NULL")
|
|
|
|
* })
|
|
|
|
* @var Song|null
|
|
|
|
*/
|
|
|
|
protected $song;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="title", type="string", length=200, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
2015-01-02 08:16:54 +00:00
|
|
|
protected $title;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="artist", type="string", length=200, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
2015-01-02 08:16:54 +00:00
|
|
|
protected $artist;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="album", type="string", length=200, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
2015-01-02 08:16:54 +00:00
|
|
|
protected $album;
|
|
|
|
|
2017-11-04 02:13:41 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="lyrics", type="text", nullable=true)
|
2017-11-04 02:13:41 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $lyrics;
|
|
|
|
|
2017-05-24 09:21:11 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="isrc", type="string", length=15, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null The track ISRC (International Standard Recording Code), used for licensing purposes.
|
2017-05-24 09:21:11 +00:00
|
|
|
*/
|
|
|
|
protected $isrc;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="length", type="integer")
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
2015-01-02 08:16:54 +00:00
|
|
|
protected $length;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="length_text", type="string", length=10, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $length_text;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="path", type="string", length=500, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $path;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="mtime", type="integer", nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int|null
|
|
|
|
*/
|
|
|
|
protected $mtime;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="fade_overlap", type="decimal", precision=3, scale=1, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var float|null
|
|
|
|
*/
|
|
|
|
protected $fade_overlap;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="fade_in", type="decimal", precision=3, scale=1, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var float|null
|
|
|
|
*/
|
|
|
|
protected $fade_in;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="fade_out", type="decimal", precision=3, scale=1, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var float|null
|
|
|
|
*/
|
|
|
|
protected $fade_out;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="cue_in", type="decimal", precision=5, scale=1, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var float|null
|
|
|
|
*/
|
|
|
|
protected $cue_in;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="cue_out", type="decimal", precision=5, scale=1, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var float|null
|
|
|
|
*/
|
|
|
|
protected $cue_out;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\OneToMany(targetEntity="StationPlaylistMedia", mappedBy="media")
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var Collection
|
|
|
|
*/
|
2018-04-29 23:48:48 +00:00
|
|
|
protected $playlist_items;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2018-04-15 23:53:46 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\OneToMany(targetEntity="StationMediaCustomField", mappedBy="media")
|
2018-04-15 23:53:46 +00:00
|
|
|
* @var Collection
|
|
|
|
*/
|
2018-04-16 00:53:27 +00:00
|
|
|
protected $custom_fields;
|
2018-04-15 23:53:46 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
public function __construct(Station $station, string $path)
|
|
|
|
{
|
|
|
|
$this->station = $station;
|
|
|
|
|
|
|
|
$this->length = 0;
|
|
|
|
$this->length_text = '0:00';
|
|
|
|
|
|
|
|
$this->mtime = 0;
|
|
|
|
|
2018-04-29 23:48:48 +00:00
|
|
|
$this->playlist_items = new ArrayCollection;
|
2018-04-17 05:56:22 +00:00
|
|
|
$this->custom_fields = new ArrayCollection;
|
2018-12-05 07:15:51 +00:00
|
|
|
|
|
|
|
$this->setPath($path);
|
|
|
|
$this->generateUniqueId();
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getId(): int
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Station
|
|
|
|
*/
|
|
|
|
public function getStation(): Station
|
|
|
|
{
|
|
|
|
return $this->station;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Song|null
|
|
|
|
*/
|
|
|
|
public function getSong(): ?Song
|
|
|
|
{
|
|
|
|
return $this->song;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Song|null $song
|
|
|
|
*/
|
|
|
|
public function setSong(Song $song = null)
|
|
|
|
{
|
|
|
|
$this->song = $song;
|
|
|
|
}
|
|
|
|
|
2018-12-05 07:15:51 +00:00
|
|
|
/**
|
|
|
|
* Check if the hash of the associated Song record matches the hash that would be
|
|
|
|
* generated by this record's artist and title metadata. Used to determine if a
|
|
|
|
* record should be reprocessed or not.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function songMatches(): bool
|
|
|
|
{
|
|
|
|
$expected_song_hash = Song::getSongHash([
|
|
|
|
'artist' => $this->artist,
|
|
|
|
'title' => $this->title,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return (null !== $this->song_id)
|
|
|
|
&& ($this->song_id === $expected_song_hash);
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getTitle(): ?string
|
|
|
|
{
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $title
|
|
|
|
*/
|
|
|
|
public function setTitle(string $title = null)
|
|
|
|
{
|
2018-04-06 21:29:27 +00:00
|
|
|
$this->title = $this->_truncateString($title, 200);
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getArtist(): ?string
|
|
|
|
{
|
|
|
|
return $this->artist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $artist
|
|
|
|
*/
|
|
|
|
public function setArtist(string $artist = null)
|
|
|
|
{
|
2018-04-06 21:29:27 +00:00
|
|
|
$this->artist = $this->_truncateString($artist, 200);
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getAlbum(): ?string
|
|
|
|
{
|
|
|
|
return $this->album;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $album
|
|
|
|
*/
|
|
|
|
public function setAlbum(string $album = null)
|
|
|
|
{
|
2018-04-06 21:29:27 +00:00
|
|
|
$this->album = $this->_truncateString($album, 200);
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
2017-11-04 02:13:41 +00:00
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getLyrics()
|
|
|
|
{
|
|
|
|
return $this->lyrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $lyrics
|
|
|
|
*/
|
|
|
|
public function setLyrics($lyrics)
|
|
|
|
{
|
|
|
|
$this->lyrics = $lyrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-05 07:15:51 +00:00
|
|
|
* Get the Flysystem URI for album artwork for this item.
|
|
|
|
*
|
|
|
|
* @return string
|
2017-11-04 02:13:41 +00:00
|
|
|
*/
|
2018-12-05 07:15:51 +00:00
|
|
|
public function getArtPath()
|
2017-11-04 02:13:41 +00:00
|
|
|
{
|
2018-12-05 07:15:51 +00:00
|
|
|
return 'albumart://'.$this->unique_id.'.jpg';
|
2017-11-04 02:13:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getIsrc(): ?string
|
|
|
|
{
|
|
|
|
return $this->isrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $isrc
|
|
|
|
*/
|
|
|
|
public function setIsrc(string $isrc = null)
|
|
|
|
{
|
|
|
|
$this->isrc = $isrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getLength(): int
|
|
|
|
{
|
|
|
|
return $this->length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $length
|
|
|
|
*/
|
2017-01-24 00:17:50 +00:00
|
|
|
public function setLength($length)
|
|
|
|
{
|
|
|
|
$length_min = floor($length / 60);
|
|
|
|
$length_sec = $length % 60;
|
|
|
|
|
2017-07-30 22:04:34 +00:00
|
|
|
$this->length = round($length);
|
2017-01-24 00:35:16 +00:00
|
|
|
$this->length_text = $length_min . ':' . str_pad($length_sec, 2, '0', STR_PAD_LEFT);
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getLengthText(): ?string
|
|
|
|
{
|
|
|
|
return $this->length_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $length_text
|
|
|
|
*/
|
|
|
|
public function setLengthText(string $length_text = null)
|
|
|
|
{
|
|
|
|
$this->length_text = $length_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getPath(): ?string
|
|
|
|
{
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $path
|
|
|
|
*/
|
|
|
|
public function setPath(string $path = null)
|
|
|
|
{
|
|
|
|
$this->path = $path;
|
|
|
|
}
|
|
|
|
|
2018-12-05 07:15:51 +00:00
|
|
|
/**
|
|
|
|
* Return the abstracted "full path" filesystem URI for this record.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-12-05 22:08:24 +00:00
|
|
|
public function getPathUri(): string
|
2018-12-05 07:15:51 +00:00
|
|
|
{
|
|
|
|
return 'media://'.$this->path;
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return int|null
|
|
|
|
*/
|
|
|
|
public function getMtime(): ?int
|
|
|
|
{
|
|
|
|
return $this->mtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int|null $mtime
|
|
|
|
*/
|
|
|
|
public function setMtime(int $mtime = null)
|
|
|
|
{
|
|
|
|
$this->mtime = $mtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return float|null
|
|
|
|
*/
|
|
|
|
public function getFadeOverlap(): ?float
|
|
|
|
{
|
|
|
|
return $this->fade_overlap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param float|null $fade_overlap
|
|
|
|
*/
|
|
|
|
public function setFadeOverlap(float $fade_overlap = null)
|
|
|
|
{
|
|
|
|
$this->fade_overlap = $fade_overlap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return float|null
|
|
|
|
*/
|
|
|
|
public function getFadeIn(): ?float
|
|
|
|
{
|
|
|
|
return $this->fade_in;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param float|null $fade_in
|
|
|
|
*/
|
|
|
|
public function setFadeIn(float $fade_in = null)
|
|
|
|
{
|
|
|
|
$this->fade_in = $fade_in;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return float|null
|
|
|
|
*/
|
|
|
|
public function getFadeOut(): ?float
|
|
|
|
{
|
|
|
|
return $this->fade_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param float|null $fade_out
|
|
|
|
*/
|
|
|
|
public function setFadeOut(float $fade_out = null)
|
|
|
|
{
|
|
|
|
$this->fade_out = $fade_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return float|null
|
|
|
|
*/
|
|
|
|
public function getCueIn(): ?float
|
|
|
|
{
|
|
|
|
return $this->cue_in;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param float|null $cue_in
|
|
|
|
*/
|
|
|
|
public function setCueIn(float $cue_in = null)
|
|
|
|
{
|
|
|
|
$this->cue_in = $cue_in;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return float|null
|
|
|
|
*/
|
|
|
|
public function getCueOut(): ?float
|
|
|
|
{
|
|
|
|
return $this->cue_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param float|null $cue_out
|
|
|
|
*/
|
|
|
|
public function setCueOut(float $cue_out = null)
|
|
|
|
{
|
|
|
|
$this->cue_out = $cue_out;
|
|
|
|
}
|
|
|
|
|
2017-06-19 17:15:57 +00:00
|
|
|
/**
|
|
|
|
* Get the length with cue-in and cue-out points included.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getCalculatedLength()
|
|
|
|
{
|
|
|
|
$length = (int)$this->length;
|
|
|
|
|
|
|
|
if ((int)$this->cue_out > 0) {
|
|
|
|
$length_removed = $length - (int)$this->cue_out;
|
|
|
|
$length -= $length_removed;
|
|
|
|
}
|
|
|
|
if ((int)$this->cue_in > 0) {
|
|
|
|
$length -= $this->cue_in;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $length;
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2018-04-29 23:48:48 +00:00
|
|
|
public function getPlaylistItems(): Collection
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2018-04-29 23:48:48 +00:00
|
|
|
return $this->playlist_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getItemForPlaylist(StationPlaylist $playlist): ?StationPlaylistMedia
|
|
|
|
{
|
|
|
|
$item = $this->playlist_items->filter(function($spm) use ($playlist) {
|
|
|
|
/** @var StationPlaylistMedia $spm */
|
|
|
|
return ($spm->getPlaylist()->getId() == $playlist->getId());
|
|
|
|
});
|
|
|
|
|
|
|
|
return $item->first() ?? null;
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2018-04-15 23:53:46 +00:00
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2018-04-16 00:53:27 +00:00
|
|
|
public function getCustomFields(): Collection
|
2018-04-15 23:53:46 +00:00
|
|
|
{
|
2018-04-16 00:53:27 +00:00
|
|
|
return $this->custom_fields;
|
2018-04-15 23:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-16 00:53:27 +00:00
|
|
|
* @param Collection $custom_fields
|
2018-04-15 23:53:46 +00:00
|
|
|
*/
|
2018-04-16 00:53:27 +00:00
|
|
|
public function setCustomFields(Collection $custom_fields): void
|
2018-04-15 23:53:46 +00:00
|
|
|
{
|
2018-04-16 00:53:27 +00:00
|
|
|
$this->custom_fields = $custom_fields;
|
2018-04-15 23:53:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 10:35:46 +00:00
|
|
|
/**
|
|
|
|
* Assemble a list of annotations for LiquidSoap.
|
|
|
|
*
|
2018-05-01 07:32:31 +00:00
|
|
|
* Liquidsoap expects a string similar to:
|
|
|
|
* annotate:type="song",album="$ALBUM",display_desc="$FULLSHOWNAME",
|
|
|
|
* liq_start_next="2.5",liq_fade_in="3.5",liq_fade_out="3.5":$SONGPATH
|
|
|
|
*
|
2017-05-18 10:35:46 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getAnnotations(): array
|
2017-05-18 10:35:46 +00:00
|
|
|
{
|
2017-06-14 17:39:11 +00:00
|
|
|
$annotations = [];
|
2017-05-18 10:35:46 +00:00
|
|
|
$annotation_types = [
|
2017-06-14 17:39:11 +00:00
|
|
|
'title' => 'title',
|
|
|
|
'artist' => 'artist',
|
2018-11-20 12:06:16 +00:00
|
|
|
'length' => 'duration',
|
2017-05-18 10:35:46 +00:00
|
|
|
'fade_overlap' => 'liq_start_next',
|
|
|
|
'fade_in' => 'liq_fade_in',
|
|
|
|
'fade_out' => 'liq_fade_out',
|
|
|
|
'cue_in' => 'liq_cue_in',
|
|
|
|
'cue_out' => 'liq_cue_out',
|
|
|
|
];
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
foreach ($annotation_types as $annotation_property => $annotation_name) {
|
2017-05-18 10:35:46 +00:00
|
|
|
if ($this->$annotation_property !== null) {
|
2017-08-04 23:48:24 +00:00
|
|
|
$prop = $this->$annotation_property;
|
2017-10-19 02:30:23 +00:00
|
|
|
$prop = mb_convert_encoding($prop, "UTF-8");
|
2017-08-04 23:48:24 +00:00
|
|
|
$prop = str_replace(['"', "\n", "\t", "\r"], ["'", '', '', ''], $prop);
|
2017-10-19 02:30:23 +00:00
|
|
|
|
2018-04-25 21:25:53 +00:00
|
|
|
if ($annotation_property === 'cue_out' && $prop < 0) {
|
|
|
|
$prop = max(0, $this->getLength() - abs($prop));
|
|
|
|
}
|
2017-10-19 02:30:23 +00:00
|
|
|
|
2018-10-01 20:34:12 +00:00
|
|
|
// Convert Liquidsoap-specific annotations to floats.
|
2018-11-20 12:06:16 +00:00
|
|
|
if ('liq' === substr($annotation_name, 0, 3)
|
|
|
|
|| 'duration' === $annotation_name) {
|
2018-10-01 20:34:12 +00:00
|
|
|
$prop = Liquidsoap::toFloat($prop);
|
|
|
|
}
|
|
|
|
|
2018-10-16 01:27:35 +00:00
|
|
|
$annotations[$annotation_name] = $prop;
|
2017-05-18 10:35:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $annotations;
|
|
|
|
}
|
|
|
|
|
2018-04-12 22:43:58 +00:00
|
|
|
/**
|
|
|
|
* Indicates whether this media is a part of any "requestable" playlists.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isRequestable(): bool
|
|
|
|
{
|
2018-04-29 23:48:48 +00:00
|
|
|
$playlists = $this->getPlaylistItems();
|
|
|
|
foreach($playlists as $playlist_item) {
|
|
|
|
$playlist = $playlist_item->getPlaylist();
|
2018-04-12 22:43:58 +00:00
|
|
|
/** @var StationPlaylist $playlist */
|
|
|
|
if ($playlist->isRequestable()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-04 23:48:24 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the API version of the object/array.
|
|
|
|
*
|
2018-10-04 23:12:12 +00:00
|
|
|
* @param \App\ApiUtilities $api_utils
|
|
|
|
* @param UriInterface|null $base_url
|
2017-08-04 23:48:24 +00:00
|
|
|
* @return Api\Song
|
|
|
|
*/
|
2018-10-04 23:12:12 +00:00
|
|
|
public function api(\App\ApiUtilities $api_utils, UriInterface $base_url = null): Api\Song
|
2017-08-04 23:48:24 +00:00
|
|
|
{
|
|
|
|
$response = new Api\Song;
|
|
|
|
$response->id = (string)$this->song_id;
|
2017-08-17 18:28:48 +00:00
|
|
|
$response->text = $this->artist . ' - ' . $this->title;
|
2017-08-04 23:48:24 +00:00
|
|
|
$response->artist = (string)$this->artist;
|
|
|
|
$response->title = (string)$this->title;
|
|
|
|
|
2017-11-04 02:13:41 +00:00
|
|
|
$response->album = (string)$this->album;
|
|
|
|
$response->lyrics = (string)$this->lyrics;
|
|
|
|
|
2018-10-04 23:12:12 +00:00
|
|
|
$response->art = $api_utils->getAlbumArtUrl($this->station_id, $this->unique_id, $base_url);
|
2018-04-17 05:21:46 +00:00
|
|
|
$response->custom_fields = $api_utils->getCustomFields($this->id);
|
2018-04-15 23:53:46 +00:00
|
|
|
|
2017-08-04 23:48:24 +00:00
|
|
|
return $response;
|
|
|
|
}
|
2018-07-16 18:59:08 +00:00
|
|
|
}
|