From 5d7df2feb7ba6149aab188aaf9ac36589bdc4cc2 Mon Sep 17 00:00:00 2001 From: dakriy Date: Sat, 9 Aug 2025 06:56:47 -0700 Subject: [PATCH] feat(legacy): now macro should use show start time when available (#3175) ### Description Previously the `now` macro used the current time. This is a bit confusing for autoloading playlists with dynamic smart blocks, as you have to think about when autoloading happens. This just makes the autoload datetime be the show start datetime. **This is a new feature**: Yes **I have updated the documentation to reflect these changes**: Yes ### Testing Notes **What I did:** I started up libretime, created an autoloading playlist with a dynamic block set for one hour ahead. I then created a show with the autoloading playlist one hour ahead of now and saw that it autoloaded properly and that the hour matched the show start hour and not the current hour. I also verified that the now functionality was not changed when not autoloading by using the preview tracks button on the dynamic smart block. **How you can replicate my testing:** See `What I did` section. ### **Links** _Issues links or other related resources. Use the line Closes: #bug_number to link a bug in the issue tracker._ --- docs/user-manual/playlists.md | 2 +- legacy/application/models/Block.php | 13 +++++++------ legacy/application/models/Scheduler.php | 5 +++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/user-manual/playlists.md b/docs/user-manual/playlists.md index 693cd6f68..d13cd3da1 100644 --- a/docs/user-manual/playlists.md +++ b/docs/user-manual/playlists.md @@ -37,7 +37,7 @@ Smart blocks are automatically filled with media files from the LibreTime librar To create a smart block, click the **Smartblocks** button on the left sidebar, and select **New** from the toolbar. Like a playlist, smart blocks can have a title and description, which you can edit. This helps you find relevant smart blocks in searches. Fill out the smart block's **Name**, **Search Criteria**, and **Limit to** sections. The search criteria can be any one of LibreTime's metadata categories, such as **Title**, **Creator** or **Genre**. The modifier depends on whether the metadata in question contains letters or numbers. For example, **Title** has modifiers including _contains_ and _starts with_, whereas the modifiers for **BPM** include _is greater than_ and _is in the range_. -To filter tracks using today's date information, use the `now{}` macro. Format characters are listed in the [php documentation](https://www.php.net/manual/en/datetime.format.php). For example, to filter to tracks with a **Title** that ends in `Instrumental Jan 2024` where `Jan 2024` is the current month and year, add a criteria for **Title** with a modifier of **ends with** and a value of `Instrumental now{M Y}`. The macro uses the configured station timezone to resolve dates and times. +To filter tracks using today's date information, use the `now{}` macro. Format characters are listed in the [php documentation](https://www.php.net/manual/en/datetime.format.php). For example, to filter to tracks with a **Title** that ends in `Instrumental Jan 2024` where `Jan 2024` is the current month and year, add a criteria for **Title** with a modifier of **ends with** and a value of `Instrumental now{M Y}`. The macro uses the configured station timezone to resolve dates and times. For dynamic autoloading smart blocks the datetime used is the start datetime of the show. In all other cases the current datetime is used. If you have a large number of files which meet the criteria that you specify, you may wish to limit the duration of the smart block using the **Limit to** field, so that it fits within the show you have in mind. Select **hours**, **minutes** or **items** from the drop-down menu, and click the **Generate** button again, if it's a static smart block. Then click the **Save** button. diff --git a/legacy/application/models/Block.php b/legacy/application/models/Block.php index dc3cfd457..859f52546 100644 --- a/legacy/application/models/Block.php +++ b/legacy/application/models/Block.php @@ -1295,9 +1295,9 @@ SQL; } } - public function getListOfFilesUnderLimit($show = null) + public function getListOfFilesUnderLimit($show = null, $showStartTime = null) { - $info = $this->getListofFilesMeetCriteria($show); + $info = $this->getListofFilesMeetCriteria($show, $showStartTime); $files = $info['files']; $limit = $info['limit']; $repeat = $info['repeat_tracks'] == 1; @@ -1480,13 +1480,14 @@ SQL; return $storedCrit; } - private function resolveDate($value, $timeZone) + private function resolveDate($value, ?DateTime $resolveTo, string $timeZone) { if (!is_string($value)) { return $value; } - $dt = new DateTime('now', new DateTimeZone($timeZone)); + $dt = $resolveTo ?: new DateTime('now'); + $dt->setTimezone(new DateTimeZone($timeZone)); return preg_replace_callback( '/now{(.*?)}/', @@ -1496,7 +1497,7 @@ SQL; } // this function return list of propel object - public function getListofFilesMeetCriteria($showLimit = null) + public function getListofFilesMeetCriteria($showLimit = null, $showStartTime = null) { $storedCrit = $this->getCriteria(); @@ -1563,7 +1564,7 @@ SQL; $spCriteriaExtra = $criteria['extra']; } - $spCriteriaValue = $this->resolveDate($spCriteriaValue, $timeZone); + $spCriteriaValue = $this->resolveDate($spCriteriaValue, $showStartTime, $timeZone); if ($spCriteriaModifier == CriteriaModifier::STARTS_WITH) { $spCriteriaValue = "{$spCriteriaValue}%"; diff --git a/legacy/application/models/Scheduler.php b/legacy/application/models/Scheduler.php index a4de230e6..9c0b80d21 100644 --- a/legacy/application/models/Scheduler.php +++ b/legacy/application/models/Scheduler.php @@ -219,6 +219,7 @@ final class Application_Model_Scheduler // if there is a show we need to set a show limit to pass to smart blocks in case they use time remaining $showInstance = new Application_Model_ShowInstance($show); $showLimit = $showInstance->getSecondsRemaining(); + $showStart = $showInstance->getShowInstanceStart(null); $originalShowLimit = $showLimit; $files = []; @@ -286,7 +287,7 @@ final class Application_Model_Scheduler } else { $defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn(); $defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut(); - $dynamicFiles = $bl->getListOfFilesUnderLimit($showLimit); + $dynamicFiles = $bl->getListOfFilesUnderLimit($showLimit, $showStart); foreach ($dynamicFiles as $f) { $fileId = $f['id']; $file = CcFilesQuery::create()->findPk($fileId); @@ -347,7 +348,7 @@ final class Application_Model_Scheduler } else { $defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn(); $defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut(); - $dynamicFiles = $bl->getListOfFilesUnderLimit($showLimit); + $dynamicFiles = $bl->getListOfFilesUnderLimit($showLimit, $showStart); foreach ($dynamicFiles as $f) { $fileId = $f['id']; $file = CcFilesQuery::create()->findPk($fileId);