2016-05-04 00:03:28 +00:00
|
|
|
<?php
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Entity;
|
2016-05-04 00:03:28 +00:00
|
|
|
|
2019-08-07 04:33:55 +00:00
|
|
|
use Cake\Chronos\Chronos;
|
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;
|
2019-08-14 23:50:53 +00:00
|
|
|
use App\Annotations\AuditLog;
|
2018-12-22 00:01:04 +00:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2019-04-13 03:27:58 +00:00
|
|
|
use OpenApi\Annotations as OA;
|
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2018-12-22 00:01:04 +00:00
|
|
|
|
2016-05-04 00:03:28 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Table(name="station_playlists")
|
|
|
|
* @ORM\Entity
|
2018-12-22 00:01:04 +00:00
|
|
|
* @ORM\HasLifecycleCallbacks
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
2019-08-14 23:50:53 +00:00
|
|
|
* @AuditLog\Auditable
|
|
|
|
*
|
2019-04-13 03:27:58 +00:00
|
|
|
* @OA\Schema(type="object")
|
2016-05-04 00:03:28 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
class StationPlaylist
|
2016-05-04 00:03:28 +00:00
|
|
|
{
|
2018-04-06 21:29:27 +00:00
|
|
|
use Traits\TruncateStrings;
|
|
|
|
|
2019-03-01 03:58:19 +00:00
|
|
|
public const DEFAULT_WEIGHT = 3;
|
2019-03-31 22:09:10 +00:00
|
|
|
public const DEFAULT_REMOTE_BUFFER = 20;
|
2019-03-01 03:58:19 +00:00
|
|
|
|
2018-04-12 22:43:58 +00:00
|
|
|
public const TYPE_DEFAULT = 'default';
|
|
|
|
public const TYPE_SCHEDULED = 'scheduled';
|
|
|
|
public const TYPE_ONCE_PER_X_SONGS = 'once_per_x_songs';
|
|
|
|
public const TYPE_ONCE_PER_X_MINUTES = 'once_per_x_minutes';
|
2019-03-26 07:05:50 +00:00
|
|
|
public const TYPE_ONCE_PER_HOUR = 'once_per_hour';
|
2018-04-12 22:43:58 +00:00
|
|
|
public const TYPE_ADVANCED = 'custom';
|
|
|
|
|
2018-04-29 23:48:48 +00:00
|
|
|
public const SOURCE_SONGS = 'songs';
|
|
|
|
public const SOURCE_REMOTE_URL ='remote_url';
|
|
|
|
|
2018-11-20 12:06:16 +00:00
|
|
|
public const REMOTE_TYPE_STREAM = 'stream';
|
|
|
|
public const REMOTE_TYPE_PLAYLIST = 'playlist';
|
|
|
|
|
2018-04-29 23:48:48 +00:00
|
|
|
public const ORDER_RANDOM = 'random';
|
2018-08-30 00:45:01 +00:00
|
|
|
public const ORDER_SHUFFLE = 'shuffle';
|
2018-04-29 23:48:48 +00:00
|
|
|
public const ORDER_SEQUENTIAL = 'sequential';
|
|
|
|
|
2019-04-29 05:20:23 +00:00
|
|
|
public const OPTION_INTERRUPT_OTHER_SONGS = 'interrupt';
|
|
|
|
public const OPTION_LOOP_PLAYLIST_ONCE = 'loop_once';
|
|
|
|
public const OPTION_PLAY_SINGLE_TRACK = 'single_track';
|
|
|
|
public const OPTION_MERGE = 'merge';
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="id", type="integer")
|
|
|
|
* @ORM\Id
|
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=1)
|
2019-05-03 09:32:45 +00:00
|
|
|
* @var int|null
|
2017-08-17 18:28:48 +00:00
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
*/
|
|
|
|
protected $station_id;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\ManyToOne(targetEntity="Station", inversedBy="playlists")
|
2018-12-22 00:01:04 +00:00
|
|
|
* @ORM\JoinColumns({
|
|
|
|
* @ORM\JoinColumn(name="station_id", referencedColumnName="id", onDelete="CASCADE")
|
2017-08-17 18:28:48 +00:00
|
|
|
* })
|
|
|
|
* @var Station
|
|
|
|
*/
|
|
|
|
protected $station;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="name", type="string", length=200)
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @Assert\NotBlank()
|
|
|
|
* @OA\Property(example="Test Playlist")
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $name;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="type", type="string", length=50)
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @Assert\Choice(choices={"default", "scheduled", "once_per_x_songs", "once_per_x_minutes", "once_per_hour", "once_per_day", "custom"})
|
|
|
|
* @OA\Property(example="default")
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $type = self::TYPE_DEFAULT;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2018-04-12 22:43:58 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="source", type="string", length=50)
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @Assert\Choice(choices={"songs", "remote_url"})
|
|
|
|
* @OA\Property(example="songs")
|
|
|
|
*
|
2018-04-12 22:43:58 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $source = self::SOURCE_SONGS;
|
2018-04-12 22:43:58 +00:00
|
|
|
|
2018-04-29 23:48:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="playback_order", type="string", length=50)
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @Assert\Choice(choices={"random", "shuffle", "sequential"})
|
|
|
|
* @OA\Property(example="shuffle")
|
|
|
|
*
|
2018-04-29 23:48:48 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $order = self::ORDER_SHUFFLE;
|
2018-04-29 23:48:48 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="remote_url", type="string", length=255, nullable=true)
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example="http://remote-url.example.com/stream.mp3")
|
|
|
|
*
|
2018-04-29 23:48:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $remote_url;
|
|
|
|
|
2018-11-20 12:06:16 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="remote_type", type="string", length=25, nullable=true)
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @Assert\Choice(choices={"stream", "playlist"})
|
|
|
|
* @OA\Property(example="stream")
|
|
|
|
*
|
2018-11-20 12:06:16 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $remote_type = self::REMOTE_TYPE_STREAM;
|
|
|
|
|
2019-03-31 22:09:10 +00:00
|
|
|
/**
|
|
|
|
* @ORM\Column(name="remote_timeout", type="smallint")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=0)
|
|
|
|
*
|
2019-03-31 22:09:10 +00:00
|
|
|
* @var int The total time (in seconds) that Liquidsoap should buffer remote URL streams.
|
|
|
|
*/
|
|
|
|
protected $remote_buffer = 0;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="is_enabled", type="boolean")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=true)
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var bool
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $is_enabled = true;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2019-03-15 02:22:09 +00:00
|
|
|
/**
|
|
|
|
* @ORM\Column(name="is_jingle", type="boolean")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=false)
|
|
|
|
*
|
2019-03-15 02:22:09 +00:00
|
|
|
* @var bool If yes, do not send jingle metadata to AutoDJ or trigger web hooks.
|
|
|
|
*/
|
|
|
|
protected $is_jingle = false;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="play_per_songs", type="smallint")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=5)
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $play_per_songs = 0;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="play_per_minutes", type="smallint")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=120)
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $play_per_minutes = 0;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2019-03-26 07:05:50 +00:00
|
|
|
/**
|
|
|
|
* @ORM\Column(name="play_per_hour_minute", type="smallint")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=15)
|
|
|
|
*
|
2019-03-26 07:05:50 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $play_per_hour_minute = 0;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="schedule_start_time", type="smallint")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=900)
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $schedule_start_time = 0;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="schedule_end_time", type="smallint")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=2200)
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $schedule_end_time = 0;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2017-08-24 01:30:43 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="schedule_days", type="string", length=50, nullable=true)
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example="0,1,2,3")
|
|
|
|
*
|
2017-08-24 01:30:43 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $schedule_days;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="weight", type="smallint")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=3)
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
2019-03-01 03:58:19 +00:00
|
|
|
protected $weight = self::DEFAULT_WEIGHT;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2018-04-12 22:43:58 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="include_in_requests", type="boolean")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=true)
|
|
|
|
*
|
2018-04-12 22:43:58 +00:00
|
|
|
* @var bool
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $include_in_requests = true;
|
2018-04-12 22:43:58 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="include_in_automation", type="boolean")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=false)
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var bool
|
|
|
|
*/
|
2018-11-20 12:06:16 +00:00
|
|
|
protected $include_in_automation = false;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2019-03-26 07:05:50 +00:00
|
|
|
/**
|
2019-04-29 05:20:23 +00:00
|
|
|
* @ORM\Column(name="backend_options", type="string", length=255, nullable=true)
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
2019-04-29 05:20:23 +00:00
|
|
|
* @OA\Property(example="interrupt,loop_once,single_track,merge")
|
2019-04-13 03:27:58 +00:00
|
|
|
*
|
2019-04-29 05:20:23 +00:00
|
|
|
* @var string
|
2019-04-02 22:49:45 +00:00
|
|
|
*/
|
2019-04-30 14:43:00 +00:00
|
|
|
protected $backend_options = '';
|
2019-04-02 22:49:45 +00:00
|
|
|
|
2019-07-19 23:27:24 +00:00
|
|
|
/**
|
|
|
|
* @ORM\Column(name="played_at", type="integer")
|
2019-08-14 23:50:53 +00:00
|
|
|
* @AuditLog\AuditIgnore
|
|
|
|
*
|
2019-07-19 23:27:24 +00:00
|
|
|
* @var int The UNIX timestamp at which a track from this playlist was last played.
|
|
|
|
*/
|
|
|
|
protected $played_at = 0;
|
|
|
|
|
2019-08-18 01:42:59 +00:00
|
|
|
/**
|
|
|
|
* @ORM\Column(name="queue", type="array", nullable=true)
|
|
|
|
* @AuditLog\AuditIgnore
|
|
|
|
*
|
|
|
|
* @var array|null The current queue of unplayed songs for this playlist.
|
|
|
|
*/
|
|
|
|
protected $queue;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\OneToMany(targetEntity="StationPlaylistMedia", mappedBy="playlist", fetch="EXTRA_LAZY")
|
2018-12-22 00:01:04 +00:00
|
|
|
* @ORM\OrderBy({"weight" = "ASC"})
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var Collection
|
|
|
|
*/
|
2018-04-29 23:48:48 +00:00
|
|
|
protected $media_items;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
|
|
|
public function __construct(Station $station)
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2017-08-17 18:28:48 +00:00
|
|
|
$this->station = $station;
|
|
|
|
|
2018-04-29 23:48:48 +00:00
|
|
|
$this->media_items = new ArrayCollection;
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 00:03:28 +00:00
|
|
|
/**
|
2019-05-03 09:32:45 +00:00
|
|
|
* @return int|null
|
2016-05-04 00:03:28 +00:00
|
|
|
*/
|
2019-05-03 09:32:45 +00:00
|
|
|
public function getId(): ?int
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
2016-05-04 00:03:28 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return Station
|
|
|
|
*/
|
|
|
|
public function getStation(): Station
|
|
|
|
{
|
|
|
|
return $this->station;
|
|
|
|
}
|
2016-05-04 00:03:28 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2019-08-14 23:50:53 +00:00
|
|
|
* @AuditLog\AuditIdentifier
|
|
|
|
*
|
2017-08-17 18:28:48 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName(): string
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
2016-05-04 00:03:28 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getShortName(): string
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
|
|
|
return Station::getStationShortName($this->name);
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setName(string $name): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
2018-04-06 21:29:27 +00:00
|
|
|
$this->name = $this->_truncateString($name, 200);
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
2016-09-21 07:53:48 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getType(): string
|
|
|
|
{
|
|
|
|
return $this->type;
|
|
|
|
}
|
2016-09-21 07:53:48 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param string $type
|
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setType(string $type): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->type = $type;
|
|
|
|
}
|
2016-09-21 07:53:48 +00:00
|
|
|
|
2018-04-12 22:43:58 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSource(): string
|
|
|
|
{
|
|
|
|
return $this->source;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $source
|
|
|
|
*/
|
|
|
|
public function setSource(string $source): void
|
|
|
|
{
|
2019-08-18 01:42:59 +00:00
|
|
|
// Reset the playback queue if source is changed.
|
|
|
|
if ($source !== $this->source) {
|
|
|
|
$this->queue = null;
|
|
|
|
}
|
|
|
|
|
2018-04-12 22:43:58 +00:00
|
|
|
$this->source = $source;
|
|
|
|
}
|
|
|
|
|
2018-04-29 23:48:48 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getOrder(): string
|
|
|
|
{
|
|
|
|
return $this->order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $order
|
|
|
|
*/
|
|
|
|
public function setOrder(string $order): void
|
|
|
|
{
|
2019-08-18 01:42:59 +00:00
|
|
|
// Reset the playback queue if order is changed.
|
|
|
|
if ($order !== $this->order) {
|
|
|
|
$this->queue = null;
|
|
|
|
}
|
|
|
|
|
2018-04-29 23:48:48 +00:00
|
|
|
$this->order = $order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getRemoteUrl(): ?string
|
|
|
|
{
|
|
|
|
return $this->remote_url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $remote_url
|
|
|
|
*/
|
|
|
|
public function setRemoteUrl(?string $remote_url): void
|
|
|
|
{
|
|
|
|
$this->remote_url = $remote_url;
|
|
|
|
}
|
|
|
|
|
2018-11-20 12:06:16 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRemoteType(): ?string
|
|
|
|
{
|
|
|
|
return $this->remote_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $remote_type
|
|
|
|
*/
|
|
|
|
public function setRemoteType(?string $remote_type): void
|
|
|
|
{
|
|
|
|
$this->remote_type = $remote_type;
|
|
|
|
}
|
|
|
|
|
2019-03-31 22:09:10 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getRemoteBuffer(): int
|
|
|
|
{
|
|
|
|
return $this->remote_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $remote_buffer
|
|
|
|
*/
|
|
|
|
public function setRemoteBuffer(int $remote_buffer): void
|
|
|
|
{
|
|
|
|
$this->remote_buffer = $remote_buffer;
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getIsEnabled(): bool
|
|
|
|
{
|
|
|
|
return $this->is_enabled;
|
|
|
|
}
|
2016-09-21 07:53:48 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param bool $is_enabled
|
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setIsEnabled(bool $is_enabled): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->is_enabled = $is_enabled;
|
|
|
|
}
|
|
|
|
|
2019-03-15 02:22:09 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isJingle(): bool
|
|
|
|
{
|
|
|
|
return $this->is_jingle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $is_jingle
|
|
|
|
*/
|
|
|
|
public function setIsJingle(bool $is_jingle): void
|
|
|
|
{
|
|
|
|
$this->is_jingle = $is_jingle;
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPlayPerSongs(): int
|
|
|
|
{
|
|
|
|
return $this->play_per_songs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $play_per_songs
|
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setPlayPerSongs(int $play_per_songs): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->play_per_songs = $play_per_songs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPlayPerMinutes(): int
|
|
|
|
{
|
|
|
|
return $this->play_per_minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $play_per_minutes
|
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setPlayPerMinutes(int $play_per_minutes): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->play_per_minutes = $play_per_minutes;
|
|
|
|
}
|
2016-09-21 07:53:48 +00:00
|
|
|
|
2019-03-26 07:05:50 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPlayPerHourMinute(): int
|
|
|
|
{
|
|
|
|
return $this->play_per_hour_minute;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $play_per_hour_minute
|
|
|
|
*/
|
|
|
|
public function setPlayPerHourMinute(int $play_per_hour_minute): void
|
|
|
|
{
|
|
|
|
if ($play_per_hour_minute > 59 || $play_per_hour_minute < 0) {
|
|
|
|
$play_per_hour_minute = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->play_per_hour_minute = $play_per_hour_minute;
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getScheduleStartTime(): int
|
|
|
|
{
|
2018-11-30 16:53:53 +00:00
|
|
|
return (int)$this->schedule_start_time;
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $schedule_start_time
|
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setScheduleStartTime(int $schedule_start_time): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->schedule_start_time = $schedule_start_time;
|
|
|
|
}
|
2016-09-21 07:53:48 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getScheduleEndTime(): int
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2018-11-30 16:53:53 +00:00
|
|
|
return (int)$this->schedule_end_time;
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param int $schedule_end_time
|
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setScheduleEndTime(int $schedule_end_time): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->schedule_end_time = $schedule_end_time;
|
|
|
|
}
|
2016-09-21 07:53:48 +00:00
|
|
|
|
2018-11-20 12:06:16 +00:00
|
|
|
/**
|
|
|
|
* @return int Get the duration of scheduled play time in seconds (used for remote URLs of indeterminate length).
|
|
|
|
*/
|
|
|
|
public function getScheduleDuration(): int
|
|
|
|
{
|
|
|
|
if (self::TYPE_SCHEDULED !== $this->type) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-13 21:25:36 +00:00
|
|
|
$start_time = self::getDateTime($this->schedule_start_time)
|
|
|
|
->getTimestamp();
|
|
|
|
$end_time = self::getDateTime($this->schedule_end_time)
|
|
|
|
->getTimestamp();
|
2018-11-20 12:06:16 +00:00
|
|
|
|
|
|
|
if ($start_time > $end_time) {
|
2019-05-13 21:25:36 +00:00
|
|
|
/** @noinspection SummerTimeUnsafeTimeManipulationInspection */
|
2018-11-20 12:06:16 +00:00
|
|
|
return 86400 - ($start_time - $end_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $end_time - $start_time;
|
|
|
|
}
|
|
|
|
|
2017-08-24 01:30:43 +00:00
|
|
|
/**
|
2017-09-01 00:37:57 +00:00
|
|
|
* @return array|null
|
2017-08-24 01:30:43 +00:00
|
|
|
*/
|
2017-09-01 00:37:57 +00:00
|
|
|
public function getScheduleDays(): ?array
|
2017-08-24 01:30:43 +00:00
|
|
|
{
|
2017-09-01 00:37:57 +00:00
|
|
|
return (!empty($this->schedule_days)) ? explode(',', $this->schedule_days) : null;
|
2017-08-24 01:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $schedule_days
|
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setScheduleDays($schedule_days): void
|
2017-08-24 01:30:43 +00:00
|
|
|
{
|
|
|
|
$this->schedule_days = implode(',', (array)$schedule_days);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-19 03:08:01 +00:00
|
|
|
* @return int
|
2017-08-24 01:30:43 +00:00
|
|
|
*/
|
2019-02-19 03:08:01 +00:00
|
|
|
public function getWeight(): int
|
2017-08-24 01:30:43 +00:00
|
|
|
{
|
2019-03-01 03:58:19 +00:00
|
|
|
if ($this->weight < 1) {
|
|
|
|
return self::DEFAULT_WEIGHT;
|
2019-02-19 03:08:01 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 03:58:19 +00:00
|
|
|
return $this->weight;
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
2016-08-30 06:28:56 +00:00
|
|
|
|
2016-05-04 00:03:28 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @param int $weight
|
2016-05-04 00:03:28 +00:00
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setWeight(int $weight): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->weight = $weight;
|
|
|
|
}
|
2016-05-04 00:03:28 +00:00
|
|
|
|
2018-04-12 22:43:58 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getIncludeInRequests(): bool
|
|
|
|
{
|
|
|
|
return $this->include_in_requests;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether this playlist can be used as a valid source of requestable media.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isRequestable(): bool
|
|
|
|
{
|
|
|
|
return ($this->is_enabled && $this->include_in_requests);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $include_in_requests
|
|
|
|
*/
|
|
|
|
public function setIncludeInRequests(bool $include_in_requests): void
|
|
|
|
{
|
|
|
|
$this->include_in_requests = $include_in_requests;
|
|
|
|
}
|
|
|
|
|
2016-05-04 00:03:28 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @return bool
|
2016-05-04 00:03:28 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getIncludeInAutomation(): bool
|
|
|
|
{
|
|
|
|
return $this->include_in_automation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $include_in_automation
|
|
|
|
*/
|
2019-01-31 17:54:17 +00:00
|
|
|
public function setIncludeInAutomation(bool $include_in_automation): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->include_in_automation = $include_in_automation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-29 05:20:23 +00:00
|
|
|
* @return array
|
2019-02-19 03:08:01 +00:00
|
|
|
*/
|
2019-04-29 05:20:23 +00:00
|
|
|
public function getBackendOptions(): array
|
2019-02-19 03:08:01 +00:00
|
|
|
{
|
2019-04-29 05:20:23 +00:00
|
|
|
return explode(',', $this->backend_options);
|
2019-02-19 03:08:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 05:20:23 +00:00
|
|
|
public function backendInterruptOtherSongs(): bool
|
2019-02-19 03:08:01 +00:00
|
|
|
{
|
2019-04-29 05:20:23 +00:00
|
|
|
$backend_options = $this->getBackendOptions();
|
|
|
|
return in_array(self::OPTION_INTERRUPT_OTHER_SONGS, $backend_options, true);
|
2019-02-19 03:08:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 05:20:23 +00:00
|
|
|
public function backendLoopPlaylistOnce(): bool
|
2019-02-19 03:08:01 +00:00
|
|
|
{
|
2019-04-29 05:20:23 +00:00
|
|
|
$backend_options = $this->getBackendOptions();
|
|
|
|
return in_array(self::OPTION_LOOP_PLAYLIST_ONCE, $backend_options, true);
|
2019-02-19 03:08:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 05:20:23 +00:00
|
|
|
public function backendPlaySingleTrack(): bool
|
2019-02-19 03:08:01 +00:00
|
|
|
{
|
2019-04-29 05:20:23 +00:00
|
|
|
$backend_options = $this->getBackendOptions();
|
|
|
|
return in_array(self::OPTION_PLAY_SINGLE_TRACK, $backend_options, true);
|
2019-02-19 03:08:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 05:20:23 +00:00
|
|
|
public function backendMerge(): bool
|
2019-04-02 22:49:45 +00:00
|
|
|
{
|
2019-04-29 05:20:23 +00:00
|
|
|
$backend_options = $this->getBackendOptions();
|
|
|
|
return in_array(self::OPTION_MERGE, $backend_options, true);
|
2019-04-02 22:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-29 05:20:23 +00:00
|
|
|
* @param array $backend_options
|
2019-04-02 22:49:45 +00:00
|
|
|
*/
|
2019-04-29 05:20:23 +00:00
|
|
|
public function setBackendOptions($backend_options): void
|
2019-04-02 22:49:45 +00:00
|
|
|
{
|
2019-04-29 06:19:03 +00:00
|
|
|
$this->backend_options = implode(',', (array)$backend_options);
|
2019-04-02 22:49:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-19 23:27:24 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPlayedAt(): int
|
|
|
|
{
|
|
|
|
return $this->played_at;
|
|
|
|
}
|
|
|
|
|
2019-07-20 21:04:42 +00:00
|
|
|
/**
|
|
|
|
* @param int $played_at
|
|
|
|
*/
|
|
|
|
public function setPlayedAt(int $played_at): void
|
|
|
|
{
|
|
|
|
$this->played_at = $played_at;
|
|
|
|
}
|
|
|
|
|
2019-07-19 23:27:24 +00:00
|
|
|
public function played(): void
|
|
|
|
{
|
|
|
|
$this->played_at = time();
|
|
|
|
}
|
|
|
|
|
2019-08-18 01:42:59 +00:00
|
|
|
/**
|
|
|
|
* @return array|null
|
|
|
|
*/
|
|
|
|
public function getQueue(): ?array
|
|
|
|
{
|
|
|
|
return $this->queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array|null $queue
|
|
|
|
*/
|
|
|
|
public function setQueue(?array $queue): void
|
|
|
|
{
|
|
|
|
$this->queue = $queue;
|
|
|
|
}
|
|
|
|
|
2019-02-19 03:08:01 +00:00
|
|
|
/**
|
2019-03-26 07:05:50 +00:00
|
|
|
* @return Collection
|
2019-02-19 03:08:01 +00:00
|
|
|
*/
|
2019-03-26 07:05:50 +00:00
|
|
|
public function getMediaItems(): Collection
|
2019-02-19 03:08:01 +00:00
|
|
|
{
|
2019-03-26 07:05:50 +00:00
|
|
|
return $this->media_items;
|
2019-02-19 03:08:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-17 21:29:21 +00:00
|
|
|
/**
|
|
|
|
* Indicates whether a playlist is enabled and has content which can be scheduled by an AutoDJ scheduler.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isPlayable(): bool
|
|
|
|
{
|
2019-07-19 23:55:44 +00:00
|
|
|
return ($this->is_enabled
|
|
|
|
&& (self::SOURCE_SONGS !== $this->source || $this->media_items->count() > 0)
|
|
|
|
&& !$this->backendInterruptOtherSongs()
|
|
|
|
&& !$this->backendMerge()
|
|
|
|
&& !$this->backendLoopPlaylistOnce());
|
2019-07-17 21:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parent function for determining whether a playlist of any type can be played by the AutoDJ.
|
|
|
|
*
|
|
|
|
* @param Chronos|null $now
|
|
|
|
* @param array $recentSongHistory
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function shouldPlayNow(Chronos $now = null, array $recentSongHistory = []): bool
|
|
|
|
{
|
|
|
|
if (null === $now) {
|
|
|
|
$now = Chronos::now(new \DateTimeZone($this->getStation()->getTimezone()));
|
|
|
|
}
|
|
|
|
|
|
|
|
switch($this->type) {
|
|
|
|
case self::TYPE_ONCE_PER_HOUR:
|
2019-07-19 23:27:24 +00:00
|
|
|
return $this->shouldPlayNowPerHour($now);
|
2019-07-17 21:29:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case self::TYPE_ONCE_PER_X_SONGS:
|
|
|
|
return !$this->wasPlayedRecently($recentSongHistory, $this->getPlayPerSongs());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case self::TYPE_ONCE_PER_X_MINUTES:
|
2019-07-19 23:27:24 +00:00
|
|
|
return $this->shouldPlayNowPerMinute($now);
|
2019-07-17 21:29:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case self::TYPE_SCHEDULED:
|
|
|
|
// If the times match, it's a "play once" playlist.
|
|
|
|
if ($this->getScheduleStartTime() === $this->getScheduleEndTime()) {
|
2019-07-19 23:27:24 +00:00
|
|
|
return $this->shouldPlayNowOnce($now);
|
2019-07-17 21:29:21 +00:00
|
|
|
}
|
|
|
|
|
2019-07-19 23:27:24 +00:00
|
|
|
return $this->shouldPlayNowScheduled($now);
|
2019-07-17 21:29:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case self::TYPE_ADVANCED:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case self::TYPE_DEFAULT:
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the playlist is scheduled to play according to schedule rules.
|
|
|
|
*
|
|
|
|
* @param Chronos $now
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-07-20 21:04:42 +00:00
|
|
|
protected function shouldPlayNowScheduled(Chronos $now): bool
|
2019-07-17 21:29:21 +00:00
|
|
|
{
|
|
|
|
$day_to_check = (int)$now->format('N');
|
|
|
|
$current_timecode = (int)$now->format('Hi');
|
|
|
|
|
|
|
|
$schedule_start_time = $this->getScheduleStartTime();
|
|
|
|
$schedule_end_time = $this->getScheduleEndTime();
|
|
|
|
|
|
|
|
// Special handling for playlists ending at midnight (hour code "000").
|
|
|
|
if (0 === $schedule_end_time) {
|
|
|
|
$schedule_end_time = 2400;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle overnight playlists that stretch into the next day.
|
|
|
|
if ($schedule_end_time < $schedule_start_time) {
|
|
|
|
if ($current_timecode <= $schedule_end_time) {
|
|
|
|
// Check the previous day, since it's before the end time.
|
|
|
|
$day_to_check = (1 === $day_to_check) ? 7 : $day_to_check - 1;
|
|
|
|
} else if ($current_timecode < $schedule_start_time) {
|
|
|
|
// The playlist shouldn't be playing before the start time on the current date.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Non-overnight playlist check
|
|
|
|
} else if ($current_timecode < $schedule_start_time || $current_timecode > $schedule_end_time) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the current day is one of the scheduled play days.
|
|
|
|
if (!$this->isScheduledToPlayToday($day_to_check)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($this->backendPlaySingleTrack())
|
2019-07-19 23:27:24 +00:00
|
|
|
? !$this->wasPlayedInLastXMinutes($now, 720)
|
2019-07-17 21:29:21 +00:00
|
|
|
: true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a day code (1-7) a-la date('N'), return if the playlist can be played on that day.
|
|
|
|
*
|
|
|
|
* @param int $day_to_check
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-07-19 23:27:24 +00:00
|
|
|
protected function isScheduledToPlayToday(int $day_to_check): bool
|
2019-07-17 21:29:21 +00:00
|
|
|
{
|
|
|
|
$play_once_days = $this->getScheduleDays();
|
|
|
|
return empty($play_once_days)
|
|
|
|
|| in_array($day_to_check, $play_once_days);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-19 23:27:24 +00:00
|
|
|
* @param Chronos $now
|
2019-07-17 21:29:21 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2019-07-20 21:04:42 +00:00
|
|
|
protected function shouldPlayNowPerMinute(Chronos $now): bool
|
2019-07-17 21:29:21 +00:00
|
|
|
{
|
2019-07-19 23:27:24 +00:00
|
|
|
return !$this->wasPlayedInLastXMinutes($now, $this->getPlayPerMinutes());
|
2019-07-17 21:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Chronos $now
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-07-20 21:04:42 +00:00
|
|
|
protected function shouldPlayNowPerHour(Chronos $now): bool
|
2019-07-17 21:29:21 +00:00
|
|
|
{
|
2019-07-20 00:26:31 +00:00
|
|
|
$current_minute = (int)$now->minute;
|
2019-07-17 21:29:21 +00:00
|
|
|
$target_minute = $this->getPlayPerHourMinute();
|
|
|
|
|
|
|
|
if ($current_minute < $target_minute) {
|
2019-07-20 00:26:31 +00:00
|
|
|
$target_time = $now->addHour(-1)->minute($target_minute);
|
2019-07-17 21:29:21 +00:00
|
|
|
} else {
|
2019-07-20 00:26:31 +00:00
|
|
|
$target_time = $now->minute($target_minute);
|
2019-07-17 21:29:21 +00:00
|
|
|
}
|
|
|
|
|
2019-07-20 00:26:31 +00:00
|
|
|
$playlist_diff = $target_time->diffInMinutes($now, false);
|
|
|
|
|
|
|
|
if ($playlist_diff < 0 || $playlist_diff > 15) {
|
2019-07-17 21:29:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-19 23:27:24 +00:00
|
|
|
return !$this->wasPlayedInLastXMinutes($now, 30);
|
2019-07-17 21:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the playlist is scheduled to play once.
|
|
|
|
*
|
|
|
|
* @param Chronos $now
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-07-20 21:04:42 +00:00
|
|
|
protected function shouldPlayNowOnce(Chronos $now): bool
|
2019-07-17 21:29:21 +00:00
|
|
|
{
|
|
|
|
if (!$this->isScheduledToPlayToday((int)$now->format('N'))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$current_timecode = (int)$now->format('Hi');
|
|
|
|
|
|
|
|
$playlist_play_time = $this->getScheduleStartTime();
|
|
|
|
$playlist_diff = $current_timecode - $playlist_play_time;
|
2019-07-19 23:27:24 +00:00
|
|
|
if ($playlist_diff < 0 || $playlist_diff > 15) {
|
2019-07-17 21:29:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-19 23:27:24 +00:00
|
|
|
return !$this->wasPlayedInLastXMinutes($now, 720);
|
2019-07-17 21:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $songHistoryEntries
|
|
|
|
* @param int $length
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-07-20 21:04:42 +00:00
|
|
|
protected function wasPlayedRecently(array $songHistoryEntries = [], $length = 15): bool
|
2019-07-17 21:29:21 +00:00
|
|
|
{
|
|
|
|
if (empty($songHistoryEntries)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if already played
|
|
|
|
$relevant_song_history = array_slice($songHistoryEntries, 0, $length);
|
|
|
|
|
|
|
|
$was_played = false;
|
|
|
|
foreach($relevant_song_history as $sh_row) {
|
|
|
|
if ((int)$sh_row['playlist_id'] === $this->id) {
|
|
|
|
$was_played = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reset($songHistoryEntries);
|
|
|
|
return $was_played;
|
|
|
|
}
|
|
|
|
|
2019-07-20 21:04:42 +00:00
|
|
|
protected function wasPlayedInLastXMinutes(Chronos $now, int $minutes): bool
|
2019-07-19 23:27:24 +00:00
|
|
|
{
|
|
|
|
if (0 === $this->played_at) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-20 15:47:55 +00:00
|
|
|
$threshold = $now->addMinutes(0-$minutes)->getTimestamp();
|
|
|
|
return ($this->played_at > $threshold);
|
2019-07-19 23:27:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-13 04:15:36 +00:00
|
|
|
/**
|
|
|
|
* Export the playlist into a reusable format.
|
|
|
|
*
|
|
|
|
* @param string $file_format
|
|
|
|
* @param bool $absolute_paths
|
2019-02-25 06:43:00 +00:00
|
|
|
* @param bool $with_annotations
|
2017-05-13 04:15:36 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2019-02-25 06:43:00 +00:00
|
|
|
public function export($file_format = 'pls', $absolute_paths = false, $with_annotations = false): string
|
2017-05-13 04:15:36 +00:00
|
|
|
{
|
|
|
|
$media_path = ($absolute_paths) ? $this->station->getRadioMediaDir().'/' : '';
|
|
|
|
|
|
|
|
switch($file_format)
|
|
|
|
{
|
2017-05-13 16:16:57 +00:00
|
|
|
case 'm3u':
|
|
|
|
$playlist_file = [];
|
2018-04-29 23:48:48 +00:00
|
|
|
foreach ($this->media_items as $media_item) {
|
|
|
|
$media_file = $media_item->getMedia();
|
2017-08-17 18:28:48 +00:00
|
|
|
$media_file_path = $media_path . $media_file->getPath();
|
2017-05-13 16:16:57 +00:00
|
|
|
$playlist_file[] = $media_file_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode("\n", $playlist_file);
|
2017-08-24 01:30:43 +00:00
|
|
|
break;
|
2017-05-13 16:16:57 +00:00
|
|
|
|
2017-05-13 04:15:36 +00:00
|
|
|
case 'pls':
|
|
|
|
default:
|
2017-05-13 16:16:57 +00:00
|
|
|
$playlist_file = [
|
|
|
|
'[playlist]',
|
|
|
|
];
|
|
|
|
|
|
|
|
$i = 0;
|
2018-04-29 23:48:48 +00:00
|
|
|
foreach($this->media_items as $media_item) {
|
2017-05-13 16:16:57 +00:00
|
|
|
$i++;
|
|
|
|
|
2018-04-29 23:48:48 +00:00
|
|
|
$media_file = $media_item->getMedia();
|
2017-08-17 18:28:48 +00:00
|
|
|
$media_file_path = $media_path . $media_file->getPath();
|
2017-05-13 16:16:57 +00:00
|
|
|
$playlist_file[] = 'File'.$i.'='.$media_file_path;
|
2017-08-17 18:28:48 +00:00
|
|
|
$playlist_file[] = 'Title'.$i.'='.$media_file->getArtist().' - '.$media_file->getTitle();
|
|
|
|
$playlist_file[] = 'Length'.$i.'='.$media_file->getLength();
|
2017-05-13 16:16:57 +00:00
|
|
|
$playlist_file[] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$playlist_file[] = 'NumberOfEntries='.$i;
|
|
|
|
$playlist_file[] = 'Version=2';
|
|
|
|
|
2017-05-13 04:15:36 +00:00
|
|
|
return implode("\n", $playlist_file);
|
2017-08-24 01:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-12 08:19:47 +00:00
|
|
|
/**
|
2018-01-13 12:45:16 +00:00
|
|
|
* Return a \DateTime object (or null) for a given time code, by default in the UTC time zone.
|
2017-11-12 08:19:47 +00:00
|
|
|
*
|
2019-01-31 17:54:17 +00:00
|
|
|
* @param string|int $time_code
|
|
|
|
* @param Chronos|null $now
|
2018-03-28 06:07:56 +00:00
|
|
|
* @return Chronos
|
2017-11-12 08:19:47 +00:00
|
|
|
*/
|
2018-04-11 02:22:15 +00:00
|
|
|
public static function getDateTime($time_code, Chronos $now = null): Chronos
|
2017-11-12 08:19:47 +00:00
|
|
|
{
|
2018-04-11 02:22:15 +00:00
|
|
|
if ($now === null) {
|
|
|
|
$now = Chronos::now(new \DateTimeZone('UTC'));
|
|
|
|
}
|
2018-03-28 06:07:56 +00:00
|
|
|
|
2018-04-11 02:22:15 +00:00
|
|
|
$time_code = str_pad($time_code, 4, '0', STR_PAD_LEFT);
|
|
|
|
return $now->setTime(substr($time_code, 0, 2), substr($time_code, 2));
|
2017-08-24 01:30:43 +00:00
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|