I wanted to know if it's possible to combine the query you suggested to prevent tracks from the same album playing...
@fbuser continuing from here I guess I'm a bit keener now into implementing one I want to force my MediaLibrary to last_played and then space out music tracks with the same circle (or album artist). Regarding the spacing out is it possible to use the LAG function or any of that sort? Suppose there are 2 rows and both of them have the same circle next to each other would it be possible to space them in a way so that they are maybe 10 minutes apart? or X minutes apart from each other?
WITH CTE AS (
SELECT
path,
subsong,
codec,
[album artist],
COALESCE(NULLIF([%jsp3_last_played%], ''), '1970-01-01 00:00:00') AS [%jsp3_last_played%],
ROW_NUMBER() OVER (PARTITION BY [album artist] ORDER BY COALESCE(NULLIF([%jsp3_last_played%], ''), '1970-01-01 00:00:00') DESC) AS row_num
FROM MediaLibrary
)
SELECT path,
subsong
FROM (
SELECT
CTE.*,
LAG([album artist]) OVER (ORDER BY COALESCE(NULLIF([%jsp3_last_played%], ''), '1970-01-01 00:00:00') DESC) AS prev_artist
FROM CTE
) AS T
WHERE (codec <> 'TAGS') AND (([%jsp3_last_played%] < datetime('now', '-300 minutes', 'localtime'))
AND (
row_num = 1 OR
COALESCE(NULLIF([%jsp3_last_played%], ''), '1970-01-01 00:00:00') < datetime('now', '-10 minutes', 'localtime')
AND (prev_artist IS NULL OR prev_artist <> [album artist])
))
ORDER BY CONCAT([%jsp3_last_played%], [album artist])
I've been scrolling through SQL functions and checking other forums but it seems harder to implement it... The code I've provided above is still incomplete...
Before this, if I only wanted to retrieve the Least Recently Played this query pretty much did the job.
WITH CTE AS(
SELECT path, subsong, codec, [%jsp3_loved%], COALESCE(NULLIF([%jsp3_last_played%], ''), '1970-01-01 00:00:00') AS [%jsp3_last_played%]
FROM MediaLibrary
)
SELECT path, subsong FROM CTE
WHERE [%jsp3_last_played%] < datetime('now', '-300 minutes', 'localtime')
ORDER BY [%jsp3_last_played%]
But I want to know if it's possible to space out album artists/circles.